fix unsubscribe bug in store
This commit is contained in:
parent
14a98d7eb1
commit
93cfb10787
1 changed files with 3 additions and 2 deletions
|
@ -21,11 +21,12 @@ class Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe(handler) {
|
subscribe(handler) {
|
||||||
const handlerIndex = this._handlers.push(handler) - 1;
|
this._handlers.push(handler);
|
||||||
storeLog(`(${this.name}) (subscribe/initial)`, this.value);
|
storeLog(`(${this.name}) (subscribe/initial)`, this.value);
|
||||||
handler(this.value);
|
handler(this.value);
|
||||||
return () => {
|
return () => {
|
||||||
this._handlers.splice(handlerIndex, 1);
|
const index = this._handlers.indexOf(handler);
|
||||||
|
this._handlers.splice(index, 1);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue