Comments (4)
Is this different from how fbemitter behaves?
from checked-emitter.
It seems that fbemitter has the same behaviour:
> const fbemitter = require('fbemitter');
undefined
> const e = new fbemitter.EventEmitter();
undefined
> e.addListener('foo', () => { throw new Error('oops'); })
> (function() { e.emit('foo'); console.log('made it!'); })()
Error: oops
at e.addListener (repl:1:36)
at BaseEventEmitter.__emitToSubscription (/private/tmp/node_modules/fbemitter/lib/BaseEventEmitter.js:185:27)
at BaseEventEmitter.emit (/private/tmp/node_modules/fbemitter/lib/BaseEventEmitter.js:166:37)
at repl:1:17
at repl:1:57
at REPLServer.defaultEval (repl.js:272:27)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:441:10)
at emitOne (events.js:101:20)
I'm tempted to leave it this way, as I'm not sure I want to go down the road of trying to improve on their API -- I'd rather just keep this a naive wrapper.
Do you have a particular use case where you think it should really catch the error? You can always wrap your own handlers with try/catch so it seems more flexible the way it is.
from checked-emitter.
I think it's reasonable to think that an event system should not break just because one of the listeners has a problem. It doesn't happen to DOM events for example:
var event = new Event('testEvent');
var x = false;
var y = false;
// var elem = document.query(...);
elem.addEventListener('testEvent', function (e) { throw new Error(); x = true; });
elem.addEventListener('testEvent', function (e) { y = true; });
elem.dispatchEvent(event);
x === true; // false
y === true; // true
Current use-case - and where I discovered the problem - is the Ohm Editor and different prototypes registering to parse:grammar
. If some prototype fails, my listener won't get called (and I don't want to fix other things first before being able to do my work).
from checked-emitter.
I don't know, I'm tempted to leave this as is. First, because I'd like to keep this package an as-simple-as-possible wrapper about fbemitter, and second, because I think fail-fast is probably a better default behaviour.
from checked-emitter.
Related Issues (3)
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 checked-emitter.