From bc7e62817b87a8ca34aa379929a8063fd2fb90c5 Mon Sep 17 00:00:00 2001 From: David Soler Date: Tue, 29 Mar 2016 11:17:02 +0200 Subject: [PATCH 1/2] Fixed crash when calling stopListeningTo on a store that listens to multiple stores ( The listened stores subs where being deleted instead of the listener subs) --- src/ListenerMethods.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ListenerMethods.js b/src/ListenerMethods.js index d45327d..d6e2c58 100644 --- a/src/ListenerMethods.js +++ b/src/ListenerMethods.js @@ -118,10 +118,10 @@ export default { _.throwIf(this.validateListening(listenable)); this.fetchInitialState(listenable, defaultCallback); desub = listenable.listen(this[callback] || callback, this); - unsubscriber = function() { - var index = subs.indexOf(subscriptionobj); + unsubscriber = function(listenerSubs) { + var index = listenerSubs.indexOf(subscriptionobj); _.throwIf(index === -1, "Tried to remove listen already gone from subscriptions list!"); - subs.splice(index, 1); + listenerSubs.splice(index, 1); desub(); }; subscriptionobj = { @@ -143,7 +143,7 @@ export default { for(;i < subs.length; i++){ sub = subs[i]; if (sub.listenable === listenable){ - sub.stop(); + sub.stop(subs); _.throwIf(subs.indexOf(sub) !== -1, "Failed to remove listen from subscriptions list!"); return true; } @@ -157,7 +157,7 @@ export default { stopListeningToAll: function(){ var remaining, subs = this.subscriptions || []; while((remaining = subs.length)){ - subs[0].stop(); + subs[0].stop(subs); _.throwIf(subs.length !== remaining - 1, "Failed to remove listen from subscriptions list!"); } }, From 9f29a95d83aa3dc3e0cd329ec7ec00932f01f71c Mon Sep 17 00:00:00 2001 From: David Soler Date: Tue, 29 Mar 2016 11:25:47 +0200 Subject: [PATCH 2/2] Added compatibility with older way of using --- src/ListenerMethods.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ListenerMethods.js b/src/ListenerMethods.js index d6e2c58..7736726 100644 --- a/src/ListenerMethods.js +++ b/src/ListenerMethods.js @@ -119,9 +119,10 @@ export default { this.fetchInitialState(listenable, defaultCallback); desub = listenable.listen(this[callback] || callback, this); unsubscriber = function(listenerSubs) { - var index = listenerSubs.indexOf(subscriptionobj); + var currentSubs = listenerSubs ? listenerSubs : subs; + var index = currentSubs.indexOf(subscriptionobj); _.throwIf(index === -1, "Tried to remove listen already gone from subscriptions list!"); - listenerSubs.splice(index, 1); + currentSubs.splice(index, 1); desub(); }; subscriptionobj = {