2.0.1 • Published 4 years ago

alpeventemitter v2.0.1

Weekly downloads
31
License
MIT
Repository
github
Last release
4 years ago

AlpEventEmitter

A simple and lightweight implementation of event emitter with limited functionality.

npm i alpeventemitter
const EventEmitter = require('alpeventemitter');

class Hello extends EventEmitter{
	constructor(){
		super();
		setInterval(this.emitSomething.bind(this), 500);
	}
	emitSomething(){
		this.emit("says", "Hello!");
		this.emit("emits", "Something");
	}
}
let emitter = new Hello();
emitter.on("emits", (message,event) => {console.log(message);});
let callback = function(message){
	console.log("Nobody stops me:", message);
}
let funcToRemove = emitter.on(callback);

// When says event emitted callback will be removed from all events.
emitter.once(["says","emits"], message => {console.log("Once: "+message)})

// Those are also same since there is only those two events.
emitter.once(["emits","says"], message => {console.log("Once the third: "+message)})
emitter.once(message => {console.log("Once the second: "+message)})


setTimeout( () => {
    funcToRemove();
},1300);
2.0.1

4 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago