immer.d.ts 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { IProduce, IProduceWithPatches, Immer, Draft, Immutable } from "./internal";
  2. export { Draft, Immutable, Patch, PatchListener, original, current, isDraft, isDraftable, NOTHING as nothing, DRAFTABLE as immerable, freeze } from "./internal";
  3. /**
  4. * The `produce` function takes a value and a "recipe function" (whose
  5. * return value often depends on the base state). The recipe function is
  6. * free to mutate its first argument however it wants. All mutations are
  7. * only ever applied to a __copy__ of the base state.
  8. *
  9. * Pass only a function to create a "curried producer" which relieves you
  10. * from passing the recipe function every time.
  11. *
  12. * Only plain objects and arrays are made mutable. All other objects are
  13. * considered uncopyable.
  14. *
  15. * Note: This function is __bound__ to its `Immer` instance.
  16. *
  17. * @param {any} base - the initial state
  18. * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified
  19. * @param {Function} patchListener - optional function that will be called with all the patches produced here
  20. * @returns {any} a new state, or the initial state if nothing was modified
  21. */
  22. export declare const produce: IProduce;
  23. export default produce;
  24. /**
  25. * Like `produce`, but `produceWithPatches` always returns a tuple
  26. * [nextState, patches, inversePatches] (instead of just the next state)
  27. */
  28. export declare const produceWithPatches: IProduceWithPatches;
  29. /**
  30. * Pass true to automatically freeze all copies created by Immer.
  31. *
  32. * Always freeze by default, even in production mode
  33. */
  34. export declare const setAutoFreeze: (value: boolean) => void;
  35. /**
  36. * Pass true to use the ES2015 `Proxy` class when creating drafts, which is
  37. * always faster than using ES5 proxies.
  38. *
  39. * By default, feature detection is used, so calling this is rarely necessary.
  40. */
  41. export declare const setUseProxies: (value: boolean) => void;
  42. /**
  43. * Apply an array of Immer patches to the first argument.
  44. *
  45. * This function is a producer, which means copy-on-write is in effect.
  46. */
  47. export declare const applyPatches: (base: import("./internal").Objectish, patches: import("./internal").Patch[]) => any;
  48. /**
  49. * Create an Immer draft from the given base state, which may be a draft itself.
  50. * The draft can be modified until you finalize it with the `finishDraft` function.
  51. */
  52. export declare const createDraft: <T extends import("./internal").Objectish>(base: T) => Draft<T>;
  53. /**
  54. * Finalize an Immer draft from a `createDraft` call, returning the base state
  55. * (if no changes were made) or a modified copy. The draft must *not* be
  56. * mutated afterwards.
  57. *
  58. * Pass a function as the 2nd argument to generate Immer patches based on the
  59. * changes that were made.
  60. */
  61. export declare const finishDraft: <D extends any>(draft: D, patchListener?: import("./internal").PatchListener | undefined) => D extends Draft<infer T> ? T : never;
  62. /**
  63. * This function is actually a no-op, but can be used to cast an immutable type
  64. * to an draft type and make TypeScript happy
  65. *
  66. * @param value
  67. */
  68. export declare function castDraft<T>(value: T): Draft<T>;
  69. /**
  70. * This function is actually a no-op, but can be used to cast a mutable type
  71. * to an immutable type and make TypeScript happy
  72. * @param value
  73. */
  74. export declare function castImmutable<T>(value: T): Immutable<T>;
  75. export { Immer };
  76. export { enableES5 } from "./plugins/es5";
  77. export { enablePatches } from "./plugins/patches";
  78. export { enableMapSet } from "./plugins/mapset";
  79. export { enableAllPlugins } from "./plugins/all";
  80. //# sourceMappingURL=immer.d.ts.map