signal-controller
Advanced tools
+4
-0
@@ -5,2 +5,3 @@ declare const ONCE_SYMBOL: unique symbol; | ||
| declare const CLEAR_ALL_SIGNALS: unique symbol; | ||
| declare const COUNT_LISTENERS: unique symbol; | ||
| interface ListenerFunction { | ||
@@ -41,2 +42,3 @@ (...args: any[]): unknown; | ||
| [CLEAR_ALL_SIGNALS](): void; | ||
| [COUNT_LISTENERS](signalName: keyof T): number; | ||
| } | ||
@@ -65,4 +67,6 @@ interface SignalControllerOptions { | ||
| destroy(): void; | ||
| /** Checks whether there are listeners attached for the specified signal. */ | ||
| testSignal(signalName: keyof T): boolean; | ||
| /** Creates a writable stream that produces signals of the specified type for each chunk of data it receives. */ | ||
| createWritableStream<K extends keyof T>(signalName: K): WritableStream<Parameters<T[K]>>; | ||
| } |
+8
-0
@@ -5,2 +5,3 @@ const ONCE_SYMBOL = Symbol('once'); | ||
| const CLEAR_ALL_SIGNALS = Symbol('clear'); | ||
| const COUNT_LISTENERS = Symbol('countListeners'); | ||
| /** This class is used to listen to signals. */ | ||
@@ -118,2 +119,5 @@ class SignalEmitter { | ||
| } | ||
| [COUNT_LISTENERS](signalName) { | ||
| return this.#listeners.get(signalName)?.size ?? 0; | ||
| } | ||
| } | ||
@@ -178,2 +182,6 @@ /** This class is used to emit signals. */ | ||
| } | ||
| /** Checks whether there are listeners attached for the specified signal. */ | ||
| testSignal(signalName) { | ||
| return this.emitter[COUNT_LISTENERS](signalName) > 0; | ||
| } | ||
| /** Creates a writable stream that produces signals of the specified type for each chunk of data it receives. */ | ||
@@ -180,0 +188,0 @@ createWritableStream(signalName) { |
+1
-1
| { | ||
| "name": "signal-controller", | ||
| "version": "0.5.0", | ||
| "version": "0.6.0", | ||
| "description": "A lightweight event emitter with separation of concerns between emitter and listener inspired by the AbortController interface.", | ||
@@ -5,0 +5,0 @@ "author": "Leonardo Raele <leonardoraele@gmail.com>", |
17619
3.25%259
4.86%