Skip to content

Commit

Permalink
Fixes a bug where stopReplying and stopComplying would unregister the…
Browse files Browse the repository at this point in the history
… wrong events.
  • Loading branch information
jamesplease committed Oct 27, 2014
1 parent 622ecbe commit 4442fbe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/backbone.radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ function callHandler(callback, context, args) {
function removeHandler(store, name, callback, context) {
var event = store[name];
if (
(!callback && !context) ||
callback && (callback === event.callback || callback === event.callback._callback) ||
context && context === event.context
(!callback || (callback === event.callback || callback === event.callback._callback)) &&
(!context || (context === event.context))
) {
delete store[name];
return true;
Expand Down
18 changes: 18 additions & 0 deletions test/spec/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,24 @@ describe('Commands:', function() {
});
});

describe('and passing a callback and a context', function() {
beforeEach(function() {
this.Commands.stopComplying(undefined, this.commandTwo, this.contextTwo);
});

it('should remove only matched handlers', function() {
expect(this.Commands._commands).to.not.contain.keys('commandFour');
});

it('should leave the other handlers', function() {
expect(this.Commands._commands).to.have.keys(['commandOne', 'commandTwo', 'commandThree', 'commandFive']);
});

it('should return the instance of Commands from stopComplying', function() {
expect(this.Commands.stopComplying).to.have.always.returned(this.Commands);
});
});

describe('and passing a name, callback, and context', function() {
beforeEach(function() {
this.Commands.stopComplying('commandThree', this.commandTwo, this.contextOne);
Expand Down
18 changes: 18 additions & 0 deletions test/spec/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,24 @@ describe('Requests:', function() {
});
});

describe('and passing a callback and a context', function() {
beforeEach(function() {
this.Requests.stopReplying(undefined, this.requestTwo, this.contextTwo);
});

it('should remove only matched handlers', function() {
expect(this.Requests._requests).to.not.contain.keys('requestFour');
});

it('should leave the other handlers', function() {
expect(this.Requests._requests).to.have.keys(['requestOne', 'requestTwo', 'requestThree', 'requestFive']);
});

it('should return the instance of Requests from stopReplying', function() {
expect(this.Requests.stopReplying).to.have.always.returned(this.Requests);
});
});

describe('and passing a name, callback, and context', function() {
beforeEach(function() {
this.Requests.stopReplying('requestThree', this.requestTwo, this.contextOne);
Expand Down

0 comments on commit 4442fbe

Please sign in to comment.