官术网_书友最值得收藏!

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
}
});

OK, so we are able to filter out only the message types we care about, but before actually filling in some code we need to think about who this listener is. The answer is simple: it is the store.

主站蜘蛛池模板: 旌德县| 谢通门县| 盈江县| 汶上县| 清苑县| 镇原县| 龙口市| 衡水市| 乌兰县| 临邑县| 凤城市| 临夏市| 黎川县| 普兰县| 林甸县| 四川省| 东平县| 桐梓县| 图木舒克市| 山西省| 漯河市| 独山县| 惠来县| 天等县| 湾仔区| 汉沽区| 宁海县| 保山市| 得荣县| 韩城市| 吴忠市| 江津市| 米泉市| 瑞丽市| 山东省| 灌南县| 隆化县| 锦州市| 墨脱县| 南城县| 长宁区|