Skip to content
Myr

current.ts

This file

Path

src/core/current.ts

47 lines · 1.2 KiB · TypeScript

Last changed by

fix: update current and original typings to assert draft value is unwrapped (#1236)Dean Kerrbefore adoptionbf2d154

History of this file

Take it

The walk stopped after 200 commits: lines older than 8571fe0 point at it.

docs: Update performance.mdx (#942)anabefore adoption8571fe0

lines 1–2why, one step back
1import {
2 die,

fix: update current and original typings to assert draft value is unwrapped (#1236)Dean Kerrbefore adoptionbf2d154

line 3why, one step back
3 Draft,

docs: Update performance.mdx (#942)anabefore adoption8571fe0

lines 4–10why, one step back
4 isDraft,
5 shallowCopy,6 each,7 DRAFT_STATE,8 set,9 ImmerState,10 isDraftable,

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 11why, one step back
11 isFrozen

docs: Update performance.mdx (#942)anabefore adoption8571fe0

lines 12–14why, one step back
12} from "../internal"
1314/** 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. */

fix: update current and original typings to assert draft value is unwrapped (#1236)Dean Kerrbefore adoptionbf2d154

lines 15–16why, one step back
15export function current<T>(value: Draft<T>): T
16export function current(value: Draft<any>): any {

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 17why, one step back
17 if (!isDraft(value)) die(10, value)

docs: Update performance.mdx (#942)anabefore adoption8571fe0

lines 18–21why, one step back
18 return currentImpl(value)
19}2021function currentImpl(value: any): any {

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 22why, one step back
22 if (!isDraftable(value) || isFrozen(value)) return value

docs: Update performance.mdx (#942)anabefore adoption8571fe0

lines 23–24why, one step back
23 const state: ImmerState | undefined = value[DRAFT_STATE]
24 let copy: any

feat: Optimize Immer performance where possible, introduce `setUseStrictIteration` (#1164)Mark Eriksonbefore adoptione1996ce

line 25why, one step back
25 let strict = true // Default to strict for compatibility

docs: Update performance.mdx (#942)anabefore adoption8571fe0

line 26why, one step back
26 if (state) {

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 27why, one step back
27 if (!state.modified_) return state.base_

docs: Update performance.mdx (#942)anabefore adoption8571fe0

lines 28–29why, one step back
28 // Optimization: avoid generating new drafts during copying
29 state.finalized_ = true

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 30why, one step back
30 copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)

feat: Optimize Immer performance where possible, introduce `setUseStrictIteration` (#1164)Mark Eriksonbefore adoptione1996ce

line 31why, one step back
31 strict = state.scope_.immer_.shouldUseStrictIteration()

docs: Update performance.mdx (#942)anabefore adoption8571fe0

line 32why, one step back
32 } else {

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 33why, one step back
33 copy = shallowCopy(value, true)

docs: Update performance.mdx (#942)anabefore adoption8571fe0

line 34why, one step back
34 }

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 35why, one step back
35 // recurse

feat: Optimize Immer performance where possible, introduce `setUseStrictIteration` (#1164)Mark Eriksonbefore adoptione1996ce

lines 36–42why, one step back
36 each(
37 copy,38 (key, childValue) => {39 set(copy, key, currentImpl(childValue))40 },41 strict42 )

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

lines 43–44why, one step back
43 if (state) {
44 state.finalized_ = false

docs: Update performance.mdx (#942)anabefore adoption8571fe0

line 45why, one step back
45 }

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 46why, one step back
46 return copy

docs: Update performance.mdx (#942)anabefore adoption8571fe0

line 47why, one step back
47}