plugins.ts
This file
Path
src/plugins.ts
111 lines · 2.5 KiB · TypeScript
Last changed by
scramble plugin names, -56Michel Weststratebefore adoption037b474
History of this fileTake it
separating plugins from coreMichel Weststratebefore adoption124518b
lines 1–9why, one step back1import {2 ImmerState,3 Patch,4 ImmerScope,5 Drafted,6 AnyObject,7 ImmerBaseState,8 AnyArray,9 AnyMap,Removed some couplingMichel Weststratebefore adoption70e77aa
line 10why, one step back10 AnySet,Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
lines 11–14why, one step back11 ProxyTypeES5Array,12 ProxyTypeES5Object,13 ProxyTypeMap,14 ProxyTypeSetseparating plugins from coreMichel Weststratebefore adoption124518b
lines 15–19why, one step back15} from "./internal"1617/** Plugin utilities */18const plugins: {19 patches?: {scramble plugin names, -56Michel Weststratebefore adoption037b474
lines 20–26why, one step back20 generatePatches_(21 state: ImmerState,22 basePath: PatchPath,23 patches: Patch[],24 inversePatches: Patch[]25 ): void26 applyPatches_<T>(draft: T, patches: Patch[]): Tseparating plugins from coreMichel Weststratebefore adoption124518b
lines 27–28why, one step back27 }28 es5?: {scramble plugin names, -56Michel Weststratebefore adoption037b474
lines 29–34why, one step back29 willFinalizeES5_(scope: ImmerScope, result: any, isReplaced: boolean): void30 createES5Proxy_<T>(31 base: T,32 parent?: ImmerState33 ): Drafted<T, ES5ObjectState | ES5ArrayState>34 markChangedES5_(state: ImmerState): voidseparating plugins from coreMichel Weststratebefore adoption124518b
lines 35–36why, one step back35 }36 mapset?: {scramble plugin names, -56Michel Weststratebefore adoption037b474
lines 37–38why, one step back37 proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): T38 proxySet_<T extends AnySet>(target: T, parent?: ImmerState): Tseparating plugins from coreMichel Weststratebefore adoption124518b
lines 39–49why, one step back39 }40} = {}4142type Plugins = typeof plugins4344export function getPlugin<K extends keyof Plugins>(45 pluginKey: K46): Exclude<Plugins[K], undefined> {47 const plugin = plugins[pluginKey]48 if (!plugin) {49 throw new Error(New build set. Current statsMichel Weststratebefore adoption9aec0fe
lines 50–52why, one step back50 `The plugin ${pluginKey} has not been loaded into Immer. Make sure to call "enable${pluginKey[0].toUpperCase()}${pluginKey.substr(51 152 )}()" when initializing your application, just after requiring immer itself.`separating plugins from coreMichel Weststratebefore adoption124518b
lines 53–58why, one step back53 )54 }55 // @ts-ignore56 return plugin57}58TSDXMichel Weststratebefore adoption4c4fecc
line 59why, one step back59export function loadPlugin<K extends keyof Plugins>(separating plugins from coreMichel Weststratebefore adoption124518b
line 60why, one step back60 pluginKey: K,TSDXMichel Weststratebefore adoption4c4fecc
line 61why, one step back61 implementation: Plugins[K]Removed some couplingMichel Weststratebefore adoption70e77aa
line 62why, one step back62): void {TSDXMichel Weststratebefore adoption4c4fecc
line 63why, one step back63 plugins[pluginKey] = implementationseparating plugins from coreMichel Weststratebefore adoption124518b
lines 64–68why, one step back64}6566/** ES5 Plugin */6768interface ES5BaseState extends ImmerBaseState {Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 69–72why, one step back69 finalizing_: boolean70 assigned_: {[key: string]: any}71 parent_?: ImmerState72 revoked_: booleanseparating plugins from coreMichel Weststratebefore adoption124518b
lines 73–75why, one step back73}7475export interface ES5ObjectState extends ES5BaseState {Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
line 76why, one step back76 type_: typeof ProxyTypeES5ObjectMangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 77–79why, one step back77 draft_: Drafted<AnyObject, ES5ObjectState>78 base_: AnyObject79 copy_: AnyObject | nullseparating plugins from coreMichel Weststratebefore adoption124518b
lines 80–82why, one step back80}8182export interface ES5ArrayState extends ES5BaseState {Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
line 83why, one step back83 type_: typeof ProxyTypeES5ArrayMangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 84–86why, one step back84 draft_: Drafted<AnyObject, ES5ArrayState>85 base_: AnyArray86 copy_: AnyArray | nullseparating plugins from coreMichel Weststratebefore adoption124518b
lines 87–91why, one step back87}8889/** Map / Set plugin */9091export interface MapState extends ImmerBaseState {Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
line 92why, one step back92 type_: typeof ProxyTypeMapMangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 93–97why, one step back93 copy_: AnyMap | undefined94 assigned_: Map<any, boolean> | undefined95 base_: AnyMap96 revoked_: boolean97 draft_: Drafted<AnyMap, MapState>separating plugins from coreMichel Weststratebefore adoption124518b
lines 98–100why, one step back98}99100export interface SetState extends ImmerBaseState {Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
line 101why, one step back101 type_: typeof ProxyTypeSetMangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 102–106why, one step back102 copy_: AnySet | undefined103 base_: AnySet104 drafts_: Map<any, Drafted> // maps the original value to the draft value in the new set105 revoked_: boolean106 draft_: Drafted<AnySet, SetState>separating plugins from coreMichel Weststratebefore adoption124518b
lines 107–111why, one step back107}108109/** Patches plugin */110111export type PatchPath = (string | number)[]