immer.ts
This file
Path
src/immer.ts
117 lines · 3.4 KiB · TypeScript
Last changed by
chore(comments): update comments (#727)郗银before adoptionfe8f589
History of this fileTake it
The walk stopped after 200 commits: lines older than ef8990b point at it.
chore: verify build during testMichel Weststratebefore adoptionef8990b
lines 1–2why, one step back1import {2 IProduce,Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 3–4why, one step back3 IProduceWithPatches,4 Immer,chore: verify build during testMichel Weststratebefore adoptionef8990b
line 5why, one step back5 Draft,Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 6–12why, one step back6 Immutable7} from "./internal"89export {10 Draft,11 Immutable,12 Patch,chore: verify build during testMichel Weststratebefore adoptionef8990b
line 13why, one step back13 PatchListener,Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
line 14why, one step back14 original,Immer 7Michel Weststratebefore adoption467ea5d
line 15why, one step back15 current,chore: verify build during testMichel Weststratebefore adoptionef8990b
line 16why, one step back16 isDraft,Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 17–18why, one step back17 isDraftable,18 NOTHING as nothing,feature: Always freeze by default (#702)Michel Weststratebefore adoptiona406c8f
lines 19–20why, one step back19 DRAFTABLE as immerable,20 freezechore: verify build during testMichel Weststratebefore adoptionef8990b
lines 21–22why, one step back21} from "./internal"22Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
line 23why, one step back23const immer = new Immer()chore: verify build during testMichel Weststratebefore adoptionef8990b
line 24why, one step back24Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 25–45why, one step back25/**26 * The `produce` function takes a value and a "recipe function" (whose27 * return value often depends on the base state). The recipe function is28 * free to mutate its first argument however it wants. All mutations are29 * only ever applied to a __copy__ of the base state.30 *31 * Pass only a function to create a "curried producer" which relieves you32 * from passing the recipe function every time.33 *34 * Only plain objects and arrays are made mutable. All other objects are35 * considered uncopyable.36 *37 * Note: This function is __bound__ to its `Immer` instance.38 *39 * @param {any} base - the initial state40 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified41 * @param {Function} patchListener - optional function that will be called with all the patches produced here42 * @returns {any} a new state, or the initial state if nothing was modified43 */44export const produce: IProduce = immer.produce45export default producechore: verify build during testMichel Weststratebefore adoptionef8990b
line 46why, one step back46Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 47–53why, one step back47/**48 * Like `produce`, but `produceWithPatches` always returns a tuple49 * [nextState, patches, inversePatches] (instead of just the next state)50 */51export const produceWithPatches: IProduceWithPatches = immer.produceWithPatches.bind(52 immer53)chore: verify build during testMichel Weststratebefore adoptionef8990b
line 54why, one step back54Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 55–57why, one step back55/**56 * Pass true to automatically freeze all copies created by Immer.57 *chore(comments): update comments (#727)郗银before adoptionfe8f589
line 58why, one step back58 * Always freeze by default, even in production modeMerge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 59–60why, one step back59 */60export const setAutoFreeze = immer.setAutoFreeze.bind(immer)chore: verify build during testMichel Weststratebefore adoptionef8990b
line 61why, one step back61Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 62–68why, one step back62/**63 * Pass true to use the ES2015 `Proxy` class when creating drafts, which is64 * always faster than using ES5 proxies.65 *66 * By default, feature detection is used, so calling this is rarely necessary.67 */68export const setUseProxies = immer.setUseProxies.bind(immer)chore: verify build during testMichel Weststratebefore adoptionef8990b
line 69why, one step back69Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 70–75why, one step back70/**71 * Apply an array of Immer patches to the first argument.72 *73 * This function is a producer, which means copy-on-write is in effect.74 */75export const applyPatches = immer.applyPatches.bind(immer)chore: verify build during testMichel Weststratebefore adoptionef8990b
line 76why, one step back76Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 77–81why, one step back77/**78 * Create an Immer draft from the given base state, which may be a draft itself.79 * The draft can be modified until you finalize it with the `finishDraft` function.80 */81export const createDraft = immer.createDraft.bind(immer)chore: verify build during testMichel Weststratebefore adoptionef8990b
line 82why, one step back82Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 83–91why, one step back83/**84 * Finalize an Immer draft from a `createDraft` call, returning the base state85 * (if no changes were made) or a modified copy. The draft must *not* be86 * mutated afterwards.87 *88 * Pass a function as the 2nd argument to generate Immer patches based on the89 * changes that were made.90 */91export const finishDraft = immer.finishDraft.bind(immer)chore: verify build during testMichel Weststratebefore adoptionef8990b
line 92why, one step back92Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 93–101why, one step back93/**94 * This function is actually a no-op, but can be used to cast an immutable type95 * to an draft type and make TypeScript happy96 *97 * @param value98 */99export function castDraft<T>(value: T): Draft<T> {100 return value as any101}chore: verify build during testMichel Weststratebefore adoptionef8990b
line 102why, one step back102Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 103–110why, one step back103/**104 * This function is actually a no-op, but can be used to cast a mutable type105 * to an immutable type and make TypeScript happy106 * @param value107 */108export function castImmutable<T>(value: T): Immutable<T> {109 return value as any110}chore: verify build during testMichel Weststratebefore adoptionef8990b
line 111why, one step back111Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
line 112why, one step back112export {Immer}chore: verify build during testMichel Weststratebefore adoptionef8990b
line 113why, one step back113Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 114–117why, one step back114export {enableES5} from "./plugins/es5"115export {enablePatches} from "./plugins/patches"116export {enableMapSet} from "./plugins/mapset"117export {enableAllPlugins} from "./plugins/all"