Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically append/amend types #326

Closed
s-panferov opened this issue Aug 22, 2017 · 4 comments
Closed

Dynamically append/amend types #326

s-panferov opened this issue Aug 22, 2017 · 4 comments

Comments

@s-panferov
Copy link

Hello. I have some dynamically-loaded parts of my codebase, and because of that, I cannot build the entire store model at startup.

Is there any way to append properties to existed types after they are created?

Example:

const Document = types.model('Document', {})

// Only document type is known at startup
const Block = types.union(Document)

import('./other').then(otherType => {
  Block.append(otherType) // ??
})
@mattiamanzati
Copy link
Contributor

There is no included solution yet, please see #247 for proposal and please give feedback on what do you expect to be able to do there :)
If you are injecting your store using mobx-react Provider, you could btw achieve this. Basically use types.frozen as placeholder type until the type is actually loaded, trigger the type loading, and one you have loaded it, replace the store definition with a new one with the loaded types and re-create the store on root using NewStoreType.create(getSnapshot(oldStoreInstance)).
Yeah, sounds difficult, but we will work on that soon :)

@s-panferov
Copy link
Author

@mattiamanzati sorry, haven't seen the PR. Ok, thanks, moving to #247

@mattiamanzati
Copy link
Contributor

No problem! :)

@ThaJay
Copy link

ThaJay commented Oct 29, 2018

I would like to migrate my custom orm solution to mst for our react-native app. We don't use typescript and we dynamically load data from our rest api. I do not want to document every detail of the data in our code. I hoped it would be as easy as starting with an empty model like so https://codesandbox.io/s/kkw1o3ory7 and then define actions on it. but mst only seems to accept entries that are defined on the model.

I would love to use this for the observable data, actions and patches. My current solution is not observable (I have to keep a version number per collection to decide what to rerender) but I do have actions and patches. It would be awesome if I could throw away all that code and just use a simple api.

Is there currently any way to dynamically fill models with data or is that closed pull request my only hope?

https://stackoverflow.com/questions/53046923/is-there-any-way-to-not-define-a-data-model-in-mobx-state-tree-beforehand-to-d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants