event-listener-service
Advanced tools
Comparing version 0.0.2 to 0.0.3
export interface EventListenerImplementation { | ||
addListener: (event: string, listener: Function, ...additional: any[]) => void; | ||
removeListener: (event: string, listener: Function, ...additional: any[]) => void; | ||
addListener: (eventName: string, listener: (event?: any) => void, ...additional: any[]) => void; | ||
removeListener: (eventName: string, listener: (event?: any) => void, ...additional: any[]) => void; | ||
} | ||
export interface EventListenerRegisterdListener { | ||
event: string; | ||
listener: Function; | ||
eventName: string; | ||
listener: (event?: any) => void; | ||
} | ||
@@ -16,6 +16,6 @@ export declare class EventListenerService { | ||
static setImplementation(implementation: EventListenerImplementation): void; | ||
static addListener(event: string, listener: Function, ...additional: any[]): void; | ||
static emit(event: string, emitted?: any): void; | ||
static removeListener(event: string, listener: Function, ...additional: any[]): void; | ||
static addListener(eventName: string, listener: (event?: any) => void, ...additional: any[]): void; | ||
static emit(eventName: string, emitted?: any): void; | ||
static removeListener(eventName: string, listener: (event?: any) => void, ...additional: any[]): void; | ||
} | ||
export default EventListenerService; |
22
index.js
@@ -13,3 +13,3 @@ "use strict"; | ||
var emit = this; | ||
if (emit.event === registered.event) { | ||
if (emit.eventName === registered.eventName) { | ||
emit.emitted ? registered.listener(emit.emitted) : registered.listener(); | ||
@@ -21,3 +21,3 @@ } | ||
for (var index = constants.zero; index < registered.length; ++index) { | ||
if ((wanted.event === registered[index].event) && (wanted.listener === registered[index].listener)) { | ||
if ((wanted.eventName === registered[index].eventName) && (wanted.listener === registered[index].listener)) { | ||
return index; | ||
@@ -37,3 +37,3 @@ } | ||
listener = registered[registered.length - constants.one]; | ||
previus.removeListener(listener.event, listener.listener); | ||
previus.removeListener(listener.eventName, listener.listener); | ||
registered.pop(); | ||
@@ -44,3 +44,3 @@ } | ||
}; | ||
EventListenerService.addListener = function (event, listener) { | ||
EventListenerService.addListener = function (eventName, listener) { | ||
var additional = []; | ||
@@ -51,14 +51,14 @@ for (var _i = 2; _i < arguments.length; _i++) { | ||
var implementation = EventListenerService.implementation, findIndexOf = EventListenerService.findIndexOf; | ||
var register = { event: event, listener: listener }; | ||
var register = { eventName: eventName, listener: listener }; | ||
if (findIndexOf(register) === constants.minusOne) { | ||
EventListenerService.registered.push(register); | ||
if (implementation !== null) | ||
implementation.addListener.apply(implementation, [event, listener].concat(additional)); | ||
implementation.addListener.apply(implementation, [eventName, listener].concat(additional)); | ||
} | ||
}; | ||
EventListenerService.emit = function (event, emitted) { | ||
EventListenerService.emit = function (eventName, emitted) { | ||
var registered = EventListenerService.registered, emitToLisener = EventListenerService.emitToLisener; | ||
registered.forEach(emitToLisener, { event: event, emitted: emitted }); | ||
registered.forEach(emitToLisener, { eventName: eventName, emitted: emitted }); | ||
}; | ||
EventListenerService.removeListener = function (event, listener) { | ||
EventListenerService.removeListener = function (eventName, listener) { | ||
var additional = []; | ||
@@ -69,7 +69,7 @@ for (var _i = 2; _i < arguments.length; _i++) { | ||
var implementation = EventListenerService.implementation; | ||
var index = EventListenerService.findIndexOf({ event: event, listener: listener }); | ||
var index = EventListenerService.findIndexOf({ eventName: eventName, listener: listener }); | ||
if (index !== constants.minusOne) { | ||
EventListenerService.registered.splice(index, constants.one); | ||
if (implementation !== null) | ||
implementation.removeListener.apply(implementation, [event, listener].concat(additional)); | ||
implementation.removeListener.apply(implementation, [eventName, listener].concat(additional)); | ||
} | ||
@@ -76,0 +76,0 @@ }; |
{ | ||
"name": "event-listener-service", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Simple helper class to help you stay DRY (Don't repeat yourself)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
8143