Skip to main content

EventEmitter

A purejs provided solution to polyfill NodeJS EventEmitter.

Contructor

new EventEmitter(max);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
maxnumber?✔️50Max number of allowed listeners before a mem leak warning is emitted.

Methods

addListener

Add a new listener to be synchronously called on an event.

addListener(event, listener);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstringundefinedEvent name to add listener to.
listenerCallableFunctionundefinedFunction to execute.

Returns

void


removeListener

Removes a previously registered listener from an event.

removeListener(event, listener);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstringundefinedEvent name to remove listener from.
listenerCallableFunctionundefinedFunction that was given.

Returns

void


removeListeners

Remove all previously registered listeners from an event.

removeListeners(event);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstringundefinedEvent name to remove listeners from.

Returns

void


removeAllListeners

Removes all previously registered listeners from all event.

removeAllListeners();

Returns

void


envokeEvent

Envokes all listeners to be synchronously called on an event.

envokeEvent(event, ...args);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstringundefinedEvent name to envoke listeners from.
argsstring[]?✔️undefinedArguments to pass through CallableFunction.

Returns

void


listeners

Returns an array of all listeners on an event.

listeners(event);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstringundefinedEvent name to get listeners from.

Returns

CallableFunction[] | undefined


listenerCount

Returns number of listeners on an event.

listenerCount(event);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstringundefinedEvent name to get amount of listeners from.

Returns

number


getMaxListeners

Returns the max amount of listeners before mem leak warning occurs.

getMaxListeners();

Returns

number


setMaxListeners

Returns the max amount of listeners before mem leak warning occurs.

setMaxListeners(amount);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
amountnumberundefinedNew amount of listeners before mem leak warning.

Returns

void


on

Add a new listener to be synchronously called on an event.

on(event, listener);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstringundefinedEvent name to add listener to.
listenerCallableFunctionundefinedFunction to execute.

Returns

void


once

Similar to on however after being called once it cannot be called again.

once(event, listener);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstringundefinedEvent name to add listener to.
listenerCallableFunctionundefinedFunction to execute.

Returns

void


off

Removes a previously registered listener from an event.

removeListener(event, listener);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstringundefinedEvent name to remove listener from.
listenerCallableFunctionundefinedFunction that was given.

Returns

void


emit

Envokes all listeners to be synchronously called on an event.

envokeEvent(event, ...args);
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstringundefinedEvent name to envoke listeners from.
argsstring[]?✔️undefinedArguments to pass through CallableFunction.

Returns

void