Skip to content

Commit

Permalink
remove listenable in store.registered after unsubscribe()
Browse files Browse the repository at this point in the history
  • Loading branch information
undoZen committed Aug 17, 2014
1 parent 449c2d0 commit 760ecf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/createStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ module.exports = function(definition) {
throw Error("Store cannot listen to this listenable because of circular loop");
}
this.registered.push(listenable);
return listenable.listen(callback, this);
var unsubscribe = listenable.listen(callback, this);
var self = this;
return function () {
unsubscribe();
self.registered.splice(self.registered.indexOf(listenable), 1);
};
};
Store.prototype.listen = function(callback, bindContext) {
var eventHandler = function(args) {
Expand Down
7 changes: 7 additions & 0 deletions test/creatingStores.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ describe('Creating stores', function() {
}, 20);
});

it('can listenTo the same action again', function() {
store.listenTo(action, store.actionCalled);
action(1337, 'ninja');

return assert.eventually.deepEqual(promise, [1337, 'ninja']);
});

});

describe('listening to the store', function() {
Expand Down

0 comments on commit 760ecf5

Please sign in to comment.