Constructor
new EventSystem()
- Source
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
- Source
Returns:
- Type:
- void
Example
events.clear();
emit(event, …args) → {void}
Dispatch the event to the listeners
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
event | string | event name | |
args | any | <repeatable> | all arguments to pass |
- Source
Returns:
- Type:
- void
Example
events.emit("eventName", 1, 2);
has(event) → {boolean}
Check if the event exists
Parameters:
Name | Type | Description |
---|---|---|
event | string | th event name |
- Source
Returns:
- Type:
- boolean
off(event) → {void}
Remove the listener
Parameters:
Name | Type | Description |
---|---|---|
event | string | event name |
- Source
Returns:
- Type:
- void
Example
events.off("eventName");
on(event, callback) → {void}
Start listening the event
Parameters:
Name | Type | Description |
---|---|---|
event | string | the event name |
callback | function | a function callback |
- Source
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:
Name | Type | Description |
---|---|---|
event | string | the event name |
callback | function | a function callback |
- Source
Returns:
- Type:
- void
Example
events.once("eventName", (num1, num2) => { console.log("testOnceOnce", num1, num2); });