immer.ts
This file
Path
src/immer.ts
119 lines · 3.4 KiB · TypeScript
Last changed by
fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2
History of this fileTake it
The walk stopped after 200 commits: lines older than bc35916 point at it.
chore: fix links, fixes #779Michel Weststratebefore adoptionbc35916
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: fix links, fixes #779Michel Weststratebefore adoptionbc35916
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: fix links, fixes #779Michel Weststratebefore adoptionbc35916
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: fix links, fixes #779Michel Weststratebefore adoptionbc35916
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: fix links, fixes #779Michel Weststratebefore adoptionbc35916
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 */fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2
line 54why, one step back54export const produceWithPatches: IProduceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(chore: fix links, fixes #779Michel Weststratebefore adoptionbc35916
lines 55–62why, one step back55 immer56)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 back63export const setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer)chore: fix links, fixes #779Michel Weststratebefore adoptionbc35916
lines 64–65why, one step back6465/**Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 66why, one step back66 * Pass true to enable strict shallow copy.chore: fix links, fixes #779Michel Weststratebefore adoptionbc35916
line 67why, one step back67 *Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 68why, one step back68 * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.chore: fix links, fixes #779Michel Weststratebefore adoptionbc35916
line 69why, one step back69 */fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2
lines 70–72why, one step back70export const setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(71 immer72)chore: fix links, fixes #779Michel Weststratebefore adoptionbc35916
lines 73–78why, one step back7374/**75 * Apply an array of Immer patches to the first argument.76 *77 * This function is a producer, which means copy-on-write is in effect.78 */fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2
line 79why, one step back79export const applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer)chore: fix links, fixes #779Michel Weststratebefore adoptionbc35916
lines 80–84why, one step back8081/**82 * Create an Immer draft from the given base state, which may be a draft itself.83 * The draft can be modified until you finalize it with the `finishDraft` function.84 */fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2
line 85why, one step back85export const createDraft = /* @__PURE__ */ immer.createDraft.bind(immer)chore: fix links, fixes #779Michel Weststratebefore adoptionbc35916
lines 86–94why, one step back8687/**88 * Finalize an Immer draft from a `createDraft` call, returning the base state89 * (if no changes were made) or a modified copy. The draft must *not* be90 * mutated afterwards.91 *92 * Pass a function as the 2nd argument to generate Immer patches based on the93 * changes that were made.94 */fix: Mark exports as pure, for better tree-shakability (#1124)Steven Luscherbefore adoption85faaa2
line 95why, one step back95export const finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer)chore: fix links, fixes #779Michel Weststratebefore adoptionbc35916
lines 96–119why, one step back9697/**98 * This function is actually a no-op, but can be used to cast an immutable type99 * to an draft type and make TypeScript happy100 *101 * @param value102 */103export function castDraft<T>(value: T): Draft<T> {104 return value as any105}106107/**108 * This function is actually a no-op, but can be used to cast a mutable type109 * to an immutable type and make TypeScript happy110 * @param value111 */112export function castImmutable<T>(value: T): Immutable<T> {113 return value as any114}115116export {Immer}117118export {enablePatches} from "./plugins/patches"119export {enableMapSet} from "./plugins/mapset"