plugins.ts
This file
Path
src/plugins.ts
108 lines · 2.3 KiB · TypeScript
Last changed by
Errors for prodMichel Weststratebefore adoption67565dd
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–13why, one step back11 ProxyTypeES5Array,12 ProxyTypeES5Object,13 ProxyTypeMap,Errors for prodMichel Weststratebefore adoption67565dd
lines 14–15why, one step back14 ProxyTypeSet,15 dieseparating plugins from coreMichel Weststratebefore adoption124518b
lines 16–20why, one step back16} from "./internal"1718/** Plugin utilities */19const plugins: {20 patches?: {scramble plugin names, -56Michel Weststratebefore adoption037b474
lines 21–27why, one step back21 generatePatches_(22 state: ImmerState,23 basePath: PatchPath,24 patches: Patch[],25 inversePatches: Patch[]26 ): void27 applyPatches_<T>(draft: T, patches: Patch[]): Tseparating plugins from coreMichel Weststratebefore adoption124518b
lines 28–29why, one step back28 }29 es5?: {scramble plugin names, -56Michel Weststratebefore adoption037b474
lines 30–35why, one step back30 willFinalizeES5_(scope: ImmerScope, result: any, isReplaced: boolean): void31 createES5Proxy_<T>(32 base: T,33 parent?: ImmerState34 ): Drafted<T, ES5ObjectState | ES5ArrayState>35 markChangedES5_(state: ImmerState): voidseparating plugins from coreMichel Weststratebefore adoption124518b
lines 36–37why, one step back36 }37 mapset?: {scramble plugin names, -56Michel Weststratebefore adoption037b474
lines 38–39why, one step back38 proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): T39 proxySet_<T extends AnySet>(target: T, parent?: ImmerState): Tseparating plugins from coreMichel Weststratebefore adoption124518b
lines 40–49why, one step back40 }41} = {}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) {Errors for prodMichel Weststratebefore adoption67565dd
line 50why, one step back50 die(__DEV__ ? 18 : 19, plugin)separating plugins from coreMichel Weststratebefore adoption124518b
lines 51–55why, one step back51 }52 // @ts-ignore53 return plugin54}55TSDXMichel Weststratebefore adoption4c4fecc
line 56why, one step back56export function loadPlugin<K extends keyof Plugins>(separating plugins from coreMichel Weststratebefore adoption124518b
line 57why, one step back57 pluginKey: K,TSDXMichel Weststratebefore adoption4c4fecc
line 58why, one step back58 implementation: Plugins[K]Removed some couplingMichel Weststratebefore adoption70e77aa
line 59why, one step back59): void {TSDXMichel Weststratebefore adoption4c4fecc
line 60why, one step back60 plugins[pluginKey] = implementationseparating plugins from coreMichel Weststratebefore adoption124518b
lines 61–65why, one step back61}6263/** ES5 Plugin */6465interface ES5BaseState extends ImmerBaseState {Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 66–69why, one step back66 finalizing_: boolean67 assigned_: {[key: string]: any}68 parent_?: ImmerState69 revoked_: booleanseparating plugins from coreMichel Weststratebefore adoption124518b
lines 70–72why, one step back70}7172export interface ES5ObjectState extends ES5BaseState {Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
line 73why, one step back73 type_: typeof ProxyTypeES5ObjectMangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 74–76why, one step back74 draft_: Drafted<AnyObject, ES5ObjectState>75 base_: AnyObject76 copy_: AnyObject | nullseparating plugins from coreMichel Weststratebefore adoption124518b
lines 77–79why, one step back77}7879export interface ES5ArrayState extends ES5BaseState {Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
line 80why, one step back80 type_: typeof ProxyTypeES5ArrayMangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 81–83why, one step back81 draft_: Drafted<AnyObject, ES5ArrayState>82 base_: AnyArray83 copy_: AnyArray | nullseparating plugins from coreMichel Weststratebefore adoption124518b
lines 84–88why, one step back84}8586/** Map / Set plugin */8788export interface MapState extends ImmerBaseState {Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
line 89why, one step back89 type_: typeof ProxyTypeMapMangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 90–94why, one step back90 copy_: AnyMap | undefined91 assigned_: Map<any, boolean> | undefined92 base_: AnyMap93 revoked_: boolean94 draft_: Drafted<AnyMap, MapState>separating plugins from coreMichel Weststratebefore adoption124518b
lines 95–97why, one step back95}9697export interface SetState extends ImmerBaseState {Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db
line 98why, one step back98 type_: typeof ProxyTypeSetMangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd
lines 99–103why, one step back99 copy_: AnySet | undefined100 base_: AnySet101 drafts_: Map<any, Drafted> // maps the original value to the draft value in the new set102 revoked_: boolean103 draft_: Drafted<AnySet, SetState>separating plugins from coreMichel Weststratebefore adoption124518b
lines 104–108why, one step back104}105106/** Patches plugin */107108export type PatchPath = (string | number)[]