Skip to content
Myr

introduce StrictMode enum

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

authored by Michel Weststrate · committed by Michel Weststrate · parent 85a8f7b · Browse files · 4 files+13 added−8 removed
This commit

State

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

Diff stats

4 files+13 added−8 removed

  • tests:+3 added−2 removed
  • other:+10 added−6 removed

4 files+13 added−8 removed

modified:__tests__/not-strict-copy.ts+3 added-2 removed
modified:src/core/immerClass.ts+5 added-3 removed
29 unmodified lines
30 produce: IProduce31 produceWithPatches: IProduceWithPatches32}3334export type StrictMode = boolean | "class_only";3536export class Immer implements ProducersFns {37 autoFreeze_: boolean = true36 useStrictShallowCopy_: boolean | "class_only" = false38 useStrictShallowCopy_: StrictMode = false3940 constructor(config?: {41 autoFreeze?: boolean40 useStrictShallowCopy?: boolean | "class_only"42 useStrictShallowCopy?: StrictMode43 }) {44 if (typeof config?.autoFreeze === "boolean")45 this.setAutoFreeze(config!.autoFreeze)46 if (typeof config?.useStrictShallowCopy === "boolean")
120 unmodified lines
167 * Pass true to enable strict shallow copy.168 *169 * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.170 */169 setUseStrictShallowCopy(value: boolean | "class_only") {171 setUseStrictShallowCopy(value: StrictMode) {172 this.useStrictShallowCopy_ = value173 }174175 applyPatches<T extends Objectish>(base: T, patches: Patch[]): T {
43 unmodified lines
modified:src/utils/common.ts+3 added-2 removed
6 unmodified lines
7 AnyMap,8 AnySet,9 ImmerState,10 ArchType,11 die11 die,12 StrictMode13} from "../internal"1415export const getPrototypeOf = Object.getPrototypeOf16
123 unmodified lines
140 return state.copy_ || state.base_141}142143/*#__PURE__*/143export function shallowCopy(base: any, strict: boolean | "class_only") {144export function shallowCopy(base: any, strict: StrictMode) {145 if (isMap(base)) {146 return new Map(base)147 }148 if (isSet(base)) {
69 unmodified lines
modified:src/immer.ts+2 added-1 removed