I use Flux from Facebook, react, ES6.
I have different problems with these single-user stores. However, repeating is the next. I send one action from one component, and I have two stores (StoreA, StoreB) that listen to this action.
My two stores are in two different files, and in each I export a singleton repository instance. Both stores have already been imported into the appropriate container (representation of the React component). I want StoreA to wait for StoreB to finish processing the current dispatch before starting the process in StoreA.
I read the document and there is a waitFor method that can be used with the token returned by the register method from the dispatcher. However, my two stores are in different files. Cannot find a way to access StoreB token from StoreA ...
In other words:
ReactComp.js
...
handleClick() {
dispatcher.dispatch({
type: 'ACTION1'
});
}
StoreA.js
class StoreA {
constructor() {
this.dispatchToken = dispatcher.register((action) => {
switch(action.type) {
case 'ACTION1':
break;
}
});
}
}
export default new StoreA();
StoreB.js
class StoreB {
constructor() {
dispatcher.register((action) => {
switch(action.type) {
case 'ACTION1':
dispatcher.waitFor([storeADispatchToken]);
break;
}
});
}
}
export default new StoreB();
I am new to the architecture of response and flow, the answer may be obvious and sorry if there is one, however with all the hours that have been unsuccessfully looking for an answer, I rely on SO ..
source
share