Coding task · JavaScript and React course · Module 15: Patterns and Architecture
Practice: Many Publishers and Subscribers
Each publisher only emits events, and each subscriber listens to them independently: you can remove ShipLog and the rest keeps working. The log listens to the ship:log event, so it shows entries from the shields and from the alerts although it knows neither of these components. The slider value arrives as a string, which is why the code turns it into a number (Number). The new array [newest, ...old] puts the entry first, and slice(0, 8) cuts the list down to eight items.
Task
The EventBus and the hooks are ready, finish two publishers and two subscribers. ___BLANK1___: after the slider moves, ShieldControl emits shields:level with the new level as a number (next, not the old value from state). ___BLANK2___: on a click AlertSystem emits alert:status with the alert level (alert.level: green, yellow or red). ___BLANK3___: StatusDashboard listens to the event that changes the alert state. ___BLANK4___: ShipLog adds a new entry at the beginning of the list and keeps at most the 8 newest entries.