Alt data dependency between actions not stores
Asked Answered
M

0

0

I have a react app where I'm using alt for the flux architecture side of things.

I have a situation where I have two stores which are fed by ajax calls in their corresponding actions.

Having read the alt getting started page on data dependencies it mentions dependencies between stores using waitFor - http://alt.js.org/guide/wait-for/ but I don't see a way to use this kind of approach if one of my store actions is dependent on another store action (both of which are async).

If I was doing this inside a single action handler, I might return or chain some promises but I'm not sure how to implement this across action handlers. Has anyone achieved this? or am I going about my usage of ajax in react the wrong way?

EDIT: More detail.

In my example I have a list of nodes defined in a local json config file, my node-store makes an ajax request to get the node detail. Once it's complete, a different component (with a different action handler and store) wants to use the node collection to make an ajax query to different endpoints a node may expose.

The nodes are re-used across many different components so I don't want to roll their functionality into several different stores/action handlers if possible.

Maggiemaggio answered 21/10, 2015 at 7:31 Comment(6)
Could you give some more details? If its not in one action handler then it seems like these actions could happen independently and therefore shouldn't depend on each other? Trying to get a better idea of why the stores are dependent.Lattice
Sure, I've edited the question, in terms of dependence I think one option might be to make a call to the node-store and include that as part of the state of the component I'm working with, does this seem sensible?Maggiemaggio
In Flux terms, an ajax call is usually triggered by an action, and stores are not supposed to create an action. In you case, would it be possible to have 1 action-name to get the ajax data, and include store ID in request + response? That way, you could use waitFor to have one store what for the other to be finished. More detail (picture?) of the relationship between your stores, nodes, actions, ajax calls would help.Morphology
I'd abstract out from actions as the waitFor pattern suggest, your code should be dependant on the store data, not on particular actions.Foretopmast
Did you ever solve this problem? I'm seeing a similar situation and am asking a question on the topic. It's a bit more concretely stated tnan this and so I hope it gets some play.Cassy
I posted a question that I think covers your scenario too: #35345135Cassy

© 2022 - 2024 — McMap. All rights reserved.