fix unsubscribe bug in store

This commit is contained in:
hippoz 2022-09-18 01:46:09 +03:00
parent 14a98d7eb1
commit 93cfb10787
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

@ -21,11 +21,12 @@ class Store {
}
subscribe(handler) {
const handlerIndex = this._handlers.push(handler) - 1;
this._handlers.push(handler);
storeLog(`(${this.name}) (subscribe/initial)`, this.value);
handler(this.value);
return () => {
this._handlers.splice(handlerIndex, 1);
const index = this._handlers.indexOf(handler);
this._handlers.splice(index, 1);
};
}