Skip to content

Instantly share code, notes, and snippets.

@DanielZhangQingLong
Created April 27, 2018 14:56
Show Gist options
  • Save DanielZhangQingLong/27f0b19996e9346857e73c9903f6d4a3 to your computer and use it in GitHub Desktop.
Save DanielZhangQingLong/27f0b19996e9346857e73c9903f6d4a3 to your computer and use it in GitHub Desktop.
dispatcher for flux
export default class Dispatcher {
constructor() {
//this._id = 0;
// Store add all the reducers.
this._callbacks = [];
}
register(callback) {
// key is a timestamp, value is the callback
//let id = (new Date()).getTime();
//this._callbacks[id] = callback;
console.log('Push a reducer:\n', callback);
this._callbacks.push(callback);
}
dispatch(action) {
console.log('Dispatch an action:\n', action);
console.log('Now all callbacks are:\n', this._callbacks);
this._callbacks.map((callback) => callback(action));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment