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

Stream removes itself upon destruction #609

Merged
merged 2 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,21 @@ function __(StreamCtor) {
var mapper = hintMapper(mappingHint);

s = new StreamCtor();
secondArg.on(xs, function () {

var callback_func = function () {
var ctx = mapper.apply(this, arguments);
s.write(ctx);
});
};

secondArg.on(xs, callback_func);
var removeMethod = secondArg.removeListener // EventEmitter
|| secondArg.unbind; // jQuery

if (removeMethod) {
s._destructors.push(function() {
removeMethod.call(secondArg, xs, callback_func);
});
}
}
else {
throw new Error(
Expand Down
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2864,6 +2864,21 @@ exports['wrap EventEmitter (or jQuery) on handler'] = function (test) {
});
};

exports['removing EventEmitter (or jQuery) listener on destruction (issue #500)'] = function(test) {
var ee = new EventEmitter();
var s = _('myevent', ee);

var removed = false;

ee.on('removeListener', function() {
removed = true;
});

s.destroy();
test.ok(removed);
test.done();
};

exports['wrap EventEmitter (or jQuery) on handler with args wrapping by function'] = function (test) {
var ee = {
on: function (name, f) {
Expand Down