I’m currently building a prototype for a text-based RPG using React+MobX and I’m stuck on the matter of how to use the stores. For example, the game will have items, such as swords, potions, helmets as well as NPCs, mobs etc. So my initial thought was to have multiple stores such as, for example:
UI (current view, device dimensions, etc.)
Navigation (where the player is located, movement, where he/she can go and what options are available in a location)
Inventory (picked up items, equipped items etc.)
Questlog (ongoing quests etc.)
…and a few more. But I immediately stumbled on a problem with having multiple stores, i.e. that I have an action in the Navigation store (pickUpItem) which affects the Inventory store. I read the best practices for multiple stores but it didn’t really make things clearer for me since it offers multiple ways to do it.
So - my question to you is: How would you solve this? Combine multiple stores? Use Mobx State Tree? Keep everything in a single store? Import the instantiated stores to each other?
Nick Luparev
front-end developer working with react/redux/elm
For things you describe at items such as swords, potions, helmets as well as NPCs I would not consider them as Stores I guess I would implement them as models. I, personally, use Stores as a way to collect some state outside of React's Component tree. I can have Store which has observable attributes which hold a list of Models, inventory for example and so on.
What about Combining stores it really depends on what you want to achieve. If you need to do something as a result of something has happened on one store, for example, a user has moved and Position store changed coordinates and you may have some other store which should react to this changes in some way and may use reactions for this case.
Another case might be that you just need to recompute something because some Store's value you depend on in some distant store has changed and you need to have different values now you might consider to use plain computed properties
If I didn't answer your question please post some real case scenario you want to implement and maybe I can help you with that.