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

Feature Request: Batch dispatch actions #2108

Closed
eloytoro opened this issue Nov 16, 2016 · 1 comment
Closed

Feature Request: Batch dispatch actions #2108

eloytoro opened this issue Nov 16, 2016 · 1 comment

Comments

@eloytoro
Copy link

eloytoro commented Nov 16, 2016

Right now redux's listeners are synchronous, this means that for every dispatch call all the listeners will trigger, and if many happen at the same time then all the listeners will trigger that same amount of times

store.subscribe(() => console.log('hello'))

store.dispatch(...) // 'hello'
store.dispatch(...) // 'hello'

If for example there are many dispatch calls that trigger react DOM redraw it would be much better if it only happened once since it might save itself some extra computation

store.subscribe(() => console.log('hello'))

// this is completely made up, it would dispatch all these actions in a bulk
store.batch([
  (action1),
  (action2),
  ...
]);
// 'hello'

Or maybe if we stack up dispatches and clear that stack in the next tick the results might be different

store.subscribe(() => console.log('hello'))
store.lazyDispatch(...)
store.lazyDispatch(...)
// async 'hello' log in the next tick
@markerikson
Copy link
Contributor

This is something that can be handled in "userland", outside of core Redux itself. There's a number of approaches that can be used - middleware, higher order reducers, store enhancers, etc. See http://redux.js.org/docs/faq/Actions.html#actions-multiple-actions and http://redux.js.org/docs/faq/Performance.html#performance-update-events for further info, and in particular the discussion in #1813 . My Redux addons catalog lists the various change subscription libraries out there, including an enhancer that supports dispatching arrays.

brandoncroberts pushed a commit to brandoncroberts/redux that referenced this issue Oct 13, 2023
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

2 participants