Comments (2)
The example above has an error. If I at first add a new listener, and at second remove the old one.
module.exports = {
event: () => {
let ev = (data) => {
ev[1] ++;
try {
for (ev[3] = 0; i < ev[0].length; ev[3]++)
ev[0][ev[3]](data)
}
finally {
ev[1]--;
if (!ev[1] && ev[2].length) {
ev[0] = ev[0].concat(ev[2]);
ev[2].length = 0;
}
}
}
ev[0] = []
ev[1] = 0 // listen phase
ev[2] = [] // new listeners
ev[3] = 0 // current iteration index
return ev
},
listen: (ev, fn) => (
ev[0].indexOf(fn) < 0 && (ev[1] ? (ev[2].indexOf(fn) < 0 && ev[2].push(fn)) : ev[0].push(fn)),
() => {
let i = ev[0].indexOf(fn)
i > -1 && (ev[1] && i <= ev[3] && ev[3]--, ev[0].splice(i, 1))
i = ev[2].indexOf(fn)
i > -1 && ev[2].splice(i, 1)
}
)
}
I should check its performance. Compare it with the original algorithm. We should understand how much we will miss.
from evemin.
50% - 100% slower
Lines 6 to 17 in 6c9f985
from evemin.
Related Issues (15)
- renaming: rename "event" to "<anything elese>"
- proposal package name: rvent
- proposal: entity from subdirectory HOT 1
- nested syntax proposal HOT 1
- performance issue: make two struct of subscribers. HOT 1
- name ideas: evemin
- performace: only event and listen no more!
- perf idea: attach should return first argument
- article idea: blazing fast event emitter in javascript
- feat: add typescript typings HOT 1
- refactor: rewrite test to typescript
- add og image to the repository
- add github ci and coveralls.io
- release 1.0.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from evemin.