quarrant / mobx-persist-store

Persist and rehydrate observable properties in mobx store.
268 stars 14 forks source link

Question: Is it possible to persist multiple instances of a store without separately naming them? #109

Open ThaJay opened 11 months ago

ThaJay commented 11 months ago

Example:

How would this work?

At the moment I may be able through some finaggling save WidgetStore instances on ChosenWidgetsStore

But what if I don't have the instances in a store? What if I have a bunch of Widget components who all have their own WidgetStore? I could use some kind of string passed in the constructor and add it to the name to make it unique.

What if I don't have that kind of information or don't want my instanced stores to have that kind of information because of dependencies and decoupling?

We already give this to makePersistable. So we could already identify an instance in memory by checking with triple equality. Would it also be possible to do something like this for persisted stores? Where makePersistable has information about the actual instance that called it? If possible this could also make the name property obsolete.

Let me know your thoughts.

ThaJay commented 11 months ago

I have some kind of a ORM with Mobx stores. The data is relational and has a tree like structure. One Location has many Connections, has many Usages.

I would love to be able to save my whole tree.

Now I can only save the non recursive elements of the tree. That is, only the models that can ever have only one instance.

quarrant commented 8 months ago

Soooo. It's really hard to persist recursive trees and I don't know how soon we can do it. You would better writing your own solution

ThaJay commented 6 months ago

Thank you for your answer. Perhaps I should start reading about Mobx State Tree again.