2.2 KiB
| id | title | status | assignee | created_date | updated_date | labels | milestone | dependencies | references | priority | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| TASK-43 | Implement Event Broadcasting: canvas-wide pub/sub system | Done | 2026-02-18 20:06 | 2026-03-11 23:14 |
|
m-1 |
|
|
medium |
Description
Add a pub/sub event system so shapes can broadcast and subscribe to named events across the canvas.
New file lib/event-bus.ts:
- CanvasEventBus class with emit(), subscribe(), unsubscribe(), getSubscribers()
- Events written to CRDT doc.eventLog (bounded ring buffer, last 100 entries)
- Remote users see events replayed via Automerge patch application
- Re-entrancy guard kills chains after 10 levels to prevent infinite loops
Automerge schema additions:
- doc.eventLog: EventEntry[] (id, channel, sourceShapeId, payload, timestamp)
- shapes[id].subscriptions: string[] (channel names)
Shapes opt in with onEventReceived(channel, payload) method.
Example: Timer emits "timer:done" → all subscribed Budget shapes recalculate.
Acceptance Criteria
- #1 CanvasEventBus emits events to CRDT eventLog
- #2 Shapes can subscribe to channels and receive events
- #3 Events sync to remote users via Automerge
- #4 Ring buffer bounded at 100 entries with GC
- #5 Re-entrancy guard prevents infinite event loops
- #6 Works offline (events queued in CRDT, replayed on reconnect)
Implementation Notes
Implementation started: CanvasEventBus class, CommunityDoc schema updates, CommunitySync helper methods
Complete. Created lib/event-bus.ts with CanvasEventBus class. Updated CommunityDoc with eventLog field, ShapeData with subscriptions field. Added appendEvent(), getEventLog(), setShapeSubscriptions(), getShapeSubscriptions(), getShapesSubscribedTo(), getShapeElement() methods to CommunitySync. Added eventlog-changed dispatch in both patch and full-sync paths. Added onEventReceived() optional method on FolkShape. Exported from lib/index.ts.