0Pricing
Sveltejs Academy · Lesson

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

  1. Store Architecture: Feature Modules
  2. Event Bus Pattern with Stores
  3. Optimistic UI Updates
  4. Undo/Redo with Store History
← Back to Sveltejs Academy