EventEmitter
A purejs provided solution to polyfill NodeJS EventEmitter.
Contructor
new EventEmitter(max);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
max | number? | ✔️ | 50 | Max 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);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
event | string | ❌ | undefined | Event name to add listener to. |
listener | CallableFunction | ❌ | undefined | Function to execute. |
Returns
void
removeListener
Removes a previously registered listener from an event.
removeListener(event, listener);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
event | string | ❌ | undefined | Event name to remove listener from. |
listener | CallableFunction | ❌ | undefined | Function that was given. |
Returns
void
removeListeners
Remove all previously registered listeners from an event.
removeListeners(event);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
event | string | ❌ | undefined | Event 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);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
event | string | ❌ | undefined | Event name to envoke listeners from. |
args | string[]? | ✔️ | undefined | Arguments to pass through CallableFunction. |
Returns
void
listeners
Returns an array of all listeners on an event.
listeners(event);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
event | string | ❌ | undefined | Event name to get listeners from. |
Returns
CallableFunction[] | undefined
listenerCount
Returns number of listeners on an event.
listenerCount(event);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
event | string | ❌ | undefined | Event name to get amount of listeners from. |
Returns
getMaxListeners
Returns the max amount of listeners before mem leak warning occurs.
getMaxListeners();
Returns
setMaxListeners
Returns the max amount of listeners before mem leak warning occurs.
setMaxListeners(amount);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
amount | number | ❌ | undefined | New amount of listeners before mem leak warning. |
Returns
void
on
Add a new listener to be synchronously called on an event.
on(event, listener);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
event | string | ❌ | undefined | Event name to add listener to. |
listener | CallableFunction | ❌ | undefined | Function to execute. |
Returns
void
once
Similar to on
however after being called once it cannot be called again.
once(event, listener);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
event | string | ❌ | undefined | Event name to add listener to. |
listener | CallableFunction | ❌ | undefined | Function to execute. |
Returns
void
off
Removes a previously registered listener from an event.
removeListener(event, listener);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
event | string | ❌ | undefined | Event name to remove listener from. |
listener | CallableFunction | ❌ | undefined | Function that was given. |
Returns
void
emit
Envokes all listeners to be synchronously called on an event.
envokeEvent(event, ...args);
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
event | string | ❌ | undefined | Event name to envoke listeners from. |
args | string[]? | ✔️ | undefined | Arguments to pass through CallableFunction. |
Returns
void