Sign in
Log inSign up

Multiple stores - best practice?

Adam Gerthel's photo
Adam Gerthel
·Mar 8, 2018

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?

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct