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

Hi-Perf event emitter with Map/Set sugar

  • 0.7.4
  • Source
  • npm
  • Socket score

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

arbitrary-emitter

High performance event emitter with Map/Set sugar for node.js and browsers (<500 bytes when gzipped)

Build Status npm version

arbitrary-emitter stores listeners and actions in ES6 Map and Sets, this allows to use arbitrary values as keys for your listeners

arbitrary-emitter is written in vanilla ES6, so you will have to transpile it before using it in old browsers or node.js < v5.9

Create a new emitter

const emitter = arbitraryEmitter()

Emitter API

on(key, action)

Add a listener with key which will trigger action function. key can be any type of value.

on returns unsubscribe method

const obj = {}
let removeAction = emitter.on(obj, () => doSomething())
emitter.emit(obj) // will `doSomething`
removeAction()
emitter.emit(obj) // won't do anything

once(key, action)

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

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

emit(key[, ...args])

emit methods binded to key, and pass the rest of the arguments to it

emitter.on('test', (a, b) => console.log(a + b))
emitter.emit('test', 1, 2) // => 3

off(key[, action])

Remove action from listener key. If no action is specified will remove all listeners binded to key

emitter.off(key, action) // will remove action from listener `key`
emitter.off(key) // will remove the listener `key` and all actions binded to it

Testing

Node

npm test

Browser

Build browser tests (npm run build-tests) and open test/test.html

Building

  • Build UMD file: npm run build-umd
  • Build browser tests: npm run build-tests
  • Run both builds: npm run build




© 2016 Jacobo Tabernero - Released under MIT License

Keywords

FAQs

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