source: frontend/node_modules/immer/src/immer.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[9af201e]1import {
2 IProduce,
3 IProduceWithPatches,
4 Immer,
5 Draft,
6 Immutable
7} from "./internal"
8
9export {
10 Draft,
11 Immutable,
12 Patch,
13 PatchListener,
14 original,
15 current,
16 isDraft,
17 isDraftable,
18 NOTHING as nothing,
19 DRAFTABLE as immerable,
20 freeze
21} from "./internal"
22
23const immer = new Immer()
24
25/**
26 * The `produce` function takes a value and a "recipe function" (whose
27 * return value often depends on the base state). The recipe function is
28 * free to mutate its first argument however it wants. All mutations are
29 * only ever applied to a __copy__ of the base state.
30 *
31 * Pass only a function to create a "curried producer" which relieves you
32 * from passing the recipe function every time.
33 *
34 * Only plain objects and arrays are made mutable. All other objects are
35 * considered uncopyable.
36 *
37 * Note: This function is __bound__ to its `Immer` instance.
38 *
39 * @param {any} base - the initial state
40 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified
41 * @param {Function} patchListener - optional function that will be called with all the patches produced here
42 * @returns {any} a new state, or the initial state if nothing was modified
43 */
44export const produce: IProduce = immer.produce
45export default produce
46
47/**
48 * Like `produce`, but `produceWithPatches` always returns a tuple
49 * [nextState, patches, inversePatches] (instead of just the next state)
50 */
51export const produceWithPatches: IProduceWithPatches = immer.produceWithPatches.bind(
52 immer
53)
54
55/**
56 * Pass true to automatically freeze all copies created by Immer.
57 *
58 * Always freeze by default, even in production mode
59 */
60export const setAutoFreeze = immer.setAutoFreeze.bind(immer)
61
62/**
63 * Pass true to use the ES2015 `Proxy` class when creating drafts, which is
64 * 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)
69
70/**
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)
76
77/**
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)
82
83/**
84 * Finalize an Immer draft from a `createDraft` call, returning the base state
85 * (if no changes were made) or a modified copy. The draft must *not* be
86 * mutated afterwards.
87 *
88 * Pass a function as the 2nd argument to generate Immer patches based on the
89 * changes that were made.
90 */
91export const finishDraft = immer.finishDraft.bind(immer)
92
93/**
94 * This function is actually a no-op, but can be used to cast an immutable type
95 * to an draft type and make TypeScript happy
96 *
97 * @param value
98 */
99export function castDraft<T>(value: T): Draft<T> {
100 return value as any
101}
102
103/**
104 * This function is actually a no-op, but can be used to cast a mutable type
105 * to an immutable type and make TypeScript happy
106 * @param value
107 */
108export function castImmutable<T>(value: T): Immutable<T> {
109 return value as any
110}
111
112export {Immer}
113
114export {enableES5} from "./plugins/es5"
115export {enablePatches} from "./plugins/patches"
116export {enableMapSet} from "./plugins/mapset"
117export {enableAllPlugins} from "./plugins/all"
Note: See TracBrowser for help on using the repository browser.