plugins.d.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { ImmerState, Patch, ImmerScope, Drafted, AnyObject, ImmerBaseState, AnyMap, AnySet, ProxyTypeES5Array, ProxyTypeES5Object, ProxyTypeMap, ProxyTypeSet } from "../internal";
  2. /** Plugin utilities */
  3. declare const plugins: {
  4. Patches?: {
  5. generatePatches_(state: ImmerState, basePath: PatchPath, patches: Patch[], inversePatches: Patch[]): void;
  6. generateReplacementPatches_(rootState: ImmerState, replacement: any, patches: Patch[], inversePatches: Patch[]): void;
  7. applyPatches_<T>(draft: T, patches: Patch[]): T;
  8. };
  9. ES5?: {
  10. willFinalizeES5_(scope: ImmerScope, result: any, isReplaced: boolean): void;
  11. createES5Proxy_<T>(base: T, parent?: ImmerState): Drafted<T, ES5ObjectState | ES5ArrayState>;
  12. hasChanges_(state: ES5ArrayState | ES5ObjectState): boolean;
  13. };
  14. MapSet?: {
  15. proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): T;
  16. proxySet_<T extends AnySet>(target: T, parent?: ImmerState): T;
  17. };
  18. };
  19. declare type Plugins = typeof plugins;
  20. export declare function getPlugin<K extends keyof Plugins>(pluginKey: K): Exclude<Plugins[K], undefined>;
  21. export declare function loadPlugin<K extends keyof Plugins>(pluginKey: K, implementation: Plugins[K]): void;
  22. /** ES5 Plugin */
  23. interface ES5BaseState extends ImmerBaseState {
  24. assigned_: {
  25. [key: string]: any;
  26. };
  27. parent_?: ImmerState;
  28. revoked_: boolean;
  29. }
  30. export interface ES5ObjectState extends ES5BaseState {
  31. type_: typeof ProxyTypeES5Object;
  32. draft_: Drafted<AnyObject, ES5ObjectState>;
  33. base_: AnyObject;
  34. copy_: AnyObject | null;
  35. }
  36. export interface ES5ArrayState extends ES5BaseState {
  37. type_: typeof ProxyTypeES5Array;
  38. draft_: Drafted<AnyObject, ES5ArrayState>;
  39. base_: any;
  40. copy_: any;
  41. }
  42. /** Map / Set plugin */
  43. export interface MapState extends ImmerBaseState {
  44. type_: typeof ProxyTypeMap;
  45. copy_: AnyMap | undefined;
  46. assigned_: Map<any, boolean> | undefined;
  47. base_: AnyMap;
  48. revoked_: boolean;
  49. draft_: Drafted<AnyMap, MapState>;
  50. }
  51. export interface SetState extends ImmerBaseState {
  52. type_: typeof ProxyTypeSet;
  53. copy_: AnySet | undefined;
  54. base_: AnySet;
  55. drafts_: Map<any, Drafted>;
  56. revoked_: boolean;
  57. draft_: Drafted<AnySet, SetState>;
  58. }
  59. /** Patches plugin */
  60. export declare type PatchPath = (string | number)[];
  61. export {};
  62. //# sourceMappingURL=plugins.d.ts.map