arbitrary-emitter
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -39,7 +39,11 @@ 'use strict' | ||
const link = links.get(key) | ||
if (!key) return | ||
if (!link) return | ||
link.forEach(fn => fn()) | ||
} | ||
return { add, addOnce, trigger } | ||
function remove (key) { | ||
links.delete(key) | ||
} | ||
return { add, addOnce, trigger, remove } | ||
} |
{ | ||
"name": "arbitrary-emitter", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Event emitter with Map/Set sugar", | ||
@@ -5,0 +5,0 @@ "main": "arbitrary-emitter.js", |
@@ -23,2 +23,3 @@ arbitrary-emitter | ||
- [emitter.trigger](#emitter-trigger-api) | ||
- [emitter.remove](#emitter-remove-api) | ||
- [Testing](#testing) | ||
@@ -72,2 +73,13 @@ | ||
<a name="emitter-remove-api"></a> | ||
## emitter.remove(key) | ||
Remove all listeners binded to `key` | ||
```js | ||
emitter.remove(obj) | ||
``` | ||
<a name="testing"></a> | ||
@@ -74,0 +86,0 @@ ## Testing |
14
test.js
@@ -32,1 +32,15 @@ 'use strict' | ||
}) | ||
test('remove', t => { | ||
const emitter = ae() | ||
const obj = {} | ||
let control = 0 | ||
emitter.add(obj, () => ++control) | ||
emitter.add(obj, () => ++control) | ||
emitter.trigger(obj) | ||
t.is(control, 2, 'control') | ||
emitter.remove(obj) | ||
emitter.trigger(obj) | ||
t.is(control, 2, 'remove link from subscriptions') | ||
t.end() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5680
82
100