arbitrary-emitter
Advanced tools
Comparing version 0.10.2 to 0.11.0
@@ -92,3 +92,10 @@ 'use strict' | ||
} | ||
}, | ||
listeners (key) { | ||
const e = events.get(key) | ||
if (!e) return [] | ||
else return e.listeners.slice(0).reverse() | ||
} | ||
} | ||
@@ -95,0 +102,0 @@ } |
{ | ||
"name": "arbitrary-emitter", | ||
"version": "0.10.2", | ||
"version": "0.11.0", | ||
"description": "Event emitter with ES6 Map sugar for modern browsers and node.js", | ||
@@ -5,0 +5,0 @@ "main": "arbitrary-emitter.js", |
@@ -89,2 +89,18 @@ arbitrary-emitter | ||
<a name="emitter-listeners-api"></a> | ||
### listeners(eventKey) | ||
Returns a copy of the array of listeners for the event tagged `eventKey` | ||
```js | ||
const key = {} | ||
const f1 = () => console.log('f1') | ||
const f2 = () => console.log('f2') | ||
emitter.on(key, f1) | ||
emitter.on(key, f2) | ||
emitter.listeners(key)[0] === f1 // true | ||
emitter.listeners(key)[1] === f2 // true | ||
``` | ||
<a name="testing"></a> | ||
@@ -91,0 +107,0 @@ ## Testing |
@@ -146,1 +146,25 @@ 'use strict' | ||
}) | ||
test('get listeners', t => { | ||
const emitter = ae() | ||
const key = {} | ||
const key2 = {} | ||
let c1 = 0 | ||
let c2 = 0 | ||
const f1 = () => ++c1 | ||
const f2 = () => ++c2 | ||
emitter.on(key, f1) | ||
emitter.on(key, f2) | ||
emitter.on(key2, f2) | ||
emitter.emit(key) | ||
t.is(c1, 1) | ||
t.is(c2, 1) | ||
const list = emitter.listeners(key) | ||
t.is(list[0], f1) | ||
t.is(list[1], f2) | ||
const list2 = emitter.listeners(key2) | ||
t.is(list2[0], f2) | ||
const other = emitter.listeners({}) | ||
t.is(other.length, 0) | ||
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
12548
244
133