Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

longjohn is not compatible to other modules using a similar wrapping of EventEmitter #60

Open
Flarna opened this issue May 18, 2016 · 1 comment

Comments

@Flarna
Copy link

Flarna commented May 18, 2016

The way how longjohn wraps EventEmitter is incompatible with other modules doing a similar/same wrapping.
I tested by creating a clone of longjohn (incl. modifiny the 'longjohn' property of on()) and used it together with unmodified longjohn in following script:

require('longjohn');

var assert = require('assert');
var EventEmitter = require('events').EventEmitter;

function onListener() {}
function onceListener() {}

function test() {
    var emitter = new EventEmitter;
    emitter.on('xxx', onListener);
    emitter.once('xxx', onceListener);
    assert.equal(emitter.listenerCount('xxx'), 2);

    emitter.removeListener('xxx', onListener);
    // fails on second call as onListener was not removed
    assert.equal(emitter.listenerCount('xxx'), 1);

    emitter.removeListener('xxx', onceListener);
    assert.equal(emitter.listenerCount('xxx'), 0);
}

test();

require('longjohn-clone');

test();
@Flarna
Copy link
Author

Flarna commented Jan 18, 2017

Above sample passes now since #67 but following sample fails:

require('longjohn');

var assert = require('assert');
var EventEmitter = require('events').EventEmitter;

function onListener() {}
function onceListener() {}

function test() {
    var emitter = new EventEmitter;
    emitter.on('xxx', onListener);
    assert.equal(emitter.listenerCount('xxx'), 1);
    emitter.emit("xxx");
    // fails on second call as onListener was removed
    assert.equal(emitter.listenerCount('xxx'), 1);
}

test();

require('longjohn-clone');

test();

Reason is that second on() call sees the listener property and installs the function as once handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant