Skip to content
Permalink
Browse files

Update: Allow more arguments in listeners

  • Loading branch information...
jacoborus committed Jun 30, 2019
1 parent bd00455 commit 739ee674fea321366b8561029a9fc84ea5505e1c
Showing with 10 additions and 10 deletions.
  1. +7 −7 arbitrary-emitter.js
  2. +2 −2 package.json
  3. +1 −1 tests/tests.js
@@ -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()
})
@@ -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",
@@ -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)

0 comments on commit 739ee67

Please sign in to comment.
You can’t perform that action at this time.