Skip to content

Commit

Permalink
Merge pull request #80 from nsftx/task/CU-8694xgzft/master_reset
Browse files Browse the repository at this point in the history
Save event listener reference for deregister
  • Loading branch information
Lanchi authored Jun 26, 2024
2 parents 9af030f + 0ba1a71 commit 14cd579
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/master_gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ function validateInitialization(config) {
}
}

var msgListenerReference = null;

var masterGateway = {

initialized: false,
Expand All @@ -55,6 +57,7 @@ var masterGateway = {

eventHandler: null,


init: function (config) {
var slaves = config.slaves || config.products;
this.initialized = true;
Expand All @@ -70,7 +73,8 @@ var masterGateway = {
}
this.setAllowedDomains();
//Set message handler
window.addEventListener('message', this.handleMessage.bind(this));
msgListenerReference = this.handleMessage.bind(this);
window.addEventListener('message', msgListenerReference);
},

addSlave: function(config) {
Expand Down Expand Up @@ -398,7 +402,7 @@ var masterGateway = {

this.clearSubscriptions();

window.removeEventListener('message', this.handleMessage.bind(this));
window.removeEventListener('message', msgListenerReference);
},

_createCallbackSubscription : function(event, def, idx) {
Expand Down

0 comments on commit 14cd579

Please sign in to comment.