Skip to content
Myr

fix: #768 `immerable` field being lost during patch value cloning (#771)

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

authored by Michel Weststrate · committed by GitHub · parent 2c2f30e · Browse files · 4 files+61 added−6 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+61 added−6 removed

  • tests:+56 added−3 removed
  • other:+5 added−3 removed

4 files+61 added−6 removed

modified:__tests__/empty.ts+54 added-2 removed
modified:__tests__/tsconfig.json+2 added-1 removed
modified:src/core/immerClass.ts+3 added-3 removed
183 unmodified lines
184 }185 this.useProxies_ = value186 }187188 applyPatches(base: Objectish, patches: Patch[]) {188 applyPatches<T extends Objectish>(base: Objectish, patches: Patch[]): T {189 // If a patch replaces the entire state, take that replacement as base190 // before applying patches191 let i: number192 for (i = patches.length - 1; i >= 0; i--) {
6 unmodified lines
199200 const applyPatchesImpl = getPlugin("Patches").applyPatches_201 if (isDraft(base)) {202 // N.B: never hits if some patch a replacement, patches are never drafts203 return applyPatchesImpl(base, patches)203 return applyPatchesImpl(base, patches) as any204 }205 // Otherwise, produce a copy of the base state.206 return this.produce(base, (draft: Drafted) =>207 applyPatchesImpl(draft, patches.slice(i + 1))208 )208 ) as any209 }210}211212export function createProxy<T extends Objectish>(
17 unmodified lines
modified:src/plugins/patches.ts+2 added
1import {immerable} from "../immer"2import {3 ImmerState,4 Patch,5 SetState,
281 unmodified lines
287 )288 if (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue))289 const cloned = Object.create(Object.getPrototypeOf(obj))290 for (const key in obj) cloned[key] = deepClonePatchValue(obj[key])291 if (has(obj, immerable)) cloned[immerable] = obj[immerable]292 return cloned293 }294295 function clonePatchValueIfNeeded<T>(obj: T): T {
11 unmodified lines