diff --git a/src/stores/tab-actions/slices/tab-actions.slice.ts b/src/stores/tab-actions/slices/tab-actions.slice.ts new file mode 100644 index 00000000..66b53c3c --- /dev/null +++ b/src/stores/tab-actions/slices/tab-actions.slice.ts @@ -0,0 +1,29 @@ +import { TabActionsSlice } from '@/stores/tab-actions/tab-actions.store'; +import { StateCreator } from 'zustand'; + +export const createTabActionsSlice: StateCreator< + TabActionsSlice, + [], + [], + TabActionsSlice +> = (set) => ({ + // Initial state + tabActions: {}, + + // Actions + setTabActions: (tabId, actions) => + set((state) => ({ + tabActions: { + ...state.tabActions, + [tabId]: actions, + }, + })), + + clearTabActions: (tabId) => + set((state) => { + const { [tabId]: _, ...rest } = state.tabActions; + return { tabActions: rest }; + }), + + clearAllTabActions: () => set({ tabActions: {} }), +}); diff --git a/src/stores/tab-actions/tab-actions.store.ts b/src/stores/tab-actions/tab-actions.store.ts index 15ccf186..e80c3016 100644 --- a/src/stores/tab-actions/tab-actions.store.ts +++ b/src/stores/tab-actions/tab-actions.store.ts @@ -3,6 +3,7 @@ import { create } from 'zustand'; import { devtools } from 'zustand/middleware'; import { ReactNode } from 'react'; +import { createTabActionsSlice } from '@/stores/tab-actions/slices/tab-actions.slice'; export type TabActionsSlice = { // State - actions per tab ID @@ -16,24 +17,8 @@ export type TabActionsSlice = { export const useTabActionsStore = create()( devtools( - (set) => ({ - tabActions: {}, - - setTabActions: (tabId, actions) => - set((state) => ({ - tabActions: { - ...state.tabActions, - [tabId]: actions, - }, - })), - - clearTabActions: (tabId) => - set((state) => { - const { [tabId]: _, ...rest } = state.tabActions; - return { tabActions: rest }; - }), - - clearAllTabActions: () => set({ tabActions: {} }), + (...args) => ({ + ...createTabActionsSlice(...args), }), { name: 'TabActionsStore',