From 7e5a79155a083a8242579dee18d019049b7ad6f5 Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 1 Nov 2024 23:42:34 +0800 Subject: [PATCH] fix: remove immer set to avoid object extensible Signed-off-by: Innei --- apps/renderer/src/store/list/store.ts | 11 +++++++---- packages/utils/src/utils.ts | 9 +++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/renderer/src/store/list/store.ts b/apps/renderer/src/store/list/store.ts index 5fcd672ad..2cd485dfb 100644 --- a/apps/renderer/src/store/list/store.ts +++ b/apps/renderer/src/store/list/store.ts @@ -14,22 +14,25 @@ export const useListStore = createZustandStore("list")(() => ({ const immerSet = createImmerSetter(useListStore) const get = useListStore.getState - +const set = useListStore.setState class ListActionStatic { upsertMany(lists: ListModelPoplutedFeeds[]) { if (lists.length === 0) return const feeds = [] as FeedModel[] - immerSet((state) => { + set((state) => { for (const list of lists) { state.lists[list.id] = list if (!list.feeds) continue for (const feed of list.feeds) { - feeds.push({ ...feed }) + feeds.push(feed) } } - return state + return { + ...state, + lists: { ...state.lists }, + } }) feedActions.upsertMany(feeds) diff --git a/packages/utils/src/utils.ts b/packages/utils/src/utils.ts index ad659cf0e..7ce32b689 100644 --- a/packages/utils/src/utils.ts +++ b/packages/utils/src/utils.ts @@ -199,3 +199,12 @@ export { parse as parseUrl } from "tldts" export const clamp = (value: number, min: number, max: number) => Math.min(Math.max(value, min), max) + +export function shallowCopy(input: T): T { + if (Array.isArray(input)) { + return [...input] as T + } else if (input && typeof input === "object") { + return { ...input } as T + } + return input +}