event-class-es6
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

event-class-es6 Build Status

event-class-es6 is an ES6 module providing event communication to ES6 classes.

Installation

npm install --save event-class-es6

Example

import EventClass from "event-class-es6"
 
class EventTest extends EventClass {}
 
const event = new EventTest();
 
const cb = event.on("event-on", () => {
    console.log("I've been called");
});
 
event.once("event-once", () => {
    console.log("I will be called once");
});
event.emit("event-on");
"I've been called"
event.emit("event-on");
"I've been called"
event.off("event-on", cb);
event.emit("event-name");
event.emit("event-once");
"I will be called once"
event.emit("event-once");
 

API

.on(event, listener)


This will register the given listener to the given event, multiple listeners can be added to the same event.

.once(event, listener)


Same as .on but will only calls the listener once for the given event.

.off(event, [listener=undefined])


Removes the given listener from listening to the given event. If listener is undefined, all listeners for the given event will be removed.

.emit(event, [...arguments])


This will call every listeners registered for this given event with the given arguments.

Package Sidebar

Install

npm i event-class-es6

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

62.3 kB

Total Files

14

Last publish

Collaborators

  • jonathanpicques