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 fileTake it
The walk stopped after 200 commits: lines older than 26355d7 point at it.
chore: typo (#857)Kim Chanbefore adoption26355d7
lines 1–10why, one step back1import {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 back11 WritableDraft,chore: typo (#857)Kim Chanbefore adoption26355d7
lines 12–14why, one step back12 Immutable,13 Patch,14 PatchListener,fix: export lost types (#1116)Jodobefore adoption5a8f6e7
line 15why, one step back15 Producer,chore: typo (#857)Kim Chanbefore adoption26355d7
lines 16–21why, one step back16 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 back22 freeze,feat(performance): Make non-strict mode faster for classes. Addresses #1071Michel Weststratebefore adoption53e3203
lines 23–24why, one step back23 Objectish,24 StrictModechore: typo (#857)Kim Chanbefore adoption26355d7
lines 25–47why, one step back25} 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 back48export const produce: IProduce = /* @__PURE__ */ immer.producechore: typo (#857)Kim Chanbefore adoption26355d7
lines 49–53why, one step back4950/**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 back54export const produceWithPatches: IProduceWithPatches =55 /* @__PURE__ */ immer.produceWithPatches.bind(immer)chore: typo (#857)Kim Chanbefore adoption26355d7
lines 56–61why, one step back5657/**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 back62export const setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer)chore: typo (#857)Kim Chanbefore adoption26355d7
lines 63–64why, one step back6364/**Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 65why, one step back65 * Pass true to enable strict shallow copy.chore: typo (#857)Kim Chanbefore adoption26355d7
line 66why, one step back66 *Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 67why, one step back67 * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.chore: typo (#857)Kim Chanbefore adoption26355d7
line 68why, one step back68 */chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f
lines 69–70why, one step back69export const setUseStrictShallowCopy =70 /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(immer)chore: typo (#857)Kim Chanbefore adoption26355d7
lines 71–72why, one step back7172/**feat: Optimize Immer performance where possible, introduce `setUseStrictIteration` (#1164)Mark Eriksonbefore adoptione1996ce
lines 73–77why, one step back73 * 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 back78export 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 back8081/**chore: typo (#857)Kim Chanbefore adoption26355d7
lines 82–85why, one step back82 * 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 back86export const applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer)chore: typo (#857)Kim Chanbefore adoption26355d7
lines 87–91why, one step back8788/**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 back92export const createDraft = /* @__PURE__ */ immer.createDraft.bind(immer)chore: typo (#857)Kim Chanbefore adoption26355d7
lines 93–101why, one step back9394/**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 back102export const finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer)chore: typo (#857)Kim Chanbefore adoption26355d7
lines 103–109why, one step back103104/**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 back110export let castDraft = <T>(value: T): Draft<T> => value as anychore: typo (#857)Kim Chanbefore adoption26355d7
lines 111–116why, one step back111112/**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 back117export let castImmutable = <T>(value: T): Immutable<T> => value as anychore: typo (#857)Kim Chanbefore adoption26355d7
lines 118–122why, one step back118119export {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 back123export {enableArrayMethods} from "./plugins/arrayMethods"