@fablevision/utils
Advanced tools
Comparing version 1.0.1 to 1.1.0
import { Disposable, IDisposable } from './Disposable'; | ||
/** | ||
* A strongly typed event emitter using the IDisposable pattern for cleanup. | ||
* A strongly typed event emitter for events with a single (or no) argument using the IDisposable pattern for cleanup. | ||
* Handles a single event, create one for each event you need to emit. | ||
@@ -42,1 +42,81 @@ */ | ||
} | ||
/** | ||
* A strongly typed event emitter for events with two arguments using the IDisposable pattern for cleanup. | ||
* Handles a single event, create one for each event you need to emit. | ||
*/ | ||
export declare class DoubleEvent<T1, T2> { | ||
private listeners; | ||
constructor(); | ||
/** | ||
* Emits this event with the given value. | ||
* @param value The event data to be sent to listeners. | ||
*/ | ||
emit(val1: T1, val2: T2): void; | ||
/** | ||
* Adds a listener. | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
add(listener: (val1: T1, val2: T2) => void): Disposable; | ||
/** | ||
* An alias for add(). | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
on(listener: (val1: T1, val2: T2) => void): Disposable; | ||
/** | ||
* Adds a listener that will be removed after one event is emitted. | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
once(listener: (val1: T1, val2: T2) => void): Disposable; | ||
/** | ||
* Cleans up the event emitter, removing all listeners. | ||
* This does not fully destroy the emitter, so it can be reused later. | ||
*/ | ||
dispose(): void; | ||
/** | ||
* An alias for dispose(). | ||
*/ | ||
destroy(): void; | ||
} | ||
/** | ||
* A strongly typed event emitter for events with three or more arguments using the IDisposable pattern for cleanup. | ||
* Handles a single event, create one for each event you need to emit. | ||
*/ | ||
export declare class MultiEvent<TArgs extends any[]> { | ||
private listeners; | ||
constructor(); | ||
/** | ||
* Emits this event with the given value. | ||
* @param value The event data to be sent to listeners. | ||
*/ | ||
emit(...value: TArgs): void; | ||
/** | ||
* Adds a listener. | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
add(listener: (...value: TArgs) => void): Disposable; | ||
/** | ||
* An alias for add(). | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
on(listener: (...value: TArgs) => void): Disposable; | ||
/** | ||
* Adds a listener that will be removed after one event is emitted. | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
once(listener: (...value: TArgs) => void): Disposable; | ||
/** | ||
* Cleans up the event emitter, removing all listeners. | ||
* This does not fully destroy the emitter, so it can be reused later. | ||
*/ | ||
dispose(): void; | ||
/** | ||
* An alias for dispose(). | ||
*/ | ||
destroy(): void; | ||
} |
import { Disposable } from './Disposable'; | ||
/** | ||
* A strongly typed event emitter using the IDisposable pattern for cleanup. | ||
* A strongly typed event emitter for events with a single (or no) argument using the IDisposable pattern for cleanup. | ||
* Handles a single event, create one for each event you need to emit. | ||
@@ -65,1 +65,127 @@ */ | ||
} | ||
/** | ||
* A strongly typed event emitter for events with two arguments using the IDisposable pattern for cleanup. | ||
* Handles a single event, create one for each event you need to emit. | ||
*/ | ||
export class DoubleEvent { | ||
constructor() { | ||
this.listeners = new Set(); | ||
} | ||
/** | ||
* Emits this event with the given value. | ||
* @param value The event data to be sent to listeners. | ||
*/ | ||
emit(val1, val2) { | ||
for (const listener of this.listeners) { | ||
listener(val1, val2); | ||
} | ||
} | ||
/** | ||
* Adds a listener. | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
add(listener) { | ||
this.listeners.add(listener); | ||
return new Disposable(() => { var _a; return (_a = this.listeners) === null || _a === void 0 ? void 0 : _a.delete(listener); }); | ||
} | ||
/** | ||
* An alias for add(). | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
on(listener) { | ||
return this.add(listener); | ||
} | ||
/** | ||
* Adds a listener that will be removed after one event is emitted. | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
once(listener) { | ||
// eslint-disable-next-line prefer-const | ||
let cleanup; | ||
const wrapper = (val1, val2) => { | ||
cleanup.dispose(); | ||
listener(val1, val2); | ||
}; | ||
cleanup = this.add(wrapper); | ||
return cleanup; | ||
} | ||
/** | ||
* Cleans up the event emitter, removing all listeners. | ||
* This does not fully destroy the emitter, so it can be reused later. | ||
*/ | ||
dispose() { | ||
this.listeners.clear(); | ||
} | ||
/** | ||
* An alias for dispose(). | ||
*/ | ||
destroy() { | ||
this.dispose(); | ||
} | ||
} | ||
/** | ||
* A strongly typed event emitter for events with three or more arguments using the IDisposable pattern for cleanup. | ||
* Handles a single event, create one for each event you need to emit. | ||
*/ | ||
export class MultiEvent { | ||
constructor() { | ||
this.listeners = new Set(); | ||
} | ||
/** | ||
* Emits this event with the given value. | ||
* @param value The event data to be sent to listeners. | ||
*/ | ||
emit(...value) { | ||
for (const listener of this.listeners) { | ||
listener(...value); | ||
} | ||
} | ||
/** | ||
* Adds a listener. | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
add(listener) { | ||
this.listeners.add(listener); | ||
return new Disposable(() => { var _a; return (_a = this.listeners) === null || _a === void 0 ? void 0 : _a.delete(listener); }); | ||
} | ||
/** | ||
* An alias for add(). | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
on(listener) { | ||
return this.add(listener); | ||
} | ||
/** | ||
* Adds a listener that will be removed after one event is emitted. | ||
* @param listener Function to call when events are emitted. | ||
* @returns A disposable token to remove that listener. | ||
*/ | ||
once(listener) { | ||
// eslint-disable-next-line prefer-const | ||
let cleanup; | ||
const wrapper = (...value) => { | ||
cleanup.dispose(); | ||
listener(...value); | ||
}; | ||
cleanup = this.add(wrapper); | ||
return cleanup; | ||
} | ||
/** | ||
* Cleans up the event emitter, removing all listeners. | ||
* This does not fully destroy the emitter, so it can be reused later. | ||
*/ | ||
dispose() { | ||
this.listeners.clear(); | ||
} | ||
/** | ||
* An alias for dispose(). | ||
*/ | ||
destroy() { | ||
this.dispose(); | ||
} | ||
} |
{ | ||
"name": "@fablevision/utils", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -12,3 +12,5 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc" | ||
"build": "tsc", | ||
"prepublish": "npm run build", | ||
"postpublish": "git push && git push --tags" | ||
}, | ||
@@ -15,0 +17,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18610
576