@mocanvas/store · function

devFreeze

declare function devFreeze<T>(object: T): T

Deep-freeze object in development builds, and hand it straight back in production.

Records in the store are shared by reference with every consumer that read them, so mutating one in place skips the whole change pipeline: no diff, no side effects, no listeners, and an undo that silently does nothing. Freezing turns that from a bug someone finds a week later into a TypeError on the line that did it. The check is skipped in production because freezing every record on every write is not free.

Already-frozen objects are left alone, so re-freezing a record that came out of the store costs one property read.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.