Skip to content
Myr

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 file

Take it

separating plugins from coreMichel Weststratebefore adoption124518b

lines 1–9why, one step back
1import {
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 back
10 AnySet,

Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db

lines 11–13why, one step back
11 ProxyTypeES5Array,
12 ProxyTypeES5Object,13 ProxyTypeMap,

Errors for prodMichel Weststratebefore adoption67565dd

lines 14–15why, one step back
14 ProxyTypeSet,
15 die

separating plugins from coreMichel Weststratebefore adoption124518b

lines 16–20why, one step back
16} from "./internal"
1718/** Plugin utilities */19const plugins: {20 patches?: {

scramble plugin names, -56Michel Weststratebefore adoption037b474

lines 21–27why, one step back
21 generatePatches_(
22 state: ImmerState,23 basePath: PatchPath,24 patches: Patch[],25 inversePatches: Patch[]26 ): void27 applyPatches_<T>(draft: T, patches: Patch[]): T

separating plugins from coreMichel Weststratebefore adoption124518b

lines 28–29why, one step back
28 }
29 es5?: {

scramble plugin names, -56Michel Weststratebefore adoption037b474

lines 30–35why, one step back
30 willFinalizeES5_(scope: ImmerScope, result: any, isReplaced: boolean): void
31 createES5Proxy_<T>(32 base: T,33 parent?: ImmerState34 ): Drafted<T, ES5ObjectState | ES5ArrayState>35 markChangedES5_(state: ImmerState): void

separating plugins from coreMichel Weststratebefore adoption124518b

lines 36–37why, one step back
36 }
37 mapset?: {

scramble plugin names, -56Michel Weststratebefore adoption037b474

lines 38–39why, one step back
38 proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): T
39 proxySet_<T extends AnySet>(target: T, parent?: ImmerState): T

separating plugins from coreMichel Weststratebefore adoption124518b

lines 40–49why, one step back
40 }
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 back
50 die(__DEV__ ? 18 : 19, plugin)

separating plugins from coreMichel Weststratebefore adoption124518b

lines 51–55why, one step back
51 }
52 // @ts-ignore53 return plugin54}55

TSDXMichel Weststratebefore adoption4c4fecc

line 56why, one step back
56export function loadPlugin<K extends keyof Plugins>(

separating plugins from coreMichel Weststratebefore adoption124518b

line 57why, one step back
57 pluginKey: K,

TSDXMichel Weststratebefore adoption4c4fecc

line 58why, one step back
58 implementation: Plugins[K]

Removed some couplingMichel Weststratebefore adoption70e77aa

line 59why, one step back
59): void {

TSDXMichel Weststratebefore adoption4c4fecc

line 60why, one step back
60 plugins[pluginKey] = implementation

separating plugins from coreMichel Weststratebefore adoption124518b

lines 61–65why, one step back
61}
6263/** ES5 Plugin */6465interface ES5BaseState extends ImmerBaseState {

Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd

lines 66–69why, one step back
66 finalizing_: boolean
67 assigned_: {[key: string]: any}68 parent_?: ImmerState69 revoked_: boolean

separating plugins from coreMichel Weststratebefore adoption124518b

lines 70–72why, one step back
70}
7172export interface ES5ObjectState extends ES5BaseState {

Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db

line 73why, one step back
73 type_: typeof ProxyTypeES5Object

Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd

lines 74–76why, one step back
74 draft_: Drafted<AnyObject, ES5ObjectState>
75 base_: AnyObject76 copy_: AnyObject | null

separating plugins from coreMichel Weststratebefore adoption124518b

lines 77–79why, one step back
77}
7879export interface ES5ArrayState extends ES5BaseState {

Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db

line 80why, one step back
80 type_: typeof ProxyTypeES5Array

Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd

lines 81–83why, one step back
81 draft_: Drafted<AnyObject, ES5ArrayState>
82 base_: AnyArray83 copy_: AnyArray | null

separating plugins from coreMichel Weststratebefore adoption124518b

lines 84–88why, one step back
84}
8586/** Map / Set plugin */8788export interface MapState extends ImmerBaseState {

Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db

line 89why, one step back
89 type_: typeof ProxyTypeMap

Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd

lines 90–94why, one step back
90 copy_: AnyMap | undefined
91 assigned_: Map<any, boolean> | undefined92 base_: AnyMap93 revoked_: boolean94 draft_: Drafted<AnyMap, MapState>

separating plugins from coreMichel Weststratebefore adoption124518b

lines 95–97why, one step back
95}
9697export interface SetState extends ImmerBaseState {

Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db

line 98why, one step back
98 type_: typeof ProxyTypeSet

Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd

lines 99–103why, one step back
99 copy_: AnySet | undefined
100 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 back
104}
105106/** Patches plugin */107108export type PatchPath = (string | number)[]