Intermediate
A Safe Reducer
The chat state is handled by reduce(state, action). Four buttons drive it: #send (a question), #token (a piece for the latest answer), #stale (a piece for an answer that is no longer current) and #stop.
Make the reducer refuse what doesn't fit. A send while the chat is busy is ignored. A token or stop whose id is not state.currentId is ignored. After stop, the answer's id is no longer current, so a late token cannot change it.
#status shows Status: <status>, #count the number of messages and #text the text of the last answer.
What Check tests
- Before anything:
Status: idleand no messages - A send adds two messages and the status is waiting
- A second send while busy is ignored
- A token adds its text to the last answer
- A token for an old id is ignored
- After stop, the status is done and a late token changes nothing
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.