by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Julien Goux
    @jgoux
    Hello
    I just discovered ObjectModel, good stuff ! :)
    Is it possible to model a Map with it ?
    I like to use a kind of Map (actually a simple object) to index my entities by their id :)
    Maybe something like : Model.Map(UserId, User) would do ?
    Sylvain Pollet-Villard
    @sylvainpolletvillard
    Hi @jgoux , sorry for the delay, this channel has not being used so far
    Map Models are on the way, they will be in v3
    you can already try them in the next branch : https://github.com/sylvainpolletvillard/ObjectModel/tree/next
    I would not recommend to use the next branch though, many breaking changes are still expected
    See also "I use an object like a map with a number of key-value pairs. How do I check the type of all the values ?" in http://objectmodel.js.org/#common-questions
    Sylvain Pollet-Villard
    @sylvainpolletvillard
    Erik Harper
    @eriklharper
    I'm looking to use ObjectModel within a React app. I'd like to build js model Classes that can have the smarts to define how they fetch their data from a server, vis a vis:
    class FloorModel {
      constructor({ locationId, floorId }) {
        this.locationId = locationId;
        this.floorId = floorId;
      }
      get() {
        try {
          return api.get(`/locations/${this.locationId}/maps/${this.floorId}`);
        } catch (e) {
          if (ramda.has("response", e)) {
            return e.response.data;
          } else {
            throw e;
          }
        }
      }
    }
    do you recommend creating models hydrated with server data with the Model constructor like so: Model(resultsFromServerFetch)?
    Sylvain Pollet-Villard
    @sylvainpolletvillard
    you mean create model instances, not models ?
    FloorModel(resultsFromServerFetch)
    the idea is to define your api data structures as models on the client, then dynamically validate the data sent by the server by instanciating these models with it
    Artur Baybulatov
    @ArturBaybulatov
    image.png
    Artur Baybulatov
    @ArturBaybulatov
    Hello. Could somebody explain, is BasicModel is meant to be used like this: BasicModel({foo: String, bar: SomeCustomModel})? As you can see on the screenshot, it behaves weirdly when tested from Chrome console (you can try at https://codesandbox.io/s/sweet-hill-h9tht ). Although, seems to work fine from the actual written code.
    Artur Baybulatov
    @ArturBaybulatov
    image.png
    Also this is weird. When model defined and evaluated instantly it works as expected. But when it's first assigned to a variable and then evaluated, it behaves differently.
    Sylvain Pollet-Villard
    @sylvainpolletvillard
    Hello Arthur. If you pass an object as definition, what you need is an ObjectModel, not a Basic model. You can also use the Model constructor which will pick the appropriate model type for you.
    Sylvain Pollet-Villard
    @sylvainpolletvillard
    looking at your screens, I'm very confused. I added the same tests to the lib test suite and cannot reproduce your results: http://objectmodel.js.org/test/?moduleId=b5d7ac90&filter=Object%20definitions
    Sylvain Pollet-Villard
    @sylvainpolletvillard
    I'm assuming you are using latest Chrome ?
    Artur Baybulatov
    @ArturBaybulatov

    Hey, Sylvain! Thanks for the reply. Yes, I'm using the latest Chrome, v81.0.4044.138. Such strange results are happening only in Chrome console. I was puzzled as well :)

    And, BTW, thanks for super awesome lib!

    Sylvain Pollet-Villard
    @sylvainpolletvillard
    image.png
    Indeed there is something weird with Chrome console. For example, on this page with these tests it works:
    but I managed to reproduce it with the exact same conditions a few minutes ago
    maybe it is related to devtool formatters, let me try
    Sylvain Pollet-Villard
    @sylvainpolletvillard
    there, same conditions, got this result:
    image.png
    for some reason, the model definition is changed and the foo property became optional
    my guess is that there is a bug related to the custom devtool formatters
    Sylvain Pollet-Villard
    @sylvainpolletvillard
    yep I think I found it ! So the bug only happened when inspecting a model definition with custom devtool formatters enabled in browser console. Good finding ! will push a fix tonight
    Sylvain Pollet-Villard
    @sylvainpolletvillard
    fixed in v4.2.1 ! Thanks for the report :thumbsup:
    Artur Baybulatov
    @ArturBaybulatov
    Awesome!
    Artur Baybulatov
    @ArturBaybulatov
    Can confirm, the bug is not reproduced anymore!