FIX: Unsubscribe seemed to be missing some events (#7762)

FIX: Unsubscribe seemed to be missing some events (#7762)

This forces an unsubscribe from all events.

diff --git a/test/javascripts/test_helper.js b/test/javascripts/test_helper.js
index 9d9d859..eebf640 100644
--- a/test/javascripts/test_helper.js
+++ b/test/javascripts/test_helper.js
@@ -178,10 +178,7 @@ QUnit.testDone(function() {
     }
   });
 
-  // attempts to remove any subscribed message bus callback
-  window.MessageBus.callbacks.forEach(function(callback) {
-    window.MessageBus.unsubscribe(callback.channel, callback.func);
-  });
+  window.MessageBus.unsubscribe("*");
 });
 
 // Load ES6 tests

GitHub sha: 9daba50d

2 Likes

This is somewhat strange… I would like the code in message bus reviewed then?

This is the only place it is added:

And this is the removal function:

I am not sure how this is possible?

1 Like

I dived into it this morning and it seems that unsubscribe loops through and modifies the same array as Window.MessageBus.callbacks. This means that when looping through an array as it’s being spliced that certain elements are missed.

This goes away when you delete on the glob of * since there’s only one loop through all the callbacks.

3 Likes

Ohhhh I was hunting for a bug in MessageBus here but this is entirely a usage thing. Adding a slice(0) to clone would fix this… but clearly this is just a wasteful amount of code to write when we can simply unsubscribe("*")

  window.MessageBus.callbacks.slice(0).forEach(function(callback) {
    window.MessageBus.unsubscribe(callback.channel, callback.func);
  });
1 Like

@SamSaffron I came to the same conclusion!

2 Likes