Skip to content

Commit 3d8d9ba

Browse files
committed
Allow the dispatcher to dispatch sync if required.
1 parent 1041ee6 commit 3d8d9ba

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

‎src/dispatcher.js‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,25 @@ limitations under the License.
1919
var flux = require("flux");
2020

2121
class MatrixDispatcher extends flux.Dispatcher {
22-
dispatch(payload) {
23-
// We always set a timeout to do this: The flux dispatcher complains
24-
// if you dispatch from within a dispatch, so rather than action
25-
// handlers having to worry about not calling anything that might
26-
// then dispatch, we just do dispatches asynchronously.
27-
setTimeout(super.dispatch.bind(this, payload), 0);
22+
/**
23+
* @param {Object} payload Required. The payload to dispatch.
24+
* Must contain at least an 'action' key.
25+
* @param {boolean} sync Optional. Pass true to dispatch
26+
* synchronously. This is useful for anything triggering
27+
* an operation that the browser requires user interaction
28+
* for.
29+
*/
30+
dispatch(payload, sync) {
31+
if (sync) {
32+
super.dispatch(payload);
33+
} else {
34+
// Unless the caller explicitly asked for us to dispatch synchronously,
35+
// we always set a timeout to do this: The flux dispatcher complains
36+
// if you dispatch from within a dispatch, so rather than action
37+
// handlers having to worry about not calling anything that might
38+
// then dispatch, we just do dispatches asynchronously.
39+
setTimeout(super.dispatch.bind(this, payload), 0);
40+
}
2841
}
2942
};
3043

0 commit comments

Comments
 (0)