上QQ阅读APP看书,第一时间看更新
Adding the dispatcher
Next off we need a dispatcher that is able to take our message, like so:
// demo/dispatcher.js
class Dispatcher {
constructor() {
this.listeners = [];
}
dispatch(message) {
this.listeners.forEach(listener => listener(message));
}
register(listener) {
this.listeners.push(listener);
}
}
const dispatcher = new Dispatcher();
export default dispatcher;