@ahoo-wang/fetcher-eventbus 2.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,61 @@
1
+ import { EventHandler, EventType } from './types';
2
+ import { TypedEventBus } from './typedEventBus';
3
+ /**
4
+ * Supplier function for creating TypedEventBus instances by event type
5
+ */
6
+ export type TypeEventBusSupplier = (type: EventType) => TypedEventBus<unknown>;
7
+ /**
8
+ * Generic event bus that manages multiple event types using lazy-loaded TypedEventBus instances
9
+ *
10
+ * @template Events - A record mapping event types to their event data types
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const supplier = (type: EventType) => new SerialTypedEventBus(type);
15
+ * const bus = new EventBus<{ 'user-login': string; 'order-update': number }>(supplier);
16
+ * bus.on('user-login', { name: 'logger', order: 1, handle: (event) => console.log(event) });
17
+ * await bus.emit('user-login', 'john-doe');
18
+ * ```
19
+ */
20
+ export declare class EventBus<Events extends Record<EventType, unknown>> {
21
+ private readonly typeEventBusSupplier;
22
+ private readonly buses;
23
+ /**
24
+ * Creates a generic event bus
25
+ *
26
+ * @param typeEventBusSupplier - Function to create TypedEventBus for specific event types
27
+ */
28
+ constructor(typeEventBusSupplier: TypeEventBusSupplier);
29
+ /**
30
+ * Adds an event handler for a specific event type
31
+ *
32
+ * @template Key - The event type
33
+ * @param type - The event type to listen for
34
+ * @param handler - The event handler to add
35
+ * @returns true if the handler was added, false if a handler with the same name already exists
36
+ */
37
+ on<Key extends EventType>(type: Key, handler: EventHandler<Events[Key]>): boolean;
38
+ /**
39
+ * Removes an event handler for a specific event type
40
+ *
41
+ * @template Key - The event type
42
+ * @param type - The event type
43
+ * @param name - The name of the event handler to remove
44
+ * @returns true if a handler was removed, false otherwise
45
+ */
46
+ off<Key extends EventType>(type: Key, name: string): boolean;
47
+ /**
48
+ * Emits an event for a specific event type
49
+ *
50
+ * @template Key - The event type
51
+ * @param type - The event type to emit
52
+ * @param event - The event data
53
+ * @returns Promise if the underlying bus is async, void otherwise
54
+ */
55
+ emit<Key extends EventType>(type: Key, event: Events[Key]): void | Promise<void>;
56
+ /**
57
+ * Cleans up all managed event buses
58
+ */
59
+ destroy(): void;
60
+ }
61
+ //# sourceMappingURL=eventBus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventBus.d.ts","sourceRoot":"","sources":["../src/eventBus.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,SAAS,KAAK,aAAa,CAAC,OAAO,CAAC,CAAC;AAE/E;;;;;;;;;;;;GAYG;AACH,qBAAa,QAAQ,CAAC,MAAM,SAAS,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC;IAQjD,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAPjD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqD;IAE3E;;;;OAIG;gBAC0B,oBAAoB,EAAE,oBAAoB;IAGvE;;;;;;;OAOG;IACH,EAAE,CAAC,GAAG,SAAS,SAAS,EACtB,IAAI,EAAE,GAAG,EACT,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GACjC,OAAO;IASV;;;;;;;OAOG;IACH,GAAG,CAAC,GAAG,SAAS,SAAS,EACvB,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,MAAM,GACX,OAAO;IAIV;;;;;;;OAOG;IACH,IAAI,CAAC,GAAG,SAAS,SAAS,EACxB,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,GACjB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvB;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB"}
@@ -0,0 +1,7 @@
1
+ export * from './eventBus';
2
+ export * from './parallelTypedEventBus';
3
+ export * from './serialTypedEventBus';
4
+ export * from './typedEventBus';
5
+ export * from './broadcastTypedEventBus';
6
+ export * from './types';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,SAAS,CAAC"}