EventSystem

A simple event system

Constructor

new EventSystem()

Examples
// Normal Event
const events = new EventSystem();
events.on("test", (num1, num2) => { console.log(num1, num2); });
events.emit("test", 1, 2);
events.off("test");
events.emit("test", 3, 4); // Nothing happens
// Once Event
const events = new EventSystem();
events.on("testOnce", (num1, num2) => { console.log("testOnceOn", num1, num2); });
events.once("testOnce", (num1, num2) => { console.log("testOnceOnce", num1, num2); });
events.emit("testOnce", 5, 6);

Methods

clear() → {void}

Remove all the events

Returns:
Type: 
void
Example
events.clear();

emit(event, …args) → {void}

Dispatch the event to the listeners

Parameters:
NameTypeAttributesDescription
eventstring

event name

argsany<repeatable>

all arguments to pass

Returns:
Type: 
void
Example
events.emit("eventName", 1, 2);

has(event) → {boolean}

Check if the event exists

Parameters:
NameTypeDescription
eventstring

th event name

Returns:
Type: 
boolean

off(event) → {void}

Remove the listener

Parameters:
NameTypeDescription
eventstring

event name

Returns:
Type: 
void
Example
events.off("eventName");

on(event, callback) → {void}

Start listening the event

Parameters:
NameTypeDescription
eventstring

the event name

callbackfunction

a function callback

Returns:
Type: 
void
Example
events.on("eventName", (num1, num2) => { console.log(num1, num2); });

once(event, callback) → {void}

Listening the event but just only one time

Parameters:
NameTypeDescription
eventstring

the event name

callbackfunction

a function callback

Returns:
Type: 
void
Example
events.once("eventName", (num1, num2) => { console.log("testOnceOnce", num1, num2); });