From 62b7d0d46f0b9b1084b1d6db9f76a276075eec52 Mon Sep 17 00:00:00 2001 From: Jonathan Eiten Date: Tue, 12 Jan 2016 14:43:58 -0500 Subject: [PATCH] proposed unsubscribe fix --- polymer/js/fin-hypergrid-excel.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/polymer/js/fin-hypergrid-excel.js b/polymer/js/fin-hypergrid-excel.js index db37358e9..81f40e783 100644 --- a/polymer/js/fin-hypergrid-excel.js +++ b/polymer/js/fin-hypergrid-excel.js @@ -177,8 +177,17 @@ * */ subscribeToBus: function() { - fin.desktop.InterApplicationBus.subscribe('*', this.subscribe, this.subscriptionCallback.bind(this)); - fin.desktop.InterApplicationBus.subscribe('*', 'ExcelError', this.errorCallback.bind(this)); + this.unSubscribeToBus(); // automatically cancel existing subscription, if any + + if (this.subscribe.toLowerCase() !== 'null') { + this.busHandlers ={ + subscription: this.subscriptionCallback.bind(this), + error: this.errorCallback.bind(this) + }; + + fin.desktop.InterApplicationBus.subscribe('*', this.subscribe, this.busHandlers.subscription); + fin.desktop.InterApplicationBus.subscribe('*', 'ExcelError', this.busHandlers.error); + } }, /** @@ -189,8 +198,11 @@ * */ unSubscribeToBus: function() { - fin.desktop.InterApplicationBus.unsubscribe('*', this.subscribe, this.subscriptionCallback.bind(this)); - fin.desktop.InterApplicationBus.unsubscribe('*', 'ExcelError', this.errorCallback.bind(this)); + if (this.busHandlers) { + fin.desktop.InterApplicationBus.unsubscribe('*', this.subscribe, this.busHandlers.subscription); + fin.desktop.InterApplicationBus.unsubscribe('*', 'ExcelError', this.busHandlers.error); + delete this.busHandlers; + } }, /**