Skip to content

Commit 626ec28

Browse files
committed
~ Prevent changes to initial state
1 parent a9d0bd0 commit 626ec28

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/2n8.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ export function createStore<Store extends TwoAndEight>(
142142
if (typeof value === 'function') {
143143
throw new TypeError('2n8: Cannot reset a method.')
144144
}
145-
const initialValue = initialState[field]
145+
const initialValue = structuredClone(initialState[field])
146146
if (initialValue !== undefined) {
147147
store[field] = initialValue
148148
commit(prevState, store.$getState())
149149
}
150150
} else {
151151
for (const [key, initialValue] of Object.entries(initialState)) {
152-
Reflect.set(store, key, initialValue)
152+
Reflect.set(store, key, structuredClone(initialValue))
153153
commit(prevState, store.$getState())
154154
}
155155
}

0 commit comments

Comments
 (0)