Allow the dispatcher to dispatch sync if required.

This commit is contained in:
David Baker 2015-10-20 11:02:54 +01:00
parent 1041ee654e
commit 3d8d9bac8e

View file

@ -19,12 +19,25 @@ limitations under the License.
var flux = require("flux"); var flux = require("flux");
class MatrixDispatcher extends flux.Dispatcher { class MatrixDispatcher extends flux.Dispatcher {
dispatch(payload) { /**
// We always set a timeout to do this: The flux dispatcher complains * @param {Object} payload Required. The payload to dispatch.
// if you dispatch from within a dispatch, so rather than action * Must contain at least an 'action' key.
// handlers having to worry about not calling anything that might * @param {boolean} sync Optional. Pass true to dispatch
// then dispatch, we just do dispatches asynchronously. * synchronously. This is useful for anything triggering
setTimeout(super.dispatch.bind(this, payload), 0); * an operation that the browser requires user interaction
* for.
*/
dispatch(payload, sync) {
if (sync) {
super.dispatch(payload);
} else {
// Unless the caller explicitly asked for us to dispatch synchronously,
// 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);
}
} }
}; };