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

When using batch, do not receive error when calling dispatch inside of dispatch #225

Open
wrightnathan opened this issue Oct 21, 2016 · 2 comments

Comments

@wrightnathan
Copy link

wrightnathan commented Oct 21, 2016

The following code will not throw an error in console:

in my componentDidMount():

Reactor.batch(() => {
    Reactor.dispatch('DISPATCH1');
})

in my store:

initialize() { 
    this.on('DISPATCH1', (state) => {
        Reactor.dispatch('DISPATCH2');
        return state;
    });
    this.on('DISPATCH2', (state) => { return state.set('blah', foo);} );
}

This will execute DISPATCH2 inside of DISPATCH1, but will result in the changes made by DISPATCH2 being thrown away (instead of receiving an error message).

If I remove the batch, then I receive the following error message:

nuclear.js:5647Uncaught Error: Dispatch may not be called while a dispatch is in progress

@code-shoily
Copy link

It is showing that error because you are dispatching DISPATCH2 from within the handler of DISPATCH1. That yielded the error. Try moving that logic to an action.

@wrightnathan
Copy link
Author

I realize there's a problem with my code. However, the issue I raised is that you don't get any sort of error from nuclear if you do this inside of a batch.

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