goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 321 forks source link

Using bindListeners vs Store.listen emits changes several seconds slower #722

Closed joshuamanns closed 6 years ago

joshuamanns commented 6 years ago

I have a strange experience happening with Alt.js I could use some thoughts on.

I have a Store that uses bindListeners to bind an action to another store's action. It works, however, the action fires much later than if I use MyStore.listen(...) and dispatch my action from within that callback.

The basic setup is

  1. Dispatch ActionA from StoreA
  2. When a response is received from the server, dispatch ActionB from StoreA, which updates StoreA.myProp.
  3. In StoreB, bindListeners ActionC to StoreA.ActionB ...waitFor(StoreA) and read StoreA.getState().myProp

ActionC fires when StoreA.ActionB fires. This takes 7-8 seconds including round-trip to server.

The faster way is

  1. Dispatch ActionA from StoreA
  2. When a response is received from the server, dispatch ActionB from StoreA, which updates StoreA.myProp
  3. Use React componentDidMount() to StoreA.listen((state) => { StoreB.ActionC.defer() }) where the state has an updated StoreA.myProp before StoreA.ActionB even appears to dispatch...

This takes 2-3 seconds including round-trip to server.

Any thoughts???

joshuamanns commented 6 years ago

This turned out to be a non-issue and was related to a different area of the application codebase