pdubroy / checked-emitter Goto Github PK
View Code? Open in Web Editor NEWA wrapper for facebook/emitter that requires event types to be registered before use.
License: MIT License
A wrapper for facebook/emitter that requires event types to be registered before use.
License: MIT License
When adding a listener that throws an error, the listeners following after the failed listener are not triggered (#1)
. Moreover, the the error bubbles to the point where emit()
was executed and interrupts the outer program flow too (#2)
.
Test case:
test('failing listeners', t => {
let e = new CheckedEmitter();
let x = false;
let y = false;
e.registerEvent('trigger');
e.addListener('trigger', () => { throw new Error(); x = true; });
e.addListener('trigger', () => { y = true; });
e.emit('trigger'); // (#2) should continue and not stop here
t.equal(x, false, 'x was not changed');
t.equal(y, true, 'y was changed'); // (#1) should reach the second listener
t.end();
});
test
In the current implementation, this._checkEventType(eventType, callback, 'callback arity');
is checked twice when adding a listener with once()
. The first time, it succeeds (in CheckedEmitter.prototype.once
) but once the call is forwarded to CheckedEmitter.prototype.addListener
with a wrapped callback created in the FB library, it fails when checkin the arity (the wrapper that got created has no arguments whereas the event might have some).
TypeError: Wrong callback arity for 'x': expected 1, got 0
at CheckedEmitter._checkEventType (./checked-emitter/index.js:60:13)
at CheckedEmitter.addListener (./checked-emitter/index.js:70:8)
at CheckedEmitter.once (./checked-emitter/node_modules/fbemitter/lib/BaseEventEmitter.js:81:17)
at CheckedEmitter.once (./checked-emitter/index.js:76:27)
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.