From af2fa65eb1b10acb5394b2413ea88418d7510fbd Mon Sep 17 00:00:00 2001 From: barr-enden Date: Mon, 20 Jan 2025 11:32:54 +0200 Subject: [PATCH] Observable State: remove cached selector. Removed caching of selector in case of using observable state, to avoid bugs of outdated values read from the observable state. --- src/throttledStore.tsx | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/throttledStore.tsx b/src/throttledStore.tsx index 40db6d7..22b1c85 100644 --- a/src/throttledStore.tsx +++ b/src/throttledStore.tsx @@ -311,15 +311,9 @@ export const createObservable = ( name: uniqueName } const observersSlot = shell.declareSlot(subscribersSlotKey) - let cachedSelector: TSelector | undefined - const getOrCreateCachedSelector = (): TSelector => { - if (cachedSelector) { - return cachedSelector - } - const newSelector = selectorFactory(shell.getStore().getState()) - cachedSelector = newSelector - return newSelector + const createSelector = (): TSelector => { + return selectorFactory(shell.getStore().getState()) } return { @@ -330,10 +324,9 @@ export const createObservable = ( } }, notify() { - cachedSelector = undefined - const newSelector = getOrCreateCachedSelector() + const newSelector = createSelector() invokeSlotCallbacks(observersSlot, newSelector) }, - current: getOrCreateCachedSelector + current: createSelector } }