current.ts
This file
Path
src/core/current.ts
40 lines · 1.1 KiB · TypeScript
Last changed by
Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
History of this fileTake it
The walk stopped after 200 commits: lines older than 33a305b point at it.
fix: Clearing empty Set&Map should be noop (#682). Fixes #680Björgvin Ragnarssonbefore adoption33a305b
lines 1–9why, one step back1import {2 die,3 isDraft,4 shallowCopy,5 each,6 DRAFT_STATE,7 set,8 ImmerState,9 isDraftable,Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 10why, one step back10 isFrozenfix: Clearing empty Set&Map should be noop (#682). Fixes #680Björgvin Ragnarssonbefore adoption33a305b
lines 11–15why, one step back11} from "../internal"1213/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */14export function current<T>(value: T): T15export function current(value: any): any {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 16why, one step back16 if (!isDraft(value)) die(10, value)fix: Clearing empty Set&Map should be noop (#682). Fixes #680Björgvin Ragnarssonbefore adoption33a305b
lines 17–20why, one step back17 return currentImpl(value)18}1920function currentImpl(value: any): any {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 21why, one step back21 if (!isDraftable(value) || isFrozen(value)) return valuefix: Clearing empty Set&Map should be noop (#682). Fixes #680Björgvin Ragnarssonbefore adoption33a305b
lines 22–24why, one step back22 const state: ImmerState | undefined = value[DRAFT_STATE]23 let copy: any24 if (state) {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 25why, one step back25 if (!state.modified_) return state.base_fix: Clearing empty Set&Map should be noop (#682). Fixes #680Björgvin Ragnarssonbefore adoption33a305b
lines 26–27why, one step back26 // Optimization: avoid generating new drafts during copying27 state.finalized_ = trueMerge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 28why, one step back28 copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)fix: Clearing empty Set&Map should be noop (#682). Fixes #680Björgvin Ragnarssonbefore adoption33a305b
line 29why, one step back29 } else {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 30why, one step back30 copy = shallowCopy(value, true)fix: Clearing empty Set&Map should be noop (#682). Fixes #680Björgvin Ragnarssonbefore adoption33a305b
line 31why, one step back31 }Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 32why, one step back32 // recursefix: Clearing empty Set&Map should be noop (#682). Fixes #680Björgvin Ragnarssonbefore adoption33a305b
lines 33–35why, one step back33 each(copy, (key, childValue) => {34 set(copy, key, currentImpl(childValue))35 })Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
lines 36–37why, one step back36 if (state) {37 state.finalized_ = falsefix: Clearing empty Set&Map should be noop (#682). Fixes #680Björgvin Ragnarssonbefore adoption33a305b
line 38why, one step back38 }Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 39why, one step back39 return copyfix: Clearing empty Set&Map should be noop (#682). Fixes #680Björgvin Ragnarssonbefore adoption33a305b
line 40why, one step back40}