| 1 | import { IProduceWithPatches, IProduce, ImmerState, Drafted, Patch, Objectish, Draft, PatchListener } from "../internal";
|
|---|
| 2 | interface ProducersFns {
|
|---|
| 3 | produce: IProduce;
|
|---|
| 4 | produceWithPatches: IProduceWithPatches;
|
|---|
| 5 | }
|
|---|
| 6 | export declare class Immer implements ProducersFns {
|
|---|
| 7 | useProxies_: boolean;
|
|---|
| 8 | autoFreeze_: boolean;
|
|---|
| 9 | constructor(config?: {
|
|---|
| 10 | useProxies?: boolean;
|
|---|
| 11 | autoFreeze?: boolean;
|
|---|
| 12 | });
|
|---|
| 13 | /**
|
|---|
| 14 | * The `produce` function takes a value and a "recipe function" (whose
|
|---|
| 15 | * return value often depends on the base state). The recipe function is
|
|---|
| 16 | * free to mutate its first argument however it wants. All mutations are
|
|---|
| 17 | * only ever applied to a __copy__ of the base state.
|
|---|
| 18 | *
|
|---|
| 19 | * Pass only a function to create a "curried producer" which relieves you
|
|---|
| 20 | * from passing the recipe function every time.
|
|---|
| 21 | *
|
|---|
| 22 | * Only plain objects and arrays are made mutable. All other objects are
|
|---|
| 23 | * considered uncopyable.
|
|---|
| 24 | *
|
|---|
| 25 | * Note: This function is __bound__ to its `Immer` instance.
|
|---|
| 26 | *
|
|---|
| 27 | * @param {any} base - the initial state
|
|---|
| 28 | * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
|
|---|
| 29 | * @param {Function} patchListener - optional function that will be called with all the patches produced here
|
|---|
| 30 | * @returns {any} a new state, or the initial state if nothing was modified
|
|---|
| 31 | */
|
|---|
| 32 | produce: IProduce;
|
|---|
| 33 | produceWithPatches: IProduceWithPatches;
|
|---|
| 34 | createDraft<T extends Objectish>(base: T): Draft<T>;
|
|---|
| 35 | finishDraft<D extends Draft<any>>(draft: D, patchListener?: PatchListener): D extends Draft<infer T> ? T : never;
|
|---|
| 36 | /**
|
|---|
| 37 | * Pass true to automatically freeze all copies created by Immer.
|
|---|
| 38 | *
|
|---|
| 39 | * By default, auto-freezing is enabled.
|
|---|
| 40 | */
|
|---|
| 41 | setAutoFreeze(value: boolean): void;
|
|---|
| 42 | /**
|
|---|
| 43 | * Pass true to use the ES2015 `Proxy` class when creating drafts, which is
|
|---|
| 44 | * always faster than using ES5 proxies.
|
|---|
| 45 | *
|
|---|
| 46 | * By default, feature detection is used, so calling this is rarely necessary.
|
|---|
| 47 | */
|
|---|
| 48 | setUseProxies(value: boolean): void;
|
|---|
| 49 | applyPatches<T extends Objectish>(base: T, patches: Patch[]): T;
|
|---|
| 50 | }
|
|---|
| 51 | export declare function createProxy<T extends Objectish>(immer: Immer, value: T, parent?: ImmerState): Drafted<T, ImmerState>;
|
|---|
| 52 | export {};
|
|---|
| 53 | //# sourceMappingURL=immerClass.d.ts.map |
|---|