From 86ef0873109b6b95a10cd3c6d57f2e682904c256 Mon Sep 17 00:00:00 2001 From: Archis Gore Date: Wed, 13 Jul 2016 20:06:55 -0700 Subject: [PATCH] Store the Sync wrapper in a variable for clean removal. This commit primarily fixes this issue: https://github.com/koalyptus/TableFilter/issues/258 The fix here is to store a Sync call closed over "this" straight within the object we're referencing. This having access to that object, we can always retrieve the exact function reference/pointer/instance for removal from handling events. --- src/modules/hash.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/modules/hash.js b/src/modules/hash.js index 0bfb5ad7..b162e36f 100644 --- a/src/modules/hash.js +++ b/src/modules/hash.js @@ -38,10 +38,11 @@ export class Hash { } this.lastHash = location.hash; + this.boundSync = this.sync.bind(this); //Store a bound sync wrapper for future use. this.emitter.on(['state-changed'], (tf, state) => this.update(state)); - this.emitter.on(['initialized'], () => this.sync()); - addEvt(root, 'hashchange', () => this.sync()); + this.emitter.on(['initialized'], this.boundSync); + addEvt(root, 'hashchange', this.boundSync); } /** @@ -90,8 +91,8 @@ export class Hash { */ destroy() { this.emitter.off(['state-changed'], (tf, state) => this.update(state)); - this.emitter.off(['initialized'], () => this.sync()); - removeEvt(root, 'hashchange', () => this.sync()); + this.emitter.off(['initialized'], () => this.boundSync); + removeEvt(root, 'hashchange', () => this.boundSync); this.state = null; this.lastHash = null;