Skip to content
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

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

Closed
joshuamanns opened this issue Mar 1, 2018 · 1 comment

Comments

@joshuamanns
Copy link

joshuamanns commented Mar 1, 2018

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant