-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Data store dependency #209
Comments
If you can determine the stats for the StoreB just by looking at the payload of action that updates StoreA then you can just subscribe to that action with StoreB. |
I think dispatching two actions would work best for me. because the updates to StoreA are incremental, therefore I only need to run the calculation on the diff data. module X ---> dispatch 20 records ----> StoreA -----> dispatch 20 records -----> StoreB -----> calculate stats for 20 records ----> store stats on StoreB new updates -----> dispatch 5 records ----> StoreA ----> dispatch 5 records ----> StoreB -----> calculate stats for 5 records -----> add new stats to old stats ---> store sum(stats) in StoreB so I guess that this is working, but not sure if this is the best solution. |
Based on the current description of your data model, to me it sounds like the a getter would be most appropriate. I think that Stores should only store the minimum state necessary for the application, and anything that can be derived should be a getter. If whatever is calculated in StoreB is purely derived from the latest state of StoreA, then I would argue that it should be a getter and not a piece of state. As long as all data retrievals are abstracted through getters, then the part of the application that is retrieving this data should not care whether StatB was maintained in a store or if it was just derived in a getter. If the above does not work for you, another thing to consider is: Do you need StoreB to be a separate store? Maybe you could move this functionality into StoreA as another property. This way, when StoreA receives its action, it can first do its original processing, then do the secondary calculation (originally from StoreB) as part of the same action handler. |
I have StoreA and StoreB that need data from StoreA, do some calculation and store the stats. Anytime StoreA changes, StoreB do the calculations and store the latest stats.
Do you know how to implement this in NuclearJS?
I was thinking to use getters, since they have the ability to declare data dependency, but getters don't have a state that can store data.
The text was updated successfully, but these errors were encountered: