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.5.0 to 0.6.0

9

arbitrary-emitter.js

@@ -51,6 +51,11 @@ 'use strict'

off (key) {
links.delete(key)
off (key, action) {
if (1 in arguments) {
let link = links.get(key)
if (link) link.delete(action)
} else {
links.delete(key)
}
}
}
}
{
"name": "arbitrary-emitter",
"version": "0.5.0",
"version": "0.6.0",
"description": "Event emitter with Map/Set sugar",

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

@@ -47,3 +47,3 @@ arbitrary-emitter

<a name="emitter-addonce-api"></a>
### addOnce(key, method)
### once(key, method)

@@ -55,3 +55,3 @@ Add a listener for `key` which will trigger `method` function just one time, then listener will be removed.

const obj = {}
emitter.addOnce(obj, () => doSomethingOnce())
emitter.once(obj, () => doSomethingOnce())
emitter.emit(obj) // will `doSomething`

@@ -76,8 +76,9 @@ emitter.emit(obj) // won't do anything

<a name="emitter-off-api"></a>
## emitter.off(key)
## emitter.off(key[, action])
Remove all listeners binded to `key`
Remove `action` from listener `key`. If no action is specified will remove all listeners binded to `key`
```js
emitter.off(obj)
emitter.off(key, action) // will remove action from listener `key`
emitter.off(key) // will remove the listener `key` and all actions binded to it
```

@@ -84,0 +85,0 @@

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

test('off', t => {
test('off listener', t => {
const emitter = ae()

@@ -48,2 +48,22 @@ const obj = {}

test('off action', t => {
const emitter = ae()
const obj = {}
let control = {
a: 0,
b: 0
}
const fn = () => ++control.b
emitter.on(obj, () => ++control.a)
emitter.on(obj, fn)
emitter.emit(obj)
t.is(control.a, 1, 'control a')
t.is(control.b, 1, 'control b')
emitter.off(obj, fn)
emitter.emit(obj)
t.is(control.a, 2, 'control a')
t.is(control.b, 1, 'control b')
t.end()
})
test('emit with arguments', t => {

@@ -50,0 +70,0 @@ const emitter = ae()

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