La referencia de la API está disponible solo en inglés por ahora.

freezeState

function
utils/immutability.ts:52
signature
freezeState<T>(obj, seen): DeepReadonly<T>

Deep-freezes a value **in place** and returns it as `DeepReadonly<T>`.

Type parameters

NameTypeDescription
TThe input value type to freeze.

Parameters

NameTypeDescription
objTAny value; objects and arrays are frozen recursively.
NameTypeDescription
seenWeakSet<object>(Advanced) A WeakSet used to track visited objects for cycle/alias safety.

Returns

DeepReadonly<T>The **same** reference as obj, but frozen and typed as DeepReadonly<T>.

Example

example
const state = { user: { name: 'Ada' }, items: [1, { id: 1 }] };
const frozen = freezeState(state);

Object.isFrozen(frozen);                 // true
Object.isFrozen(frozen.user);            // true
Object.isFrozen(frozen.items);           // true
Object.isFrozen(frozen.items[1]);        // true

Example

example
const a: any = {};
a.self = a;              // cycle
freezeState(a);          // does not recurse infinitely

Example

example
const o = Object.freeze({ x: 1 });
const out = freezeState(o);
out === o;               // true