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

arbitrary-emitter

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arbitrary-emitter

Event emitter with Map/Set sugar

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

arbitrary-emitter

Event emitter with Map/Set sugar for browser and node.js apps

arbitrary-emitter allows to use arbitrary values as keys for your events

arbitrary-emitter is written in vanilla ES6, so maybe you want to transpile it before using it.

Project in active development, API may change

Create a new emitter

const emitter = arbitraryEmitter()

Emitter API

  • emitter.add
  • emitter.addOnce
  • emitter.trigger
  • Testing

add(key, method)

Add a listener for key which will trigger method function. key can be any type of value.

add returns unsubscribe method

const obj = {}
let unsubscribe = emitter.add(obj, () => doSomething())
emitter.trigger(obj) // will `doSomething`
unsubscribe()
emitter.trigger(obj) // won't do anything

addOnce(key, method)

Add a listener for key which will trigger method function just one time, then listener will be removed. key can be any type of value

const obj = {}
emitter.addOnce(obj, () => doSomethingOnce())
emitter.trigger(obj) // will `doSomething`
emitter.trigger(obj) // won't do anything

emitter.trigger(key)

Trigger methods binded to key

emitter.trigger(obj)

Testing

Node

npm test

Build Status




© 2016 Jacobo Tabernero - Released under MIT License

Keywords

FAQs

Package last updated on 14 Apr 2016

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