fix: remove immer set to avoid object extensible
Signed-off-by: Innei <i@innei.in>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user