Communication between stores in the same tree #1902
Unanswered
juanmavillarrazadb
asked this question in
Q&A
Replies: 1 comment 2 replies
-
What is the end goal you are trying to achieve with |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi every body, this is my first time with a discussion here and I'm an argentinian guy xD, my apologize for the spelling mistakes, so if you don't understand something or whatever just let me know...
With my work team (a great one) are building a defi trading multi-chain platform (awesome project) and we decided to choose MST for our application state within react and many others techs.
We push to standardize and design our state of the application based on the business logic, so imagine the following scenario (little approach of what we're looking for in many parts of the app).
The app has a root store, that contains 2 different store, one for the
user
state, and the other for theassets
state. Theuser
one only has simple data and anassetId
that will be used to "populate" some sort of market information from theassets
one, like for example the market price through a method calledgetById
defined on it.Our idea is to consume this information from the
assets
store inside theuser
one with Computed value, to achieve this we try three different ways to access a method from an other store, with getRoot, getParent or storing a safereference. And here is the main problem, we are not able to access the last node state of theassets
store inside theuser
one, even when the assets mocked data has been loaded. So we don't know if doing this is a good practice, something possible with this tech or there is something I'm not seeing... We find a "solution" which I believe that is ninja fix and I don't feel comfortable using it, executing agetSnapshot(assets)
inside thegetter
and forcing MST to get the last state of the node giving us the expected behavior.I also try some others alternatives that you can check on the example repo. Here is the link of a simple code base that reproduce our actual problem in the app: https://github.com/juanmavillarraza/mst-issue
Beta Was this translation helpful? Give feedback.
All reactions