From 02bba452f79709e8ffd6540b390cc2b73f5e8b45 Mon Sep 17 00:00:00 2001 From: Heinrich Lee Yu Date: Fri, 10 Jul 2015 13:45:16 +0800 Subject: [PATCH] Clean up events when removing component --- addon/mixins/resize-aware.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/addon/mixins/resize-aware.js b/addon/mixins/resize-aware.js index dafe9859..3413b9eb 100644 --- a/addon/mixins/resize-aware.js +++ b/addon/mixins/resize-aware.js @@ -14,14 +14,20 @@ export default Ember.Mixin.create({ didInsertElement() { this._super(...arguments); if (this.get('resizeEventsEnabled')) { - this.get('resizeService').on('didResize', evt => { - this._handleResizeEvent(evt); - }); + this.get('resizeService').on('didResize', this, this._handleResizeEvent); } if (this.get('resizeDebouncedEventsEnabled')) { - this.get('resizeService').on('debouncedDidResize', evt => { - this._handleDebouncedResizeEvent(evt); - }); + this.get('resizeService').on('debouncedDidResize', this, this._handleDebouncedResizeEvent); + } + }, + + willDestroyElement() { + this._super(...arguments); + if (this.get('resizeEventsEnabled')) { + this.get('resizeService').off('didResize', this, this._handleResizeEvent); + } + if (this.get('resizeDebouncedEventsEnabled')) { + this.get('resizeService').off('debouncedDidResize', this, this._handleDebouncedResizeEvent); } },