Closed ZFail closed 4 years ago
I've looked into this as well. I think keystone's api is better than mobx-state-trees especially when working with Typescript but the way it encodes $modelType and $modelId bothers me as well.
It's probably designed that way since runtime checking (tprop) is not a requirement, and just uses $modelType to figure out the correct type creator. In addition $modelId for each type is used for reconciliation, I think it would take a major rewrite encode $modelType and $modelId a different way,
Some ideas:
Currently, we can hydrate a model with fromSnapshot() since all of the type information is encoded in the snapshot. We will have to remove this requirement and hydrate models from its constructor:
i.e. new Model(snapshot) or Model.create(snapshot)
I don't know if this is possible without using the require runtime checking method (tprop) since we need to encode the Model shape inside the Model itself. Also we need to have way the resolve union types from snapshot.
At this point I think we're getting so close to mobx-state-tree, it might be better to use that library if you don't want the modelType and modelID encodings.
@ckwong90 that is pretty much spot on.
@ckwong90 Using mobx-state-tree after the keystone is painful. I think that implementing loading snapshots without meta information is a good idea.
Implemented first steps for loading snapshots. It looks pretty simple if you use a tProp. https://github.com/ZFail/mobx-keystone/commit/c1e9633b83e8b22f7bf44ca98521276f55f8152c
Just wondering, do functional models help?
Closing due to inactivity, feel free to reopen if needed
Is it possible to initialize a model from a snapshot without $modelId and $modelType fields? Like in MST. As I understand it, if you specify the root model, and also if there is information about types of all models, then you can create a model without meta-information.