refactor(FE): Add omit utility and refactor clearTabActions to use

it
This commit is contained in:
rstubryan
2026-03-07 09:19:11 +07:00
parent d467c56ea6
commit e3b86e3033
2 changed files with 18 additions and 4 deletions
+14
View File
@@ -305,3 +305,17 @@ export function transformConstants(
},
};
}
export function omit<T extends Record<string, unknown>, K extends keyof T>(
obj: T,
keys: K | K[]
): Omit<T, K> {
const keysArray = Array.isArray(keys) ? keys : [keys];
const result = { ...obj };
keysArray.forEach((key) => {
delete result[key];
});
return result;
}
@@ -1,4 +1,5 @@
import { TabActionsSlice } from '@/stores/tab-actions/tab-actions.store';
import { omit } from '@/lib/helper';
import { StateCreator } from 'zustand';
export const createTabActionsSlice: StateCreator<
@@ -20,10 +21,9 @@ export const createTabActionsSlice: StateCreator<
})),
clearTabActions: (tabId) =>
set((state) => {
const { [tabId]: _, ...rest } = state.tabActions;
return { tabActions: rest };
}),
set((state) => ({
tabActions: omit(state.tabActions, tabId),
})),
clearAllTabActions: () => set({ tabActions: {} }),
});