Listening to the dispatcher

We have established that the dispatcher dispatches a message to anyone who will listen. Now it is time to be that listener. The dispatcher needs a register or subscribe method so that you, who listens, have the ability to listen for incoming messages. The setup for that usually looks something like this:

dispatcher.register(function(message){});

Now, when you set up a listener this way, it will have the capability to listen to any message type being sent. You want to narrow this down; usually, a listener is specified to only handle a few message types around a certain theme. Your listener most likely looks something like this:

dispatcher.register((message) => {  switch(message.type) {    case 'SELECT_ITEM': // do something ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.