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

diode

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diode

A simple event emitter.

  • 6.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
251
decreased by-58.99%
Maintainers
2
Weekly downloads
 
Created
Source

NPM


Build Status Coverage Status


A dead simple event emitter. Diode only has one event.

Diode.listen(callback)
Diode.emit()

It is also small (see API). We found ourselves building something similar to it on several projects and decided it was better to keep it in one place.

Diode is both an event emitter and a decorator that can add event subscription to another object:

var MyData = Diode({
  data: [],
  add: function(record) {
    this.data.push(record)
    this.publish()
  }
})

New instances of Diode

Diode also supports the new operator:

var myDiode = new Diode()

Managing scope

By providing a second argument to listen, callbacks will be executed within a given context:

var emitter = new Diode()

emitter.listen(function() {
  assert.equal(this, 'custom context')
}, 'custom context')

emitter.emit()

API

listen(callback, &scope)

Add a callback. If a second argument is provided, the callback will be executed within that context.

Alias: subscribe.

ignore(callback)

Remove a callback.

Alias: unsubscribe.

emit(...arguments)

Trigger all subscriptions.

Alias: 'publish'


Code At Viget

Visit code.viget.com to see more projects from Viget.

FAQs

Package last updated on 10 Feb 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