From e3b86e3033ee1acdf6ca19c9eb1d2f423e8c6d6a Mon Sep 17 00:00:00 2001 From: rstubryan Date: Sat, 7 Mar 2026 09:19:11 +0700 Subject: [PATCH] refactor(FE): Add `omit` utility and refactor `clearTabActions` to use it --- src/lib/helper.ts | 14 ++++++++++++++ src/stores/tab-actions/slices/tab-actions.slice.ts | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/lib/helper.ts b/src/lib/helper.ts index 7ae4aaae..1c4f1382 100644 --- a/src/lib/helper.ts +++ b/src/lib/helper.ts @@ -305,3 +305,17 @@ export function transformConstants( }, }; } + +export function omit, K extends keyof T>( + obj: T, + keys: K | K[] +): Omit { + const keysArray = Array.isArray(keys) ? keys : [keys]; + const result = { ...obj }; + + keysArray.forEach((key) => { + delete result[key]; + }); + + return result; +} diff --git a/src/stores/tab-actions/slices/tab-actions.slice.ts b/src/stores/tab-actions/slices/tab-actions.slice.ts index 66b53c3c..eba63c35 100644 --- a/src/stores/tab-actions/slices/tab-actions.slice.ts +++ b/src/stores/tab-actions/slices/tab-actions.slice.ts @@ -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: {} }), });