From f567fa8c6a0b4574b9a2265c7f2a42a1249d1a23 Mon Sep 17 00:00:00 2001 From: Ben Tidy Date: Sun, 21 Jul 2019 18:23:15 +0100 Subject: [PATCH] Fix the observers removal. Might be wrong but we shouldn't be adding observers on destruction. Also sometimes the observer didn't exist which caused errors to be thrown. --- addon/components/ember-chart.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/addon/components/ember-chart.js b/addon/components/ember-chart.js index 42de058..a7f630b 100644 --- a/addon/components/ember-chart.js +++ b/addon/components/ember-chart.js @@ -297,13 +297,16 @@ export default Component.extend({ // destroy the chartjs object class this.get('chart').destroy(); - // remove the observers - this.addObserver('data', this, this.updateChart); - this.addObserver('data.[]', this, this.updateChart); - this.removeObserver('model', this, this.updateChart); - this.removeObserver('model.[]', this, this.updateChart); - this.removeObserver('_page', this, this.updateChart); - this.removeObserver('colors.[]', this, this.updateChart); + // remove the observers + if (this.get('isModel')) { + this.removeObserver('model', this, this.updateChart); + this.removeObserver('model.[]', this, this.updateChart); + this.removeObserver('_page', this, this.updateChart); + this.removeObserver('colors.[]', this, this.updateChart); + } else { + this.removeObserver('data', this, this.updateChart); + this.removeObserver('data.[]', this, this.updateChart); + } this.removeObserver('options', this, this.redrawChart); this.removeObserver('type', this, this.redrawChart); },