mobx-state-tree
mobx-state-tree copied to clipboard
Cannot use `types.snapshotProcessor` response in reference
Bug report
- [x] I've checked documentation and searched for existing issues
- [x] I've made sure my project is based on the latest MST version
- [x] Fork this code sandbox or another minimal reproduction.
Sandbox link or minimal reproduction code https://codesandbox.io/s/mobx-state-tree-todolist-mc92x
Describe the expected behavior I was expecting to be able to use a processed model as a reference
Describe the observed behavior
I receive a Failed to resolve reference error when trying to set a reference to a processed instance.
I'm having a similar issue in our code base. Does anyone have any insight into why this happens and how it can be resolved?
Hello, firstly in you're example in index.html you should wrap you're div in html element.
Related to the mst error I am not sure but I guess problem is that you can't assign inside types.array(types.snapshotProcessor(...).
what you can do instead is:
todos: types.snapshotProcessor(types.array(Todo),{
preprocess:(snar)=>{
return snar ? sn.map(sn=>{
//do whatever you want
return sn
}) : []
}
})
corrected example here:
https://codesandbox.io/s/mobx-state-tree-todolist-forked-665bs?file=/models/TodoStore.js
@Relaxe111 , i have similar issue and your example works, but we should fix mobx-state-tree version from latest to previous or update all of peerDependencies to latest. I'm realize second variant. Thanks a lot! I think that this case should go to documentation) Updated: https://codesandbox.io/s/mobx-state-tree-todolist-snapshotprocessor-forked-ljdge?file=/models/TodoStore.js cp: @lnpbk fw: @jamonholmgren : maybe some abilities for explain this case in documentation?
Hey folks - looks like this issue has been resolved. @akaguny - I know it's been a few years, but if you're still interested in seeing something added to the documentation, can you tell me more about what you'd be looking for?
For now, I'm going to mark this to be closed, and if I don't hear back in about two weeks, I'll close it out.
Thanks everyone!
Hey @akaguny - I see you reacted a few weeks ago. Are you still looking for documentation update? I need a little more clarity about what kind of information you'd like to see there.
Sorry, but i can't remember problem in this issue. Now i don't use state tree
All good. I'll close this out. Thanks anyway!