Skip to content
Snippets Groups Projects
Commit 3d8d9bac authored by David Baker's avatar David Baker
Browse files

Allow the dispatcher to dispatch sync if required.

parent 1041ee65
Branches
Tags
No related merge requests found
......@@ -19,13 +19,26 @@ limitations under the License.
var flux = require("flux");
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.
* Must contain at least an 'action' key.
* @param {boolean} sync Optional. Pass true to dispatch
* synchronously. This is useful for anything triggering
* 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);
}
}
};
if (global.mxDispatcher === undefined) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment