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

elistener

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elistener

listenTo/stopListening to an EventEmitter for easy cleanup

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-25%
Maintainers
3
Weekly downloads
 
Created
Source

elistener

Usage

var EventEmitter = require('events').EventEmitter
var elistener = require('elistener')

var cat = new EventEmitter()

function Owner () {}
elistener.install(Owner.prototype) // or just elistener(Owner.prototype)

var owner = new Owner()
owner.listenTo(cat, 'meow', feed)
cat.emit('meow')
cat.emit('meow')
cat.emit('meow')
cat.emit('meow')
cat.emit('meow')
cat.emit('meow')

// should print:
// fed cat
// petted cat
// sold cat

function feed () {
  console.log('fed cat')
  owner.stopListening(cat, 'meow', feed) // remove handler
  owner.listenTo(cat, 'meow', pet)
}

function pet () {
  console.log('petted cat')
  owner.stopListening(cat, 'meow') // remove all handlers for event
  owner.listenTo(cat, 'meow', sell)
}

function sell () {
  console.log('sold cat')
  owner.stopListening(cat) // remove all handlers
}

Methods

listenTo(emitter, event, handler)

listenOnce(emitter, event, handler)

stopListening([emitter, event, handler])

Keywords

FAQs

Package last updated on 04 Jul 2017

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