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

Call dispatch with more than one argument #682

Closed
eugeny-dementev opened this issue Apr 16, 2017 · 2 comments
Closed

Call dispatch with more than one argument #682

eugeny-dementev opened this issue Apr 16, 2017 · 2 comments

Comments

@eugeny-dementev
Copy link

Original redux dispatch allow to pass more than one argument thats in result will be received in the middleware and all passed arguments will be logged. It's very useful and flexible. But dispatch function that passed to mapDispatchToProps handle only first argument and middleware always log array with that first argument.

// Redux 3.6.0

const middlewares = [
  function logArguments (store) {
    return next => (...args) => {
      console.log(args);

      next(...args);
    }
  }
];

const store = createStore(() => {}, applyMiddleware(...middlewares));

store.dispatch({ type: 'NOOP' }, { arg: 'second' }, { arg: 'third' });
// [ { type: 'NOOP' }, { arg: 'second' }, { arg: 'third' } ]

Actually i didn't find any documentation about this way to use dispatch so it'll be nice to also clarify that moment.

@markerikson
Copy link
Contributor

This is a question regarding Redux, not React-Redux. In particular, this was heavily discussed in reduxjs/redux#1813 . As a quick summary of that thread, it won't work because the entire ecosystem assumes that only one thing is passed to dispatch at a time. If you're looking to batch up dispatched actions (especially to minimize the number of subscriber notifications), there's a variety of possible batching addons you can use, such as https://github.com/manaflair/redux-batch .

@eugeny-dementev
Copy link
Author

Thank you. You were right, the issue is about ecosystem. It was previuos middleware thats handle and pass to next callback only one argument.

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