re-js / evemin Goto Github PK
View Code? Open in Web Editor NEWModern and blazing fast event emitter
License: MIT License
Modern and blazing fast event emitter
License: MIT License
import { event } from 're-event/entity';
const ev = event();
const f = ev.map(v => v * 10).filter(v => v);
f.listen(v => console.log(v));
without entity
import { event, map, filter, listen } from 'rvent';
const ev = event();
const f = event(ev, map(v => v * 10), filter(v => v));
listen(f, v => console.log(v));
last one)
import E from 're-event';
const ev = E.event();
const f = E.event(ev, E.map(v => v * 10), E.filter(v => v));
E.listen(f, v => console.log(v));
I will store all subscribers in the Set.
(new Set()).add(subscriber)
But I think iteration of the set should be an expensive operation, and the better one is the suppose both operations.
Set
for storing list of subscribers and effective unlinking.const fn = (v) => (listener(v), top_fn(v));
top_fn = fn;
const fire_stack = [];
const call_node(v) => {
// stack_start
top_fn(v);
// collect fires
Performance test should be next issue)
const listen = (ev, fn) => {
if (ev[1].indexOf(fn) === -1) ev[1] = ev[1].concat(fn);
return () => {
ev[1] = ev[1].filter(f => f !== fn);
}
}
will be
const listen = (ev, fn) => (
ev[1].indexOf(fn) === -1 && ev[1] = ev[1].concat(fn),
attach(() => (ev[1] = ev[1].filter(f => f !== fn)))
)
And compare between "evemin" and standard event emitter from nodejs.
const a = event()
const b = event(a, map(v => v + 1), filter(v => v) /*, listen(v => console.log(v) */)
const unsub = listen(b, v => console.log(v))
Sure compatible with unsubscriber
listen: (ev, fn) => (
ev[0].indexOf(fn) < 0 && (ev[0] = ev[0].concat(fn)),
() => {
let i = ev[0].indexOf(fn)
i > -1 && ev[0].splice(i, 1) // error here with iteration exactly all listeners in "ev" function
}
)
Reason:
evemin
event-mini
nano-event
lib size reason:
Only event and listen should be implemented using a single array, and the unsubscriber dependency
event
listen
Because "event" is deprecated js keyword in dom env))
var event: Event | undefined @deprecated 'event' is deprecated.ts(6385) lib.dom.d.ts(17678, 5): The declaration was marked as deprecated here. Object is possibly 'undefined'.
Variants:
rvent
re-event
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.