From 94759c3b76b6beb62f96b1e44cd6f6625170bb52 Mon Sep 17 00:00:00 2001 From: Marcelo Paternostro Date: Sat, 19 Apr 2025 15:28:00 -0400 Subject: [PATCH] use more strongly typed examples --- src/shared/eventNotifier.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/shared/eventNotifier.ts b/src/shared/eventNotifier.ts index 877f4757..a1f53238 100644 --- a/src/shared/eventNotifier.ts +++ b/src/shared/eventNotifier.ts @@ -54,12 +54,12 @@ export type EventNotifier = { * @example * * ```ts - * const notifier = createEventNotifier<{ type: string; data: unknown }>(); + * const notifier = createEventNotifier<{ type: string; value: number }>(); * notifier.onEvent((event) => { - * console.log(`Received ${event.type} with data:`, event.data); + * console.log(`Received ${event.type} with value:`, event.value); * }); * - * notifier.notify({ type: 'update', data: { id: 123, status: 'complete' } }); + * notifier.notify({ type: 'progress', value: 75 }); * ``` * * @param event The event to send to all listeners or a function that returns such event. @@ -91,12 +91,15 @@ export type EventNotifier = { * const stringNotifier = createEventNotifier(); * * // Complex object event notifier - * interface UserEvent { - * type: 'created' | 'updated' | 'deleted'; - * userId: number; - * data?: Record; + * interface TaskEvent { + * type: 'started' | 'completed' | 'failed'; + * taskId: number; + * details: { + * name: string; + * duration?: number; + * }; * } - * const userNotifier = createEventNotifier(); + * const taskNotifier = createEventNotifier(); * ``` * * @template T The type of events this notifier will handle