Handling Asynchronous Messages
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 ...
Get Practical Microservices 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.