April 2020
Intermediate to advanced
292 pages
6h 50m
English
Message handlers are functions that receive a message and do something. For Components that’ll mean carrying out some state-changing business function. For Aggregators that means updating a View Data.
We define an autonomous component’s message handlers as a JavaScript object whose keys are the message types the component handles. This Aggregator needs to handle VideoViewed events, and when we get one, we want to increment the global watch count by 1. So let’s write that first handler:
| | function createHandlers ({ queries }) { |
| | return { |
| | VideoViewed: event => queries.incrementVideosWatched(event.globalPosition) |
| | } |
| | } |
createHandlers receives the queries from the ...
Read now
Unlock full access