js-simple-events
Yet another simple event management system
npm i -S js-simple-events
About
This is just a simple class that helps to manage events in a simple way without dependencies. It also supports TypeScript!
And it's really light - <1kb in size!
Methods
Method | Params | Description |
---|---|---|
emit |
event, payload |
Emit the event with the given payload. |
fire |
event, payload |
Alias for emit |
on |
event, callback |
Listen for the event with the given callback. |
listen |
event, callback |
Alias for on |
once |
event, callback |
Listen for the event once, after handling - remove the listener. |
off |
event, callback |
Remove event listener(s) for the event. |
remove |
event, callback |
Alias for off |
Examples
// Import and initialize const eventManager = ; // Define handlersconst eventHandler = console; eventManager;eventManager; // Emit eventseventManager;// -> Yay, events work! Hello!// -> This will be called just once! eventManager;// -> Yay, events work! Hello!// (The 'once' handler isn't fired)