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 - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

27

arbitrary-emitter.js

@@ -40,7 +40,24 @@ 'use strict'

if (!link) return
if (arguments.length > 1) {
let args = arguments.slice(1)
link.forEach(fn => apply.call(fn, args))
} else {
link.forEach(fn => fn())
const l = arguments.length
switch (l) {
case 1: {
link.forEach(fn => fn())
break
}
case 2: {
link.forEach(fn => fn(arguments[1]))
break
}
case 3: {
link.forEach(fn => fn(arguments[1], arguments[2]))
break
}
default: {
let l = arguments.length
let args = new Array(l - 1)
for (let i = 1; i < l; ++i) {
args[i - 1] = arguments[i]
}
link.forEach(fn => apply.call(fn, fn, args))
}
}

@@ -47,0 +64,0 @@ },

2

package.json
{
"name": "arbitrary-emitter",
"version": "0.7.0",
"version": "0.7.1",
"description": "Event emitter with Map/Set sugar",

@@ -5,0 +5,0 @@ "main": "arbitrary-emitter.js",

arbitrary-emitter
=================
High performance event emitter with Map/Set sugar for browser and node.js apps
Event emitter with Map/Set sugar for node.js and browsers (<400 bytes when gzipped)
[![Build Status](https://travis-ci.org/jacoborus/arbitrary-emitter.svg?branch=master)](https://travis-ci.org/jacoborus/arbitrary-emitter)
[![Build Status](https://travis-ci.org/jacoborus/arbitrary-emitter.svg?branch=master)](https://travis-ci.org/jacoborus/arbitrary-emitter) [![npm version](https://badge.fury.io/js/arbitrary-emitter.svg)](https://www.npmjs.com/package/arbitrary-emitter)
**arbitrary-emitter** stores listeners in a ES6 Map and the actions in ES6 Sets, this improves performance when emitting multiple actions and also allows to use arbitrary values as keys for your listeners
**arbitrary-emitter** stores listeners and actions in ES6 Map and Sets, this allows to use arbitrary values as keys for your listeners

@@ -21,6 +21,6 @@ **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

- [emitter.on](#emitter-on-api)
- [emitter.once](#emitter-once-api)
- [emitter.emit](#emitter-emit-api)
- [emitter.off](#emitter-off-api)
- [on](#emitter-on-api)
- [once](#emitter-once-api)
- [emit](#emitter-emit-api)
- [off](#emitter-off-api)

@@ -38,5 +38,5 @@

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

@@ -43,0 +43,0 @@ ```

@@ -67,3 +67,3 @@ 'use strict'

test('emit with arguments', t => {
test('emit actions in order', t => {
const emitter = ae()

@@ -88,1 +88,23 @@ const obj = {}

})
test('emit with arguments', t => {
const emitter = ae()
const obj = {}
let control = {
a: 0,
b: 0,
c: 0
}
emitter.on(obj, (a, b, c) => {
control.a = a
control.b = b
control.c = c
})
emitter.emit(obj, 1, 2, 3)
t.is(control.a, 1)
t.is(control.b, 2)
t.is(control.c, 3)
t.end()
})
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