plugins.ts
This file
Path
src/utils/plugins.ts
86 lines · 1.9 KiB · TypeScript
Last changed by
perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
History of this fileTake it
The walk stopped after 200 commits: lines older than 6555173 point at it.
fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173
lines 1–7why, one step back1import {2 ImmerState,3 Patch,4 Drafted,5 ImmerBaseState,6 AnyMap,7 AnySet,Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 8why, one step back8 ArchType,perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
lines 9–10why, one step back9 die,10 ImmerScopefix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173
lines 11–12why, one step back11} from "../internal"12perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
lines 13–36why, one step back13export const PluginMapSet = "MapSet"14export const PluginPatches = "Patches"1516export type PatchesPlugin = {17 generatePatches_(18 state: ImmerState,19 basePath: PatchPath,20 rootScope: ImmerScope21 ): void22 generateReplacementPatches_(23 base: any,24 replacement: any,25 rootScope: ImmerScope26 ): void27 applyPatches_<T>(draft: T, patches: readonly Patch[]): T28 getPath: (state: ImmerState) => PatchPath | null29}3031export type MapSetPlugin = {32 proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): [T, ImmerState]33 proxySet_<T extends AnySet>(target: T, parent?: ImmerState): [T, ImmerState]34 fixSetContents: (state: ImmerState) => void35}36fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173
lines 37–38why, one step back37/** Plugin utilities */38const plugins: {perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
lines 39–40why, one step back39 Patches?: PatchesPlugin40 MapSet?: MapSetPluginfix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173
lines 41–49why, one step back41} = {}4243type Plugins = typeof plugins4445export function getPlugin<K extends keyof Plugins>(46 pluginKey: K47): Exclude<Plugins[K], undefined> {48 const plugin = plugins[pluginKey]49 if (!plugin) {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 50why, one step back50 die(0, pluginKey)fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173
lines 51–55why, one step back51 }52 // @ts-ignore53 return plugin54}55perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
lines 56–58why, one step back56export let isPluginLoaded = <K extends keyof Plugins>(pluginKey: K): boolean =>57 !!plugins[pluginKey]58fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173
lines 59–67why, one step back59export function loadPlugin<K extends keyof Plugins>(60 pluginKey: K,61 implementation: Plugins[K]62): void {63 if (!plugins[pluginKey]) plugins[pluginKey] = implementation64}65/** Map / Set plugin */6667export interface MapState extends ImmerBaseState {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 68why, one step back68 type_: ArchType.Mapfix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173
lines 69–75why, one step back69 copy_: AnyMap | undefined70 base_: AnyMap71 revoked_: boolean72 draft_: Drafted<AnyMap, MapState>73}7475export interface SetState extends ImmerBaseState {Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42
line 76why, one step back76 type_: ArchType.Setfix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173
lines 77–86why, one step back77 copy_: AnySet | undefined78 base_: AnySet79 drafts_: Map<any, Drafted> // maps the original value to the draft value in the new set80 revoked_: boolean81 draft_: Drafted<AnySet, SetState>82}8384/** Patches plugin */8586export type PatchPath = (string | number)[]