Managing dependencies between store.

One use case explain in Facebook Flux documentation is the ability of the dispatcher to manage stores's dependencies.

As an application grows, the dispatcher becomes more vital, as it can be used to manage dependencies between the stores by invoking the registered callbacks in a specific order. Stores can declaratively wait for other stores to finish updating, and then update themselves accordingly.

In Sinux, this is trivial. As Store signal return Promise is easy to implement waitFor using ES6/7.

The Promise way

store1.signal.add( (state, args) => {
  return store2.signal(args).then( (s2State) => s2State);
});

The Generator Function way

As sinux use the co library we can use generator function to yield call

store1.signal.add( function *(state, ...args) {
  const store2State = yield store2.signal(...args);
  return whatYouNeed;
});

The Async/Await way

Sinux support also ES7 async/await function

store1.signal.add( async function (state, ...args) => {
  const store2State = await store2.signal(...args);
  return whatYouNeed;
});

results matching ""

    No results matching ""