Permalink
Browse files

Update: fastest conditionals

  • Loading branch information...
jacoborus committed Sep 12, 2016
1 parent 7d0ae82 commit b9f72b19b217347dd7a57fd28b51fda49fc5952f
Showing with 17 additions and 22 deletions.
  1. +16 −21 arbitrary-emitter.js
  2. +1 −1 package.json
View
@@ -11,17 +11,17 @@ module.exports = () => {
events.delete(e.key)
actions.delete(e.key)
} else if (size === 1) {
actions.set(e.key, (a, b) => {
let fn = listeners[0]
if (fn) fn(a, b)
actions.set(e.key, (a, b, c) => {
const fn = listeners[0]
if (fn) fn(a, b, c)
})
} else {
actions.set(e.key, (a, b) => {
actions.set(e.key, (a, b, c) => {
e.running.push(listeners)
let size = listeners.length
while (size > 0) {
const fn = listeners[--size]
if (fn) fn(a, b)
if (fn) fn(a, b, c)
}
e.running.pop()
})
@@ -34,9 +34,7 @@ module.exports = () => {
function trash (list, lis) {
let index = list.indexOf(lis)
if (index > -1) {
delete list[index]
}
if (index > -1) delete list[index]
}
const e = {
@@ -64,38 +62,35 @@ module.exports = () => {
return {
on (key, lis) {
const e = events.get(key) || newListener(key)
e.add(lis)
(events.get(key) || newListener(key)).add(lis)
},
once (key, lis) {
const e = events.get(key) || newListener(key)
e.add(fn)
function fn () {
e.add(function fn () {
lis(arguments)
e.rm(fn)
}
})
},
emit (key, a, b) {
emit (key, a, b, c) {
const action = actions.get(key)
if (action) action(a, b)
if (action) action(a, b, c)
},
off (key, lis) {
if (!(1 in arguments)) {
if (1 in arguments) {
events.get(key).rm(lis)
} else if (events.has(key)) {
events.delete(key)
actions.delete(key)
} else if (events.has(key)) {
events.get(key).rm(lis)
}
},
listeners (key) {
const e = events.get(key)
if (!e) return []
else return e.listeners.slice(0).reverse()
if (e) return e.listeners.slice(0).reverse()
else return []
}
}
}
View
@@ -1,6 +1,6 @@
{
"name": "arbitrary-emitter",
"version": "0.11.1",
"version": "1.0.0",
"description": "High performance event emitter for modern browsers in ~450 bytes",
"main": "arbitrary-emitter.js",
"scripts": {

0 comments on commit b9f72b1

Please sign in to comment.