Skip to content

Commit

Permalink
Update: Allow more arguments in listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoborus committed Jun 30, 2019
1 parent bd00455 commit 739ee67
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions arbitrary-emitter.js
Expand Up @@ -11,17 +11,17 @@ module.exports = () => {
events.delete(e.key)
actions.delete(e.key)
} else if (size === 1) {
actions.set(e.key, (a, b, c) => {
actions.set(e.key, function () {
const fn = listeners[0]
if (fn) fn(a, b, c)
if (fn) fn(...arguments)
})
} else {
actions.set(e.key, (a, b, c) => {
actions.set(e.key, function () {
e.running.push(listeners)
let size = listeners.length
while (size > 0) {
const fn = listeners[--size]
if (fn) fn(a, b, c)
let s = size
while (s > 0) {
const fn = listeners[--s]
if (fn) fn(...arguments)
}
e.running.pop()
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "arbitrary-emitter",
"version": "1.0.0",
"description": "High performance event emitter for modern browsers in ~450 bytes",
"version": "1.1.0",
"description": "High performance event emitter in ~450 bytes",
"main": "arbitrary-emitter.js",
"scripts": {
"linter": "standard arbitrary-emitter.js tests/tests.js",
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.js
Expand Up @@ -126,11 +126,11 @@ test('remove listener in a event with muliple listeners', t => {
const emitter = ae()
const out = []
const f1 = () => out.push(1)
const f3 = () => out.push(3)
const f2 = () => {
out.push(2)
emitter.off('test', f3)
}
const f3 = () => out.push(3)
emitter.on('test', f1)
emitter.on('test', f2)
emitter.on('test', f3)
Expand Down

0 comments on commit 739ee67

Please sign in to comment.