Skip to content

Transaction behaviour of dispatch() #769

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

Closed
wants to merge 1 commit into from

Conversation

arusakov
Copy link

Hi!
Each store.dispatch(/* some action */) will invoke all listeners callbacks. This can lead to a lot of unnecessary calls.
I propose to add some transaction-like behaviour.

store.begin();
store.dispatch({type: 1});
store.dispatch({type: 2});
// ...
store.dispatch({type: 100});
store.commit(); // and invoke listeners callbacks one time at the end

It seems to me, that the idea of transaction would be very useful in redux. But this PR has big changes in API and need some work.
Maybe another API seem more successful. Something like this easier to implement:

function dispatch(action, notNotify=false) {
// ...
}

// in app
store.dispatch({type: 1}, true);
store.dispatch({type: 2}, true);
// ...
store.dispatch({type: 100}); // and invoke listeners callbacks one time at the end

@danielkcz
Copy link

Transaction seems like bad term for this because there is no rollback which is expected from such approach. Instead I would probably call it batch. And I am not sure if batching is really necessary. I needed something like this some time ago, but I managed to implement it with simple store enhancer.

@arusakov
Copy link
Author

@FredyC batch is a good term for this. Thanks. Maybe redux-batched-subscribe is what I need.
But maybe batching inside redux will be more holistic solution. I don't know.

@gaearon
Copy link
Contributor

gaearon commented Sep 22, 2015

We don't want to expand Store API surface.
See #303 (comment) for rationale.
Indeed, redux-batched-subscribe solves this in userland.

@gaearon gaearon closed this Sep 22, 2015
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

Successfully merging this pull request may close these issues.

3 participants