@hackdonalds/emitter
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -9,3 +9,3 @@ declare type EventHandler = (event?: any) => void; | ||
}; | ||
export default class Emitter { | ||
export default class Emitter<EventNames> { | ||
listeners: EventHandlerMap; | ||
@@ -19,3 +19,3 @@ constructor(listeners?: EventHandlerMap); | ||
*/ | ||
on(type: string, handler: EventHandler): void; | ||
on(type: string & EventNames, handler: EventHandler): void; | ||
/** | ||
@@ -27,3 +27,3 @@ * Remove an event handler for the given type. | ||
*/ | ||
off(type: string, handler: EventHandler): void; | ||
off(type: string & EventNames, handler: EventHandler): void; | ||
/** | ||
@@ -38,5 +38,5 @@ * Invoke this.listeners handlers for the given type. | ||
*/ | ||
emit(type: string, evt: any): void; | ||
emit(type: string & EventNames, evt: any): void; | ||
} | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["event", "emitter", "isomorphic", "events", "nodejs", "Javascript", "mitt", "eventemitter"], | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"main": "dist/index.js", | ||
@@ -8,0 +8,0 @@ "files": ["dist","README.md","src"], |
@@ -13,3 +13,3 @@ type EventHandler = (event?: any) => void; | ||
export default class Emitter { | ||
export default class Emitter<EventNames> { | ||
constructor(public listeners: EventHandlerMap = {}) { | ||
@@ -24,3 +24,3 @@ this.listeners = listeners | ||
*/ | ||
on(type: string, handler: EventHandler) { | ||
on(type: string & EventNames, handler: EventHandler) { | ||
this.listeners[type] = this.listeners[type] || [] | ||
@@ -36,3 +36,3 @@ this.listeners[type].push(handler); | ||
*/ | ||
off(type: string, handler: EventHandler) { | ||
off(type: string & EventNames, handler: EventHandler) { | ||
if (this.listeners[type]) { | ||
@@ -52,3 +52,3 @@ this.listeners[type].splice(this.listeners[type].indexOf(handler) >>> 0, 1); | ||
*/ | ||
emit(type: string, evt: any) { | ||
emit(type: string & EventNames, evt: any) { | ||
(this.listeners[type] || []).slice().map((handler) => { handler(evt); }); | ||
@@ -55,0 +55,0 @@ (this.listeners['*'] || []).slice().map((handler) => { handler(type, evt); }); |
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
11009