- Architecting Angular Applications with Redux,RxJS,and NgRx
- Christoffer Noring
- 48字
- 2021-08-27 19:56:19
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;