Skip to content
Myr

immer.ts

This file

Path

src/immer.ts

126 lines · 3.8 KiB · TypeScript

Last changed by

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

History of this file

Take it

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

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,

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

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,

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

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 */

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

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

lines 55–62why, one step back
55 immer
56)5758/**59 * Pass true to automatically freeze all copies created by Immer.60 *61 * Always freeze by default, even in production mode62 */

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

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

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

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

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

line 67why, one step back
67 *

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

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

line 69why, one step back
69 */

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

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

lines 73–74why, one step back
73
74/**

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

lines 75–84why, one step back
75 * Pass false to use loose iteration that only processes enumerable string properties.
76 * This skips symbols and non-enumerable properties for maximum performance.77 *78 * By default, strict iteration is enabled (includes all own properties).79 */80export const setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind(81 immer82)8384/**

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

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

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

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

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

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

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

lines 96–104why, one step back
96
97/**98 * Finalize an Immer draft from a `createDraft` call, returning the base state99 * (if no changes were made) or a modified copy. The draft must *not* be100 * mutated afterwards.101 *102 * Pass a function as the 2nd argument to generate Immer patches based on the103 * changes that were made.104 */

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

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

lines 106–112why, one step back
106
107/**108 * This function is actually a no-op, but can be used to cast an immutable type109 * to an draft type and make TypeScript happy110 *111 * @param value112 */

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

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

lines 114–119why, one step back
114
115/**116 * This function is actually a no-op, but can be used to cast a mutable type117 * to an immutable type and make TypeScript happy118 * @param value119 */

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

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

docs: fixing link to RFC-6902 & fixing typo (#830)Connor Burtonbefore adoption648d39b

lines 121–125why, one step back
121
122export {Immer}123124export {enablePatches} from "./plugins/patches"125export {enableMapSet} from "./plugins/mapset"

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

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