1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-19 14:56:40 +02:00

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.
This commit is contained in:
Archis Gore 2016-07-13 20:06:55 -07:00
parent 0775470b49
commit 86ef087310

View file

@ -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;