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

Issue with listenTo/stopListening and context #2015

Closed
tgriesser opened this issue Dec 24, 2012 · 5 comments
Closed

Issue with listenTo/stopListening and context #2015

tgriesser opened this issue Dec 24, 2012 · 5 comments

Comments

@tgriesser
Copy link
Collaborator

@kpdecker brought up this issue on #1954 - stopListening won't work with more than one context. Since the context isn't stored alongside the _listenerId, listening to the same object with two contexts makes it impossible to call stopListening and have all of the listeners properly removed.

test("bulk stopListening with context", 4, function() {
      var a = _.extend({}, Backbone.Events);
      var b = _.extend({}, Backbone.Events);
      var ctx = {};
      var calledWithContext = false;
      var calledWithoutContext = false;

      a.listenTo(b, 'foo', function(){ calledWithContext = true; }, ctx);
      a.listenTo(b, 'foo', function(){ calledWithoutContext = true; });

      a.stopListening(null, null, null, ctx);

      b.trigger('foo');

      equal(calledWithContext, false);
      equal(calledWithoutContext, true);

      calledWithContext = false;
      calledWithoutContext = false;
      a.stopListening();

      b.trigger('foo');

      equal(calledWithContext, false);
      equal(calledWithoutContext, false);
});
@caseywebdev
Copy link
Collaborator

The cleanest solution would be to remove the context option again. Otherwise, we have to do housekeeping on all of the passed in contexts...

objA.listenTo(objB, name, method, objC); still looks weird to me, like objA isn't really listening to anything, it's merely mediating objC's listenTo.

@gsamokovarov
Copy link
Contributor

👍 I liked the implicit this context better. Plus, it just makes the stopListening job way more cleaner and you can always _.bind another context, if you really have to.

@tgriesser
Copy link
Collaborator Author

I agree with @caseywebdev and @gsamokovarov

@braddunbar
Copy link
Collaborator

Ditto. The context argument makes little sense to me.

On Monday, December 24, 2012, Tim Griesser wrote:

I agree with @caseywebdev https://github.com/caseywebdev and
@gsamokovarov https://github.com/gsamokovarov


Reply to this email directly or view it on GitHubhttps://github.com//issues/2015#issuecomment-11665192.

-brad

@jashkenas
Copy link
Owner

Lovely.

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

No branches or pull requests

5 participants