@universal-packages/event-emitter
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,6 +0,37 @@ | ||
import EE, { ConstructorOptions } from 'eventemitter2'; | ||
import { EventIn } from './EventEmitter.types'; | ||
export default class EventEmitter extends EE { | ||
import EE2, { CancelablePromise, ConstructorOptions, GeneralEventEmitter, OnOptions, OnceOptions, event, eventNS } from 'eventemitter2'; | ||
import { EventAndListener, EventIn, ListenToOptions, Listener, ListenerFn, WaitForFilter, WaitForOptions } from './EventEmitter.types'; | ||
export default class EventEmitter extends EE2 { | ||
static defaultMaxListeners: number; | ||
constructor(options?: ConstructorOptions); | ||
emit(eventName: string | symbol, event?: EventIn): boolean; | ||
emit(eventName: event | eventNS, event?: EventIn): boolean; | ||
emitAsync(eventName: event | eventNS, event?: EventIn): Promise<any[]>; | ||
addListener(eventName: event | eventNS, listener: ListenerFn): this | Listener; | ||
on(eventName: event | eventNS, listener: ListenerFn, options?: boolean | OnOptions): this | Listener; | ||
prependListener(eventName: event | eventNS, listener: ListenerFn, options?: boolean | OnOptions): this | Listener; | ||
once(eventName: event | eventNS, listener: ListenerFn, options?: true | OnOptions): this | Listener; | ||
prependOnceListener(eventName: event | eventNS, listener: ListenerFn, options?: boolean | OnOptions): this | Listener; | ||
many(eventName: event | eventNS, timesToListen: number, listener: ListenerFn, options?: boolean | OnOptions): this | Listener; | ||
prependMany(eventName: event | eventNS, timesToListen: number, listener: ListenerFn, options?: boolean | OnOptions): this | Listener; | ||
onAny(listener: EventAndListener): this; | ||
prependAny(listener: EventAndListener): this; | ||
offAny(listener: ListenerFn): this; | ||
removeListener(eventName: event | eventNS, listener: ListenerFn): this; | ||
off(eventName: event | eventNS, listener: ListenerFn): this; | ||
removeAllListeners(event?: event | eventNS): this; | ||
setMaxListeners(n: number): void; | ||
getMaxListeners(): number; | ||
eventNames(nsAsArray?: boolean): (event | eventNS)[]; | ||
listenerCount(event?: event | eventNS): number; | ||
listeners(event?: event | eventNS): ListenerFn[]; | ||
listenersAny(): ListenerFn[]; | ||
waitFor(eventName: event | eventNS, timeout?: number): CancelablePromise<any[]>; | ||
waitFor(eventName: event | eventNS, filter?: WaitForFilter): CancelablePromise<any[]>; | ||
waitFor(eventName: event | eventNS, options?: WaitForOptions): CancelablePromise<any[]>; | ||
listenTo(target: GeneralEventEmitter, events: event | eventNS, options?: ListenToOptions): this; | ||
listenTo(target: GeneralEventEmitter, events: event[], options?: ListenToOptions): this; | ||
listenTo(target: GeneralEventEmitter, events: Object, options?: ListenToOptions): this; | ||
stopListeningTo(target?: GeneralEventEmitter, event?: event | eventNS): Boolean; | ||
hasListeners(event?: String): Boolean; | ||
static once(emitter: EventEmitter, event: event | eventNS, options?: OnceOptions): CancelablePromise<any[]>; | ||
static onAny(emitter: EventEmitter, listener: EventAndListener): EventEmitter; | ||
} |
@@ -9,3 +9,3 @@ "use strict"; | ||
constructor(options) { | ||
super({ wildcard: true, ...options }); | ||
super({ wildcard: true, delimiter: ':', ignoreErrors: true, ...options }); | ||
} | ||
@@ -15,4 +15,82 @@ emit(eventName, event) { | ||
} | ||
async emitAsync(eventName, event) { | ||
return super.emitAsync(eventName, event); | ||
} | ||
addListener(eventName, listener) { | ||
return super.addListener(eventName, listener); | ||
} | ||
on(eventName, listener, options) { | ||
return super.on(eventName, listener, options); | ||
} | ||
prependListener(eventName, listener, options) { | ||
return super.prependListener(eventName, listener, options); | ||
} | ||
once(eventName, listener, options) { | ||
return super.once(eventName, listener, options); | ||
} | ||
prependOnceListener(eventName, listener, options) { | ||
return super.prependOnceListener(eventName, listener, options); | ||
} | ||
many(eventName, timesToListen, listener, options) { | ||
return super.many(eventName, timesToListen, listener, options); | ||
} | ||
prependMany(eventName, timesToListen, listener, options) { | ||
return super.prependMany(eventName, timesToListen, listener, options); | ||
} | ||
onAny(listener) { | ||
return super.onAny(listener); | ||
} | ||
prependAny(listener) { | ||
return super.prependAny(listener); | ||
} | ||
offAny(listener) { | ||
return super.offAny(listener); | ||
} | ||
removeListener(eventName, listener) { | ||
return super.removeListener(eventName, listener); | ||
} | ||
off(eventName, listener) { | ||
return super.off(eventName, listener); | ||
} | ||
removeAllListeners(event) { | ||
return super.removeAllListeners(event); | ||
} | ||
setMaxListeners(n) { | ||
return super.setMaxListeners(n); | ||
} | ||
getMaxListeners() { | ||
return super.getMaxListeners(); | ||
} | ||
eventNames(nsAsArray) { | ||
return super.eventNames(nsAsArray); | ||
} | ||
listenerCount(event) { | ||
return super.listenerCount(event); | ||
} | ||
listeners(event) { | ||
return super.listeners(event); | ||
} | ||
listenersAny() { | ||
return super.listenersAny(); | ||
} | ||
waitFor(eventName, right) { | ||
return super.waitFor(eventName, right); | ||
} | ||
listenTo(target, events, options) { | ||
return super.listenTo(target, events, options); | ||
} | ||
stopListeningTo(target, event) { | ||
return super.stopListeningTo(target, event); | ||
} | ||
hasListeners(event) { | ||
return super.hasListeners(event); | ||
} | ||
static once(emitter, event, options) { | ||
return this.once(emitter, event, options); | ||
} | ||
static onAny(emitter, listener) { | ||
return this.onAny(emitter, listener); | ||
} | ||
} | ||
exports.default = EventEmitter; | ||
//# sourceMappingURL=EventEmitter.js.map |
import { Measurement } from '@universal-packages/time-measurer'; | ||
import { event, eventNS } from 'eventemitter2'; | ||
import EventEmitter from './EventEmitter'; | ||
export interface EventIn { | ||
@@ -11,1 +13,40 @@ error?: Error; | ||
} | ||
export interface ListenerFn { | ||
(event?: EventOut): void; | ||
} | ||
export interface EventAndListener { | ||
(eventName: string | string[], event?: EventIn): void; | ||
} | ||
export interface WaitForFilter { | ||
(event?: EventOut): boolean; | ||
} | ||
export interface WaitForOptions { | ||
timeout: number; | ||
filter: WaitForFilter; | ||
handleError: boolean; | ||
Promise: Function; | ||
overload: boolean; | ||
} | ||
export interface ListenToOptions { | ||
on?: { | ||
(event: event | eventNS, handler: ListenerFn): void; | ||
}; | ||
off?: { | ||
(event: event | eventNS, handler: ListenerFn): void; | ||
}; | ||
reducers: Function | Object; | ||
} | ||
export interface GeneralEventEmitter { | ||
addEventListener(event: event, handler: ListenerFn): this; | ||
removeEventListener(event: event, handler: ListenerFn): this; | ||
addListener?(event: event, handler: ListenerFn): this; | ||
removeListener?(event: event, handler: ListenerFn): this; | ||
on?(event: event, handler: ListenerFn): this; | ||
off?(event: event, handler: ListenerFn): this; | ||
} | ||
export interface Listener { | ||
emitter: EventEmitter; | ||
event: event | eventNS; | ||
listener: ListenerFn; | ||
off(): this; | ||
} |
export { default as EventEmitter } from './EventEmitter'; | ||
export * from './EventEmitter.types'; | ||
export * from 'eventemitter2'; |
@@ -24,3 +24,2 @@ "use strict"; | ||
__exportStar(require("./EventEmitter.types"), exports); | ||
__exportStar(require("eventemitter2"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@universal-packages/event-emitter", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Event emitter 2 with universal convention", | ||
@@ -5,0 +5,0 @@ "author": "David De Anda <david@universal-packages.com> (https://github.com/universal-packages)", |
@@ -17,3 +17,3 @@ # Buffer Dispatcher | ||
It behaves exactly as [EventEmitter2](https://github.com/EventEmitter2/EventEmitter2) but with wildcards enabled by default and emit to only emit on object following events convention for universal-packages. | ||
It behaves exactly as [EventEmitter2](https://github.com/EventEmitter2/EventEmitter2) but with wildcards enabled by default and following events convention for universal-packages. | ||
@@ -20,0 +20,0 @@ ```js |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
16703
208