xaviergonz / mobx-keystone

A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more
https://mobx-keystone.js.org
MIT License
555 stars 25 forks source link

Unprotect equivalent in MK #142

Closed garrettg123 closed 4 years ago

garrettg123 commented 4 years ago

I'm not sure if MK supports this, but MST has an unprotect(store) function. I know it's not recommended, but I used it after getting frustrated with not being able to trigger actions on other branches. To be honest, I'm not sure why this isn't recommended. Again, great work, just posing the question in the hopes that it helps others as well.

xaviergonz commented 4 years ago

It is not recommended because as soon as you modify something without an action (unprotected) then action capturing + replication won't ensure they end in the same state. E.g., if you have a sever that captures actions and sends them to clients to be replicated, yet this server does mutations outside of actions, then the clients will get out of sync eventually.

mobx-keystone does support something similar, "runUnprotected", which allows a piece of code to do mutations without requiring an action. Would that serve you in your use case?

xaviergonz commented 4 years ago

Closing due to inactivity, feel free to reopen if needed