mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-26 00:05:45 +00:00
refactor(FE): Add omit utility and refactor clearTabActions to use
it
This commit is contained in:
@@ -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 { TabActionsSlice } from '@/stores/tab-actions/tab-actions.store';
|
||||||
|
import { omit } from '@/lib/helper';
|
||||||
import { StateCreator } from 'zustand';
|
import { StateCreator } from 'zustand';
|
||||||
|
|
||||||
export const createTabActionsSlice: StateCreator<
|
export const createTabActionsSlice: StateCreator<
|
||||||
@@ -20,10 +21,9 @@ export const createTabActionsSlice: StateCreator<
|
|||||||
})),
|
})),
|
||||||
|
|
||||||
clearTabActions: (tabId) =>
|
clearTabActions: (tabId) =>
|
||||||
set((state) => {
|
set((state) => ({
|
||||||
const { [tabId]: _, ...rest } = state.tabActions;
|
tabActions: omit(state.tabActions, tabId),
|
||||||
return { tabActions: rest };
|
})),
|
||||||
}),
|
|
||||||
|
|
||||||
clearAllTabActions: () => set({ tabActions: {} }),
|
clearAllTabActions: () => set({ tabActions: {} }),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user