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

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

Open
jrmyio opened this issue Oct 16, 2023 · 1 comment
Open

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

jrmyio opened this issue Oct 16, 2023 · 1 comment

Comments

@jrmyio
Copy link

jrmyio commented Oct 16, 2023

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:

  • Have readonly MQT type of Song, and a collection Songs.
  • Have a mutable Playlist type with an array of PlaylistItems.
  • Have both Songs and Playlist in the same RootStore?
  • Will this maintain the same performance upgrade that MQT offers on the Song objects (especially their initialization).
  • Have type.references between PlaylistItem and Song(s).

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
Copy link
Contributor

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!

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

2 participants