Skip to content

Commit

Permalink
fix devtools usage
Browse files Browse the repository at this point in the history
  • Loading branch information
SKarolFolio committed Dec 2, 2024
1 parent 6afd2d6 commit 2c88a04
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/store/loadingState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const STORE_NAME = 'LoadingState';
export const useLoadingStateStore = create<LoadingState>()(
devtools(
(...args) => ({
...createBaseSlice({ basic: 'isLoading' }, false, STORE_NAME)(...args),
...createBaseSlice({ basic: 'isLoading' }, false)(...args),
}),
{ enabled: !IS_PROD_MODE },
{ name: 'Linked Data Editor', store: STORE_NAME, enabled: !IS_PROD_MODE },
),
);
8 changes: 4 additions & 4 deletions src/store/marcPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const STORE_NAME = 'MarcPreview';
export const useMarcPreviewStore = create<MarcPreviewState>()(
devtools(
(...args) => ({
...createBaseSlice({ basic: 'basicValue' }, null, STORE_NAME)(...args),
...createBaseSlice({ basic: 'complexValue' }, null as MarcPreviewData, STORE_NAME)(...args),
...createBaseSlice({ basic: 'metaData' }, null as MarcPreviewMetaData, STORE_NAME)(...args),
...createBaseSlice({ basic: 'basicValue' }, null)(...args),
...createBaseSlice({ basic: 'complexValue' }, null as MarcPreviewData)(...args),
...createBaseSlice({ basic: 'metaData' }, null as MarcPreviewMetaData)(...args),
}),
{ enabled: !IS_PROD_MODE },
{ name: 'Linked Data Editor', store: STORE_NAME, enabled: !IS_PROD_MODE },
),
);
9 changes: 4 additions & 5 deletions src/store/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ const STORE_NAME = 'Status';
export const useStatusStore = create<StatusState>()(
devtools(
(...args) => ({
...createBaseSlice({ basic: 'lastSavedRecordId' }, null as LastSavedRecordId, STORE_NAME)(...args),
...createBaseSlice({ basic: 'isEditedRecord' }, false, STORE_NAME)(...args),
...createBaseSlice({ basic: 'recordStatus' }, { type: undefined } as RecordStatus, STORE_NAME)(...args),
...createBaseSlice({ basic: 'lastSavedRecordId' }, null as LastSavedRecordId)(...args),
...createBaseSlice({ basic: 'isEditedRecord' }, false)(...args),
...createBaseSlice({ basic: 'recordStatus' }, { type: undefined } as RecordStatus)(...args),
...createBaseSlice<'statusMessages', StatusEntry[], 'statusMessage', StatusEntry>(
{ basic: 'statusMessages', singleItem: 'statusMessage' },
[] as StatusEntry[],
STORE_NAME,
true,
)(...args),
}),
{ enabled: !IS_PROD_MODE },
{ name: 'Linked Data Editor', store: STORE_NAME, enabled: !IS_PROD_MODE },
),
);
8 changes: 3 additions & 5 deletions src/store/utils/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const updateValue = <V, T>(value: V, updatedValue: T): V => {
export const createBaseSlice = <K extends string, V, S extends string = K, T = V>(
keys: { basic: K; singleItem?: S },
initialValue: V,
sliceTitle: string,
canAddSingleItem = false,
): StateCreator<SliceState<K, V, S, T>, [['zustand/devtools', never]], [], SliceState<K, V, S, T>> => {
return set => {
Expand All @@ -56,9 +55,8 @@ export const createBaseSlice = <K extends string, V, S extends string = K, T = V
const baseSlice = {
[keys.basic]: initialValue,
[`set${capitalizedTitle}`]: (updatedValue: V) =>
set({ [keys.basic]: updatedValue } as any, false, `${sliceTitle}/set${capitalizedTitle}`),
[`reset${capitalizedTitle}`]: () =>
set({ [keys.basic]: initialValue } as any, false, `${sliceTitle}/reset${capitalizedTitle}`),
set({ [keys.basic]: updatedValue } as any, false, `set${capitalizedTitle}`),
[`reset${capitalizedTitle}`]: () => set({ [keys.basic]: initialValue } as any, false, `reset${capitalizedTitle}`),
} as SliceState<K, V, S, T>;

if (canAddSingleItem && keys.singleItem) {
Expand All @@ -70,7 +68,7 @@ export const createBaseSlice = <K extends string, V, S extends string = K, T = V
return { [keys.basic]: updateValue(value, updatedValue) } as any;
},
false,
`${sliceTitle}/add${capitalizedTitle}`,
`add${capitalizedTitle}`,
);
}

Expand Down

0 comments on commit 2c88a04

Please sign in to comment.