22. Channels
Lesson 22: Channels
Streams have an init function that returns historical data. But sometimes you just want fire-and-forget events with no history.
live.channel() creates a lightweight pub/sub subscription:
export const alerts = live.channel('alerts', { merge: 'crud', key: 'id' }); No init function, no stored data. Subscribers only see events that happen after they connect. Perfect for notifications, typing indicators, or ephemeral signals.
By default channels use merge: 'set' (single latest value, like a status indicator). For an accumulating list of notifications, pass { merge: 'crud', key: 'id' } so each published item is appended.
Try it
- Create a
notificationschannel on the'alerts'topic withmerge: 'crud'andkey: 'id' - Create a
notify(text)RPC that publishes a notification object to'alerts'with event'created' - Each notification needs an
id,text, andtimestamp
WebSocket
0
No messages yet