Skip to content

Passing in runtime data on model instantiation #392

Answered by sisp
aboyer1013 asked this question in Q&A
Discussion options

You must be logged in to vote

What you're trying to do might not be sound. If you set fooAction upon model instantiation, then created a snapshot, and later restored the state from the snapshot again, fooAction would not be set then because it's neither part of the snapshot (because (a) it's not a model prop and (b) functions aren't snapshotable/serializable anyway) nor part of the model definition.

Contexts might be what you're looking for. You can inject any kind of data into a state tree via a context and retrieve it at a child node, e.g. in your model instance.

Just FYI, you don't need to decorate setFooAction with @modelAction because it doesn't assign a value to a model prop.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aboyer1013
Comment options

Answer selected by aboyer1013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants