Closed SimonChaumet closed 3 years ago
I kind of solved the problem : my creation of my store wasn't correct, I should have used the fromSnapshot. But it seems that I can't use fromSnapshot because I'm using a rest API that don't follows your snapshot structure : we can't override the modelId (I'm using ids prefixed by the model name like themeId) and references isn't compatible with normalizr (getSnapshot gives a list of objects for references and not list of ids).
Am I missing something ? If not then maybe this library is not for me because I can't use references and fromSnapshot easily which for me are the main goals of this library.
So this is not an issue anymore ?
If you consider that not using the lib anymore makes this not an issue then yes
Yes, I have returned to MST after 2 days and gave up for a now. First, docs are not clear enough, even simple model ( Items maps with inner Item ) discouraged me and takes time to implement. I found out that I need to use constructor args to initialize the model, so then why default params are there ? So decided to come back later.
If the data coming from a REST API doesn't include a $modelId / $modelType property you have some ways to work over it:
new Model({...})
over each of the snapshot objects / subObjects as needed (only recommended if your data structure is relatively simple)By the way, a change from MST is that even when all props have a default value you still need to provide an empty object in the constructor. At first this was (in part) to make typescript typings easier, but could be revised.
e.g.
@model("x")
class M extends Model({
a: prop(1),
b: prop(2)
}) {}
const m = new M({}) // empty object, indicating it will use all the default values
// m is { a: 1, b: 2 }
I think this library will become extremely popular if someone add many examples there. Todo and list of todos are not enough. It might be users with child-parent or e-shop models with a cart....
I find it reasonably well documented, especially when you kind of know how it works. But writing good documentation is a lot of work. Just picking up a previous comment of yours: Why not learn how this library works with a "child-parent" or "e-shop models with a cart" toy example that exceeds the simplicity of a "todo list" and write it up as documentation? I think what @xaviergonz has created is terrific and IMHO way better than MST with all its flaws. But open source projects built by individuals in their free time (I assume) need community support.
Closing due to inactivity
When using Typescript (4.0.3) the map properties types are incorrect.
But I can't add the getters and setters because the type is incorrect. And I can't create a getter with the same name as my property or typescript sends me a TS2611 error. What should I do ? Cast the values ?