From 4d11cedcf5162abeaec02d3d5212fca67b4eb552 Mon Sep 17 00:00:00 2001 From: Siarhei Karol Date: Thu, 5 Dec 2024 11:39:45 +0300 Subject: [PATCH] store types refactoring --- src/store/inputs.ts | 5 ++--- src/store/loadingState.ts | 5 ++--- src/store/marcPreview.ts | 5 ++--- src/store/profile.ts | 5 ++--- src/store/status.ts | 5 ++--- src/store/utils/storeCreator.ts | 6 ++++-- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/store/inputs.ts b/src/store/inputs.ts index 277b9a35..e3b394e0 100644 --- a/src/store/inputs.ts +++ b/src/store/inputs.ts @@ -1,6 +1,5 @@ -import { StateCreator } from 'zustand'; import { createBaseSlice, SliceState } from './utils/slice'; -import { generateStore } from './utils/storeCreator'; +import { generateStore, type StateCreatorTyped } from './utils/storeCreator'; export type RecordState = RecordEntry | null; export type SelectedRecordBlocksState = SelectedRecordBlocks | undefined; @@ -14,7 +13,7 @@ export type InputsState = SliceState<'userValues', UserValues> & const STORE_NAME = 'Inputs'; -const inputsStore: StateCreator = (...args) => ({ +const inputsStore: StateCreatorTyped = (...args) => ({ ...createBaseSlice({ basic: 'userValues' }, {} as UserValues, true)(...args), ...createBaseSlice({ basic: 'previewContent' }, [] as PreviewContent[])(...args), ...createBaseSlice({ basic: 'record' }, null as RecordState)(...args), diff --git a/src/store/loadingState.ts b/src/store/loadingState.ts index 6b668498..47d8f625 100644 --- a/src/store/loadingState.ts +++ b/src/store/loadingState.ts @@ -1,12 +1,11 @@ -import { StateCreator } from 'zustand'; import { createBaseSlice, SliceState } from './utils/slice'; -import { generateStore } from './utils/storeCreator'; +import { generateStore, type StateCreatorTyped } from './utils/storeCreator'; export type LoadingState = SliceState<'isLoading', boolean>; const STORE_NAME = 'Loading'; -const loadingStateStore: StateCreator = (...args) => ({ +const loadingStateStore: StateCreatorTyped = (...args) => ({ ...createBaseSlice({ basic: 'isLoading' }, false)(...args), }); diff --git a/src/store/marcPreview.ts b/src/store/marcPreview.ts index ff3a1131..8220501d 100644 --- a/src/store/marcPreview.ts +++ b/src/store/marcPreview.ts @@ -1,6 +1,5 @@ -import { StateCreator } from 'zustand'; import { createBaseSlice, SliceState } from './utils/slice'; -import { generateStore } from './utils/storeCreator'; +import { generateStore, type StateCreatorTyped } from './utils/storeCreator'; type MarcPreviewData = MarcDTO | null; type MarcPreviewMetaData = MarcPreviewMetadata | null; @@ -11,7 +10,7 @@ export type MarcPreviewState = SliceState<'basicValue', any> & const STORE_NAME = 'MarcPreview'; -const marcPreviewStore: StateCreator = (...args) => ({ +const marcPreviewStore: StateCreatorTyped = (...args) => ({ ...createBaseSlice({ basic: 'basicValue' }, null)(...args), ...createBaseSlice({ basic: 'complexValue' }, null as MarcPreviewData)(...args), ...createBaseSlice({ basic: 'metaData' }, null as MarcPreviewMetaData)(...args), diff --git a/src/store/profile.ts b/src/store/profile.ts index 1d7b6dca..d5083933 100644 --- a/src/store/profile.ts +++ b/src/store/profile.ts @@ -1,6 +1,5 @@ -import { StateCreator } from 'zustand'; import { createBaseSlice, SliceState } from './utils/slice'; -import { generateStore } from './utils/storeCreator'; +import { generateStore, type StateCreatorTyped } from './utils/storeCreator'; type SelectedProfileType = ProfileEntry | null; type PreparedFieldsType = ResourceTemplates | null; @@ -14,7 +13,7 @@ export type ProfileState = SliceState<'profiles', ProfileEntry[]> & const STORE_NAME = 'Profile'; -const profileStore: StateCreator = (...args) => ({ +const profileStore: StateCreatorTyped = (...args) => ({ ...createBaseSlice({ basic: 'profiles' }, [] as ProfileEntry[])(...args), ...createBaseSlice({ basic: 'selectedProfile' }, null as SelectedProfileType)(...args), ...createBaseSlice({ basic: 'preparedFields' }, null as PreparedFieldsType)(...args), diff --git a/src/store/status.ts b/src/store/status.ts index efb4bbaf..baf14179 100644 --- a/src/store/status.ts +++ b/src/store/status.ts @@ -1,6 +1,5 @@ -import { StateCreator } from 'zustand'; import { createBaseSlice, SliceState } from './utils/slice'; -import { generateStore } from './utils/storeCreator'; +import { generateStore, type StateCreatorTyped } from './utils/storeCreator'; type LastSavedRecordId = string | null; @@ -11,7 +10,7 @@ export type StatusState = SliceState<'lastSavedRecordId', LastSavedRecordId> & const STORE_NAME = 'Status'; -const statusStore: StateCreator = (...args) => ({ +const statusStore: StateCreatorTyped = (...args) => ({ ...createBaseSlice({ basic: 'lastSavedRecordId' }, null as LastSavedRecordId)(...args), ...createBaseSlice({ basic: 'isEditedRecord' }, false)(...args), ...createBaseSlice({ basic: 'recordStatus' }, { type: undefined } as RecordStatus)(...args), diff --git a/src/store/utils/storeCreator.ts b/src/store/utils/storeCreator.ts index 42453d12..6dde9242 100644 --- a/src/store/utils/storeCreator.ts +++ b/src/store/utils/storeCreator.ts @@ -1,8 +1,10 @@ -import { create, StateCreator } from 'zustand'; +import { create, type StateCreator } from 'zustand'; import { devtools } from 'zustand/middleware'; import { IS_PROD_MODE } from '@common/constants/bundle.constants'; const STORE_NAME = 'Linked Data Editor'; -export const generateStore = (store: StateCreator, name: string) => +export type StateCreatorTyped = StateCreator; + +export const generateStore = (store: StateCreatorTyped, name: string) => create()(devtools(store, { name: STORE_NAME, store: name, enabled: !IS_PROD_MODE }));