fix: remove immer set to avoid object extensible

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-11-01 23:42:34 +08:00
parent 6ad35ad671
commit 7e5a79155a
2 changed files with 16 additions and 4 deletions
+7 -4
View File
@@ -14,22 +14,25 @@ export const useListStore = createZustandStore<ListState>("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)
+9
View File
@@ -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<T>(input: T): T {
if (Array.isArray(input)) {
return [...input] as T
} else if (input && typeof input === "object") {
return { ...input } as T
}
return input
}