From 27ca7b48f742bdadeac2d2a550ceef34742645bc Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 5 Oct 2015 18:43:22 +0100 Subject: [PATCH] Just do all dispatches async: setting the flag obviously does not work for more than 2 nested dispatches. --- src/dispatcher.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/dispatcher.js b/src/dispatcher.js index 67d2944cf8..4b856bf310 100644 --- a/src/dispatcher.js +++ b/src/dispatcher.js @@ -20,13 +20,11 @@ var flux = require("flux"); class MatrixDispatcher extends flux.Dispatcher { dispatch(payload) { - if (this.dispatching) { - setTimeout(super.dispatch.bind(this, payload), 0); - } else { - this.dispatching = true; - super.dispatch(payload); - this.dispatching = false; - } + // We always set a timeout to do this: The flux dispatcher complains + // if you dispatch from within a dispatch, so rather than action + // handlers having to worry about not calling anything that might + // then dispatch, we just do dispatches asynchronously. + setTimeout(super.dispatch.bind(this, payload), 0); } };