We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5f42e12 commit e0289afCopy full SHA for e0289af
src/vanilla/utils/freezeAtom.ts
@@ -2,15 +2,16 @@ import type { Atom, WritableAtom } from '../../vanilla.ts'
2
3
const frozenAtoms = new WeakSet<Atom<any>>()
4
5
-const deepFreeze = (obj: unknown) => {
6
- if (typeof obj !== 'object' || obj === null) return
7
- Object.freeze(obj)
8
- const propNames = Object.getOwnPropertyNames(obj)
+const deepFreeze = <T>(value: T): T => {
+ if (typeof value !== 'object' || value === null) {
+ return value
+ }
9
+ Object.freeze(value)
10
+ const propNames = Object.getOwnPropertyNames(value)
11
for (const name of propNames) {
- const value = (obj as never)[name]
- deepFreeze(value)
12
+ deepFreeze((value as never)[name])
13
}
- return obj
14
15
16
17
export function freezeAtom<AtomType extends Atom<unknown>>(
0 commit comments