Skip to content
Myr

fix: non-enumerable (immutable) methods on Map/Set (#1069)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

when an immer object includes a Map/Set, the mutating methods are replaced with ones that prevent mutation outside of the procude function.   to prevent cluttering the console when inspecting the Map/Set, these methods are set to non-enumerable. this behavior also matches that of the original methods that are replaced.

authored by gimelg · committed by GitHub · parent b4f71a6 · Browse files · 1 file+6 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−1 removed

  • other:+6 added−1 removed

1 file+6 added−1 removed

modified:src/utils/common.ts+6 added-1 removed
196 unmodified lines
197export function freeze<T>(obj: T, deep?: boolean): T198export function freeze<T>(obj: any, deep: boolean = false): T {199 if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj200 if (getArchtype(obj) > 1 /* Map or Set */) {201 obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections as any201 Object.defineProperties(obj, {202 set: {value: dontMutateFrozenCollections as any},203 add: {value: dontMutateFrozenCollections as any},204 clear: {value: dontMutateFrozenCollections as any},205 delete: {value: dontMutateFrozenCollections as any}206 })207 }208 Object.freeze(obj)209 if (deep)210 // See #590, don't recurse into non-enumerable / Symbol properties when freezing
12 unmodified lines