Skip to content

Commit 94759c3

Browse files
committed
use more strongly typed examples
1 parent 112eed9 commit 94759c3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/shared/eventNotifier.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ export type EventNotifier<T, E = Error> = {
5454
* @example
5555
*
5656
* ```ts
57-
* const notifier = createEventNotifier<{ type: string; data: unknown }>();
57+
* const notifier = createEventNotifier<{ type: string; value: number }>();
5858
* notifier.onEvent((event) => {
59-
* console.log(`Received ${event.type} with data:`, event.data);
59+
* console.log(`Received ${event.type} with value:`, event.value);
6060
* });
6161
*
62-
* notifier.notify({ type: 'update', data: { id: 123, status: 'complete' } });
62+
* notifier.notify({ type: 'progress', value: 75 });
6363
* ```
6464
*
6565
* @param event The event to send to all listeners or a function that returns such event.
@@ -91,12 +91,15 @@ export type EventNotifier<T, E = Error> = {
9191
* const stringNotifier = createEventNotifier<string>();
9292
*
9393
* // Complex object event notifier
94-
* interface UserEvent {
95-
* type: 'created' | 'updated' | 'deleted';
96-
* userId: number;
97-
* data?: Record<string, unknown>;
94+
* interface TaskEvent {
95+
* type: 'started' | 'completed' | 'failed';
96+
* taskId: number;
97+
* details: {
98+
* name: string;
99+
* duration?: number;
100+
* };
98101
* }
99-
* const userNotifier = createEventNotifier<UserEvent>();
102+
* const taskNotifier = createEventNotifier<TaskEvent>();
100103
* ```
101104
*
102105
* @template T The type of events this notifier will handle

0 commit comments

Comments
 (0)