New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

event-emitter-lite

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-emitter-lite

simple event emitter to use with typescript and pure javascript no depences

  • 1.6.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-22.22%
Maintainers
2
Weekly downloads
 
Created
Source

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!!!'));

Keywords

FAQs

Package last updated on 08 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc