1.6.3 • Published 6 years ago

event-emitter-lite v1.6.3

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

event-emitter-lite

npm install event-emitter-lite

use

import to use

let eventemitter = require("event-emitter-lite");

API

let onTest = new eventemitter.EventEmitter();
subscribe
onTest.subscribe(msg => console.log(msg));
once
onTest.once(msg => console.log(`One more time: ${msg}`));
cancel the next call
let egoistSubscribe = onTest.subscribe(msg =>{
    console.log(`the Dalek sad: ${msg}`);
    onTest.cancel();
});

onTest.subscribe(msg => console.log(`Im not a Dalek: ${msg}`));
emit
onTest.emit('go go go!!!');
unsubscribe
onTest.unsubscribe(egoistSubscribe);
cancel a event
onTest.cancel();
cancel a subscribe
egoistSubscribe.cancel();
emit again and again ....
onTest.emit('go go go!!!');
getting emitted value
onTest.emit('last chance...');
console.log(`Would it recieve the last msg? ${onTest.emittedValue}`); 
//yes :)
working with errors

with javascript

let onTest = new eventemitter.EventEmitter();
onTest.subscribe(
	msg => console.log(msg)
	, err => console.log(err)
);

onTest.error('It´s is a multiverse erro!');

with typescript

let onTest = new EventEmitter<string,string>();
onTest.subscribe(
	msg => console.log(msg)
	, err => console.log(err)
);

onTest.error('It´s is a multiverse erro!');

emiting a value (can do a promise) after a emit

onTest.subscribe(msg => 'finished!');

let afterEmit = onTest
	.emit('its ok');
	// ['finished!']

with promise

onTest.subscribe(msg => {
	//...do any thing with 'msg';
	return new Promise(sucess => {
		setTimeout(() => sucess('finished!'),2000);
	});
});

Promise.all(
	onTest
		.emit('its ok')
)	
.then(() => console.log('finish!!!'));
1.6.3

6 years ago

1.6.2

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago