From 7c27031f4e7da71253553517a4bfc1e22f4490e1 Mon Sep 17 00:00:00 2001 From: Siarhei Karol Date: Wed, 11 Dec 2024 16:40:55 +0300 Subject: [PATCH] update selectors --- src/store/selectors.ts | 19 ++++++++++--------- src/store/utils/selectors.ts | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/store/selectors.ts b/src/store/selectors.ts index 2936af20..0f1bfe6d 100644 --- a/src/store/selectors.ts +++ b/src/store/selectors.ts @@ -1,4 +1,3 @@ -import { createSelectors } from './utils/selectors'; import { useStatusStore } from './stores/status'; import { useLoadingStateStore } from './stores/loadingState'; import { useMarcPreviewStore } from './stores/marcPreview'; @@ -8,11 +7,13 @@ import { useConfigStore } from './stores/config'; import { useUIStore } from './stores/ui'; import { useSearchStore } from './stores/search'; -export const useStatusState = () => createSelectors(useStatusStore).use; -export const useLoadingState = () => createSelectors(useLoadingStateStore).use; -export const useMarcPreviewState = () => createSelectors(useMarcPreviewStore).use; -export const useProfileState = () => createSelectors(useProfileStore).use; -export const useInputsState = () => createSelectors(useInputsStore).use; -export const useConfigState = () => createSelectors(useConfigStore).use; -export const useUIState = () => createSelectors(useUIStore).use; -export const useSearchState = () => createSelectors(useSearchStore).use; +// "createSelectors" can be used here for generation of the memoized selectors. +// Now this function is non-optimized and its usage causes memory leaks. +export const useStatusState = useStatusStore; +export const useLoadingState = useLoadingStateStore; +export const useMarcPreviewState = useMarcPreviewStore; +export const useProfileState = useProfileStore; +export const useInputsState = useInputsStore; +export const useConfigState = useConfigStore; +export const useUIState = useUIStore; +export const useSearchState = useSearchStore; diff --git a/src/store/utils/selectors.ts b/src/store/utils/selectors.ts index 4137ea55..11e235cf 100644 --- a/src/store/utils/selectors.ts +++ b/src/store/utils/selectors.ts @@ -6,6 +6,8 @@ type WithSelectors = S extends { ? S & { use: { [K in keyof T]: T[K] } } : never; +// Use this function to generate all available selectors. +// Now it causes memory leaks if invoke it after each re-render, so it should be memoized. export const createSelectors = >>(_store: S) => { const store = _store as WithSelectors; store.use = {};