gadget-inc / mobx-quick-tree

A mirror of the mobx-state-tree API that supports creating a fast, non-reactive, read-only tree
MIT License
15 stars 2 forks source link

Can you mix and match readonly / mutable MQT types? #64

Open jrmyio opened 11 months ago

jrmyio commented 11 months ago

Hello,

I have not tried out this library yet but I have faced similar issues this library tries to solve, so I am really interested in giving this a try.

When going over the documentation there is section about mixing MST and MQT: https://github.com/gadget-inc/mobx-quick-tree#mixing-mobx-state-tree-and-mobx-quick-tree

It is clear to me you need to fully switch to importing MQT as you cannot combine MST and MQT.

However, what i am missing is some notes about whether you can use MQT readonly types with mutable MQT types. For example, can the following be done with this library:

If this is supposed to work. Would RootStore be a readonly, or mutable store, considering it holds both readonly and mutable MQT types ({ songs: Songs, playlist: Playlist })?

airhorns commented 11 months ago

Hi @jrmyio -- I don't think we've ever tried mixing and matching! At Gadget our tree is either entirely observable or entirely readonly. I suspect it won't work out of the box, but I think you could work around it by setting the parts of your tree that you want to be readonly to use a types.frozen and constructs the readonly instances for those bits before passing the snapshot to your root. We could add a types.readonly that does the instantiation under the hood as well I guess -- that seems generally useful!