From 0ba1a7159860ca590d2b3c362f90124c23999f47 Mon Sep 17 00:00:00 2001 From: Lanchi Date: Wed, 26 Jun 2024 15:20:58 +0200 Subject: [PATCH] Save event listener reference for deregister --- src/master_gateway.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/master_gateway.js b/src/master_gateway.js index f25a92b..b4808b0 100644 --- a/src/master_gateway.js +++ b/src/master_gateway.js @@ -41,6 +41,8 @@ function validateInitialization(config) { } } +var msgListenerReference = null; + var masterGateway = { initialized: false, @@ -55,6 +57,7 @@ var masterGateway = { eventHandler: null, + init: function (config) { var slaves = config.slaves || config.products; this.initialized = true; @@ -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) { @@ -398,7 +402,7 @@ var masterGateway = { this.clearSubscriptions(); - window.removeEventListener('message', this.handleMessage.bind(this)); + window.removeEventListener('message', msgListenerReference); }, _createCallbackSubscription : function(event, def, idx) {