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 +}