plugins.ts
This file
Path
src/utils/plugins.ts
109 lines · 2.3 KiB · TypeScript
Last changed by
fix: No patches being generated for root primitive replacements. Fixes #888Michel Weststratebefore adoption0f96270
History of this fileTake it
The walk stopped after 200 commits: lines older than 949960f point at it.
fix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
lines 1–9why, one step back1import {2 ImmerState,3 Patch,4 ImmerScope,5 Drafted,6 AnyObject,7 ImmerBaseState,8 AnyMap,9 AnySet,chore: reduce size by using TS const enum (#812)houfengbefore adoptionb1fac9d
line 10why, one step back10 ProxyType,fix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
lines 11–23why, one step back11 die12} from "../internal"1314/** Plugin utilities */15const plugins: {16 Patches?: {17 generatePatches_(18 state: ImmerState,19 basePath: PatchPath,20 patches: Patch[],21 inversePatches: Patch[]22 ): void23 generateReplacementPatches_(fix: No patches being generated for root primitive replacements. Fixes #888Michel Weststratebefore adoption0f96270
line 24why, one step back24 base: any,fix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
lines 25–36why, one step back25 replacement: any,26 patches: Patch[],27 inversePatches: Patch[]28 ): void29 applyPatches_<T>(draft: T, patches: Patch[]): T30 }31 ES5?: {32 willFinalizeES5_(scope: ImmerScope, result: any, isReplaced: boolean): void33 createES5Proxy_<T>(34 base: T,35 parent?: ImmerState36 ): Drafted<T, ES5ObjectState | ES5ArrayState>Immer 7Michel Weststratebefore adoption467ea5d
line 37why, one step back37 hasChanges_(state: ES5ArrayState | ES5ObjectState): booleanfix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
lines 38–51why, one step back38 }39 MapSet?: {40 proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): T41 proxySet_<T extends AnySet>(target: T, parent?: ImmerState): T42 }43} = {}4445type Plugins = typeof plugins4647export function getPlugin<K extends keyof Plugins>(48 pluginKey: K49): Exclude<Plugins[K], undefined> {50 const plugin = plugins[pluginKey]51 if (!plugin) {clearer error when plugin is missingMichel Weststratebefore adoptionb2e5493
line 52why, one step back52 die(18, pluginKey)fix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
lines 53–61why, one step back53 }54 // @ts-ignore55 return plugin56}5758export function loadPlugin<K extends keyof Plugins>(59 pluginKey: K,60 implementation: Plugins[K]61): void {fix: make plugin loading idempotent, fixes #692Michel Weststratebefore adoption754331b
line 62why, one step back62 if (!plugins[pluginKey]) plugins[pluginKey] = implementationfix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
lines 63–73why, one step back63}6465/** ES5 Plugin */6667interface ES5BaseState extends ImmerBaseState {68 assigned_: {[key: string]: any}69 parent_?: ImmerState70 revoked_: boolean71}7273export interface ES5ObjectState extends ES5BaseState {chore: reduce size by using TS const enum (#812)houfengbefore adoptionb1fac9d
line 74why, one step back74 type_: ProxyType.ES5Objectfix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
lines 75–80why, one step back75 draft_: Drafted<AnyObject, ES5ObjectState>76 base_: AnyObject77 copy_: AnyObject | null78}7980export interface ES5ArrayState extends ES5BaseState {chore: reduce size by using TS const enum (#812)houfengbefore adoptionb1fac9d
line 81why, one step back81 type_: ProxyType.ES5Arrayfix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
line 82why, one step back82 draft_: Drafted<AnyObject, ES5ArrayState>Immer 7Michel Weststratebefore adoption467ea5d
lines 83–84why, one step back83 base_: any84 copy_: anyfix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
lines 85–89why, one step back85}8687/** Map / Set plugin */8889export interface MapState extends ImmerBaseState {chore: reduce size by using TS const enum (#812)houfengbefore adoptionb1fac9d
line 90why, one step back90 type_: ProxyType.Mapfix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
lines 91–98why, one step back91 copy_: AnyMap | undefined92 assigned_: Map<any, boolean> | undefined93 base_: AnyMap94 revoked_: boolean95 draft_: Drafted<AnyMap, MapState>96}9798export interface SetState extends ImmerBaseState {chore: reduce size by using TS const enum (#812)houfengbefore adoptionb1fac9d
line 99why, one step back99 type_: ProxyType.Setfix: fixed broken minimized error url (issue#550)Michel Weststratebefore adoption949960f
lines 100–109why, one step back100 copy_: AnySet | undefined101 base_: AnySet102 drafts_: Map<any, Drafted> // maps the original value to the draft value in the new set103 revoked_: boolean104 draft_: Drafted<AnySet, SetState>105}106107/** Patches plugin */108109export type PatchPath = (string | number)[]