From 93cfb10787e575ac5f6e8e8c019043acc2b060ca Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Sun, 18 Sep 2022 01:46:09 +0300 Subject: [PATCH] fix unsubscribe bug in store --- frontend/src/stores.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/stores.js b/frontend/src/stores.js index 63e3136..5e83b47 100644 --- a/frontend/src/stores.js +++ b/frontend/src/stores.js @@ -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); }; }