skills/design-patterns/behaviorals/pattern-observer/SKILL.md
Teaches and applies the Observer behavioral design pattern — defining a subscription mechanism to notify multiple objects about events in the observed object. Trigger: When implementing event-driven systems, reactive updates, or pub/sub mechanisms.
npx skillsauth add johnnystefan/test-saas-business pattern-observerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Defines a subscription mechanism to notify multiple objects about any events that happen to the object they are observing. Essential for event-driven systems, real-time updates, and reactive architectures.
update() method with event data as parameter.subscribe(), unsubscribe(), and notify() methods to the Publisher.update() on all its subscribers whenever an important event occurs.interface Subscriber {
update(event: string, data: unknown): void;
}
class Store {
// Publisher
private subscribers: Map<string, Subscriber[]> = new Map();
subscribe(event: string, subscriber: Subscriber) {
if (!this.subscribers.has(event)) {
this.subscribers.set(event, []);
}
this.subscribers.get(event)!.push(subscriber);
}
unsubscribe(event: string, subscriber: Subscriber) {
const subs = this.subscribers.get(event) ?? [];
this.subscribers.set(
event,
subs.filter((s) => s !== subscriber),
);
}
notify(event: string, data: unknown) {
(this.subscribers.get(event) ?? []).forEach((s) => s.update(event, data));
}
changeStock(item: string, quantity: number) {
// ... update logic
this.notify('stockChanged', { item, quantity });
}
}
class EmailAlert implements Subscriber {
update(event: string, data: unknown) {
console.log(`Email sent for event: ${event}`, data);
}
}
tools
Zustand 5 state management patterns. Trigger: When implementing client-side state with Zustand (stores, selectors, persist middleware, slices).
databases
Zod 4 schema validation patterns. Trigger: When creating or updating Zod v4 schemas for validation/parsing (forms, request payloads, adapters), including v3 -> v4 migration patterns.
development
Vitest unit testing patterns with React Testing Library. Trigger: When writing unit tests for React components, hooks, or utilities.
tools
Vite 8 (Rolldown-powered) build tool configuration, plugin API, SSR, and migration guide. Trigger: When working with vite.config.ts, Vite plugins, building libraries, or SSR apps with Vite.