Skip to content
Myr

Fix existing copy usage check in getValue

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

authored by Mark Erikson · committed by Mark Erikson · parent 0c3efdd · Browse files · 1 file+11 added−7 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+11 added−7 removed

  • other:+11 added−7 removed

1 file+11 added−7 removed

modified:src/utils/common.ts+11 added-7 removed
103 unmodified lines
104 const state: undefined | ImmerState = thing[DRAFT_STATE]105 return state106 ? state.type_107 : isArray(thing)108 ? ArchType.Array109 : isMap(thing)110 ? ArchType.Map111 : isSet(thing)112 ? ArchType.Set113 : ArchType.Object108 ? ArchType.Array109 : isMap(thing)110 ? ArchType.Map111 : isSet(thing)112 ? ArchType.Set113 : ArchType.Object114}115116/*#__PURE__*/117export let has = (
67 unmodified lines
185export let latest = (state: ImmerState): any => state.copy_ || state.base_186187export let getValue = <T extends object>(value: T): T => {188 const proxyDraft = getProxyDraft(value)189 return proxyDraft ? (proxyDraft.copy_ ?? proxyDraft.base_) : value189 // Use the copy only if the draft was actually modified. An unmodified190 // draft can still have a copy_ (e.g. the get trap caches child drafts191 // there), and using it would both break structural sharing and leak192 // soon-to-be-revoked child drafts into the result.193 return proxyDraft ? getFinalValue(proxyDraft) : value194}195196export let getFinalValue = (state: ImmerState): any =>197 state.modified_ ? state.copy_ : state.base_
93 unmodified lines