MCPcopy Index your code
hub / github.com/immerjs/immer / currentImpl

Function currentImpl

src/core/current.ts:21–47  ·  view source on GitHub ↗
(value: any)

Source from the content-addressed store, hash-verified

19}
20
21function currentImpl(value: any): any {
22 if (!isDraftable(value) || isFrozen(value)) return value
23 const state: ImmerState | undefined = value[DRAFT_STATE]
24 let copy: any
25 let strict = true // Default to strict for compatibility
26 if (state) {
27 if (!state.modified_) return state.base_
28 // Optimization: avoid generating new drafts during copying
29 state.finalized_ = true
30 copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)
31 strict = state.scope_.immer_.shouldUseStrictIteration()
32 } else {
33 copy = shallowCopy(value, true)
34 }
35 // recurse
36 each(
37 copy,
38 (key, childValue) => {
39 set(copy, key, currentImpl(childValue))
40 },
41 strict
42 )
43 if (state) {
44 state.finalized_ = false
45 }
46 return copy
47}

Callers 1

currentFunction · 0.85

Calls 6

isDraftableFunction · 0.85
isFrozenFunction · 0.85
shallowCopyFunction · 0.85
eachFunction · 0.85
setFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…