Skip to content
Myr

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 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–14why, one step back
11 ProxyTypeES5Array,
12 ProxyTypeES5Object,13 ProxyTypeMap,14 ProxyTypeSet

separating plugins from coreMichel Weststratebefore adoption124518b

lines 15–19why, one step back
15} from "./internal"
1617/** Plugin utilities */18const plugins: {19 patches?: {

scramble plugin names, -56Michel Weststratebefore adoption037b474

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

separating plugins from coreMichel Weststratebefore adoption124518b

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

scramble plugin names, -56Michel Weststratebefore adoption037b474

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

separating plugins from coreMichel Weststratebefore adoption124518b

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

scramble plugin names, -56Michel Weststratebefore adoption037b474

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

separating plugins from coreMichel Weststratebefore adoption124518b

lines 39–49why, one step back
39 }
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 back
50 `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 back
53 )
54 }55 // @ts-ignore56 return plugin57}58

TSDXMichel Weststratebefore adoption4c4fecc

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

separating plugins from coreMichel Weststratebefore adoption124518b

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

TSDXMichel Weststratebefore adoption4c4fecc

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

Removed some couplingMichel Weststratebefore adoption70e77aa

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

TSDXMichel Weststratebefore adoption4c4fecc

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

separating plugins from coreMichel Weststratebefore adoption124518b

lines 64–68why, one step back
64}
6566/** ES5 Plugin */6768interface ES5BaseState extends ImmerBaseState {

Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd

lines 69–72why, one step back
69 finalizing_: boolean
70 assigned_: {[key: string]: any}71 parent_?: ImmerState72 revoked_: boolean

separating plugins from coreMichel Weststratebefore adoption124518b

lines 73–75why, one step back
73}
7475export interface ES5ObjectState extends ES5BaseState {

Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db

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

Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd

lines 77–79why, one step back
77 draft_: Drafted<AnyObject, ES5ObjectState>
78 base_: AnyObject79 copy_: AnyObject | null

separating plugins from coreMichel Weststratebefore adoption124518b

lines 80–82why, one step back
80}
8182export interface ES5ArrayState extends ES5BaseState {

Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db

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

Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd

lines 84–86why, one step back
84 draft_: Drafted<AnyObject, ES5ArrayState>
85 base_: AnyArray86 copy_: AnyArray | null

separating plugins from coreMichel Weststratebefore adoption124518b

lines 87–91why, one step back
87}
8889/** Map / Set plugin */9091export interface MapState extends ImmerBaseState {

Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db

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

Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd

lines 93–97why, one step back
93 copy_: AnyMap | undefined
94 assigned_: Map<any, boolean> | undefined95 base_: AnyMap96 revoked_: boolean97 draft_: Drafted<AnyMap, MapState>

separating plugins from coreMichel Weststratebefore adoption124518b

lines 98–100why, one step back
98}
99100export interface SetState extends ImmerBaseState {

Killed enumerations -145 (!)Michel Weststratebefore adoptionfdc78db

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

Mangle properties, -114 bytesMichel Weststratebefore adoptionbfa7ddd

lines 102–106why, one step back
102 copy_: AnySet | undefined
103 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 back
107}
108109/** Patches plugin */110111export type PatchPath = (string | number)[]