Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

emitter20

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emitter20

An event emitter in 20 lines of code.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
216
increased by26.32%
Maintainers
1
Weekly downloads
 
Created
Source

emitter20

npm version Build Status

An event emitter that used to be 20 lines of code but is still quite small. No dependencies.

Install

$ npm install --save emitter20

Methods

  • on: (eventName: string, callback: Function) => void - Subscribe a callback to the given event type.
  • off: (eventName: string, callback: Function) => void - Remove a callback from the given event type.
  • trigger: (eventName: string, callback: Function) => void - Trigger an event, invoking all subscribers.
  • clear: (eventName?: string) => void - Remove all subscribers from the given event type, or all subscribers if no event type is specified.

Usage

var Emitter = require('emitter20')

var emitter = new Emitter()

emitter.on('karate-chop', function() {
  console.log('Haiaaaaaa!')
})

emitter.trigger('karate-chop') // Haiaaaaa!'

Pass arbitrary data to the event handler:

var emitter = new Emitter()

emitter.on('welcome', function(name) {
  console.log(`Welcome {name}!`)
})

emitter.trigger('welcome', 'bob') // Welcome bob!

Can be used as a mixin:

var assign = require('lodash.assign')

var obj = { a: 1, b: 2 }
assign(obj, new Emitter())

obj.on('karate-chop', function() {
  console.log('Haiaaaaaa!')
})

obj.trigger('karate-chop') // Haiaaaaa!'

License

ISC © Raine Revere

Keywords

FAQs

Package last updated on 02 Apr 2020

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