0/24
11. Merge: Latest

Lesson 11: Merge: Latest

Sometimes you don't need a full list - just the most recent events. That's what merge: 'latest' does.

It works like a ring buffer: new events push in, old ones fall off when the buffer is full.

live.stream('feed', () => entries, {
  merge: 'latest',
  max: 10  // keep only the last 10
});

This is perfect for activity feeds, notification lists, or event logs where you only care about recent history.

Try it

  1. Create an addEntry RPC that takes a text parameter
  2. Each entry should have an id (use crypto.randomUUID()), text, and timestamp (use Date.now())
  3. Create a feed stream with merge: 'latest' and max: 10
WebSocket
0
No messages yet
User A
User B