mobx-state-tree icon indicating copy to clipboard operation
mobx-state-tree copied to clipboard

Cannot use `types.snapshotProcessor` response in reference

Open lnpbk opened this issue 5 years ago • 3 comments

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.

lnpbk avatar Mar 07 '20 13:03 lnpbk

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?

mnargiForesee avatar Nov 09 '20 16:11 mnargiForesee

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 avatar Nov 09 '20 22:11 Relaxe111

@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?

akaguny avatar Dec 10 '20 20:12 akaguny

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!

coolsoftwaretyler avatar Jun 30 '23 03:06 coolsoftwaretyler

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.

coolsoftwaretyler avatar Jul 13 '23 22:07 coolsoftwaretyler

Sorry, but i can't remember problem in this issue. Now i don't use state tree

akaguny avatar Jul 14 '23 05:07 akaguny

All good. I'll close this out. Thanks anyway!

coolsoftwaretyler avatar Jul 15 '23 04:07 coolsoftwaretyler