Giter VIP home page Giter VIP logo

checked-emitter's Issues

Failing Listeners Cause Execution to Stop

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();
});

Emitter.once not working with functions that have arguments

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.