Created
April 27, 2018 14:56
-
-
Save DanielZhangQingLong/27f0b19996e9346857e73c9903f6d4a3 to your computer and use it in GitHub Desktop.
dispatcher for flux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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