Skip to content
Myr

immer.ts

This file

Path

src/immer.ts

123 lines · 3.8 KiB · TypeScript

Last changed by

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

History of this file

Take it

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

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 1–10why, one step back
1import {
2 IProduce,3 IProduceWithPatches,4 Immer,5 Draft,6 Immutable7} from "./internal"89export {10 Draft,

fix: export lost types (#1116)Jodobefore adoption5a8f6e7

line 11why, one step back
11 WritableDraft,

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 12–14why, one step back
12 Immutable,
13 Patch,14 PatchListener,

fix: export lost types (#1116)Jodobefore adoption5a8f6e7

line 15why, one step back
15 Producer,

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 16–21why, one step back
16 original,
17 current,18 isDraft,19 isDraftable,20 NOTHING as nothing,21 DRAFTABLE as immerable,

fix: export `Objectish` type (#1043)Milan Jaritzbefore adoption75e004d

line 22why, one step back
22 freeze,

feat(performance): Make non-strict mode faster for classes. Addresses #1071Michel Weststratebefore adoption53e3203

lines 23–24why, one step back
23 Objectish,
24 StrictMode

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 25–47why, one step back
25} from "./internal"
2627const immer = new Immer()2829/**30 * The `produce` function takes a value and a "recipe function" (whose31 * return value often depends on the base state). The recipe function is32 * free to mutate its first argument however it wants. All mutations are33 * only ever applied to a __copy__ of the base state.34 *35 * Pass only a function to create a "curried producer" which relieves you36 * from passing the recipe function every time.37 *38 * Only plain objects and arrays are made mutable. All other objects are39 * considered uncopyable.40 *41 * Note: This function is __bound__ to its `Immer` instance.42 *43 * @param {any} base - the initial state44 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified45 * @param {Function} patchListener - optional function that will be called with all the patches produced here46 * @returns {any} a new state, or the initial state if nothing was modified47 */

fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2

line 48why, one step back
48export const produce: IProduce = /* @__PURE__ */ immer.produce

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 49–53why, one step back
49
50/**51 * Like `produce`, but `produceWithPatches` always returns a tuple52 * [nextState, patches, inversePatches] (instead of just the next state)53 */

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 54–55why, one step back
54export const produceWithPatches: IProduceWithPatches =
55 /* @__PURE__ */ immer.produceWithPatches.bind(immer)

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 56–61why, one step back
56
57/**58 * Pass true to automatically freeze all copies created by Immer.59 *60 * Always freeze by default, even in production mode61 */

fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2

line 62why, one step back
62export const setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer)

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 63–64why, one step back
63
64/**

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

line 65why, one step back
65 * Pass true to enable strict shallow copy.

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

line 66why, one step back
66 *

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

line 67why, one step back
67 * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

line 68why, one step back
68 */

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 69–70why, one step back
69export const setUseStrictShallowCopy =
70 /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(immer)

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 71–72why, one step back
71
72/**

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

lines 73–77why, one step back
73 * Pass false to use loose iteration that only processes enumerable string properties.
74 * This skips symbols and non-enumerable properties for maximum performance.75 *76 * By default, strict iteration is enabled (includes all own properties).77 */

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

lines 78–79why, one step back
78export const setUseStrictIteration =
79 /* @__PURE__ */ immer.setUseStrictIteration.bind(immer)

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

lines 80–81why, one step back
80
81/**

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 82–85why, one step back
82 * Apply an array of Immer patches to the first argument.
83 *84 * This function is a producer, which means copy-on-write is in effect.85 */

fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2

line 86why, one step back
86export const applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer)

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 87–91why, one step back
87
88/**89 * Create an Immer draft from the given base state, which may be a draft itself.90 * The draft can be modified until you finalize it with the `finishDraft` function.91 */

fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2

line 92why, one step back
92export const createDraft = /* @__PURE__ */ immer.createDraft.bind(immer)

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 93–101why, one step back
93
94/**95 * Finalize an Immer draft from a `createDraft` call, returning the base state96 * (if no changes were made) or a modified copy. The draft must *not* be97 * mutated afterwards.98 *99 * Pass a function as the 2nd argument to generate Immer patches based on the100 * changes that were made.101 */

fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2

line 102why, one step back
102export const finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer)

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 103–109why, one step back
103
104/**105 * This function is actually a no-op, but can be used to cast an immutable type106 * to an draft type and make TypeScript happy107 *108 * @param value109 */

perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202

line 110why, one step back
110export let castDraft = <T>(value: T): Draft<T> => value as any

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 111–116why, one step back
111
112/**113 * This function is actually a no-op, but can be used to cast a mutable type114 * to an immutable type and make TypeScript happy115 * @param value116 */

perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202

line 117why, one step back
117export let castImmutable = <T>(value: T): Immutable<T> => value as any

chore: Fix typo (#954)Marc Barbeaubefore adoptionba24aab

lines 118–122why, one step back
118
119export {Immer}120121export {enablePatches} from "./plugins/patches"122export {enableMapSet} from "./plugins/mapset"

feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0

line 123why, one step back
123export {enableArrayMethods} from "./plugins/arrayMethods"