immerClass.d.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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} producer - 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(base: any, recipe?: any, patchListener?: any): any;
  33. produceWithPatches(arg1: any, arg2?: any, arg3?: any): any;
  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(base: Objectish, patches: Patch[]): any;
  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