3. Publishing Updates
Lesson 3: Publishing Updates
You know how ctx.publish() works. Now see that any RPC can publish to any topic - and multiple RPCs can publish to the same one.
Key insight
Publishing happens inside the RPC handler, not the stream. The stream defines the topic and merge strategy. Publishing is always explicit - you decide when and what to broadcast.
Try it
Add two new RPCs to the server file:
reset- sets count to 0 and publishessetCount- takes a number argument, sets count to that value, and publishes
Both should publish to the same 'counter' topic so the stream picks up the changes.
Then update the component to import and use both new functions. Add buttons for Reset and Set to 100 (or any number you like).
WebSocket
0
No messages yet