A
A
Alexander Mylchenko2017-06-19 19:26:06
flux
Alexander Mylchenko, 2017-06-19 19:26:06

How do you solve Flux's "Cannot dispatch in the middle of a dispatch" problem?

Good afternoon/evening,
Colleagues, please tell me how you solve the problem of Flux async?
By chance, I came across this solution:

import Flux from "flux";
const AppDispatcher = new Flux.Dispatcher();

AppDispatcher.deferDispatch = function( value ) {
  if( AppDispatcher.isDispatching() == true ) {
    setTimeout( () => AppDispatcher.dispatch( value ), 0 );
  } else AppDispatcher.dispatch( value );
}

export default AppDispatcher ;

But setTimeout( ..., 0 ) ... gives me nightmares, maybe you could come up with a more original/beautiful/modern solution?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question