Event Bus Pattern with Stores
Implement a global event bus using a writable store for decoupled communication.
Event Bus
An event bus is a global publish/subscribe channel for decoupled communication.
Implement with writable
A writable store carrying the latest event acts as a simple bus.
const bus = writable(null);
export function emit(event) { bus.set(event); }
export function on(fn) { return bus.subscribe(e => { if (e) fn(e); }); }All lessons in this course
- Store Architecture: Feature Modules
- Event Bus Pattern with Stores
- Optimistic UI Updates
- Undo/Redo with Store History