Skip to content
Myr

plugins.ts

This file

Path

src/utils/plugins.ts

99 lines · 2.3 KiB · TypeScript

Last changed by

feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0

History of this file

Take it

The walk stopped after 200 commits: lines older than 607b994 point at it.

chore: added unit test for #897Michel Weststratebefore adoption607b994

lines 1–7why, one step back
1import {
2 ImmerState,3 Patch,4 Drafted,5 ImmerBaseState,6 AnyMap,7 AnySet,

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 8why, one step back
8 ArchType,

perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202

line 9why, one step back
9 die,

feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0

lines 10–11why, one step back
10 ImmerScope,
11 ProxyArrayState

chore: added unit test for #897Michel Weststratebefore adoption607b994

lines 12–13why, one step back
12} from "../internal"
13

perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202

lines 14–15why, one step back
14export const PluginMapSet = "MapSet"
15export const PluginPatches = "Patches"

feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0

line 16why, one step back
16export const PluginArrayMethods = "ArrayMethods"

perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202

lines 17–38why, one step back
17
18export type PatchesPlugin = {19 generatePatches_(20 state: ImmerState,21 basePath: PatchPath,22 rootScope: ImmerScope23 ): void24 generateReplacementPatches_(25 base: any,26 replacement: any,27 rootScope: ImmerScope28 ): void29 applyPatches_<T>(draft: T, patches: readonly Patch[]): T30 getPath: (state: ImmerState) => PatchPath | null31}3233export type MapSetPlugin = {34 proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): [T, ImmerState]35 proxySet_<T extends AnySet>(target: T, parent?: ImmerState): [T, ImmerState]36 fixSetContents: (state: ImmerState) => void37}38

feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0

lines 39–44why, one step back
39export type ArrayMethodsPlugin = {
40 createMethodInterceptor: (state: ProxyArrayState, method: string) => Function41 isArrayOperationMethod: (method: string) => boolean42 isMutatingArrayMethod: (method: string) => boolean43}44

chore: added unit test for #897Michel Weststratebefore adoption607b994

lines 45–46why, one step back
45/** Plugin utilities */
46const plugins: {

perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202

lines 47–48why, one step back
47 Patches?: PatchesPlugin
48 MapSet?: MapSetPlugin

feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0

line 49why, one step back
49 ArrayMethods?: ArrayMethodsPlugin

chore: added unit test for #897Michel Weststratebefore adoption607b994

lines 50–58why, one step back
50} = {}
5152type Plugins = typeof plugins5354export function getPlugin<K extends keyof Plugins>(55 pluginKey: K56): Exclude<Plugins[K], undefined> {57 const plugin = plugins[pluginKey]58 if (!plugin) {

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 59why, one step back
59 die(0, pluginKey)

chore: added unit test for #897Michel Weststratebefore adoption607b994

lines 60–64why, one step back
60 }
61 // @ts-ignore62 return plugin63}64

perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202

lines 65–66why, one step back
65export let isPluginLoaded = <K extends keyof Plugins>(pluginKey: K): boolean =>
66 !!plugins[pluginKey]

feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0

lines 67–70why, one step back
67
68export let clearPlugin = <K extends keyof Plugins>(pluginKey: K): void => {69 delete plugins[pluginKey]70}

perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202

line 71why, one step back
71

chore: added unit test for #897Michel Weststratebefore adoption607b994

lines 72–80why, one step back
72export function loadPlugin<K extends keyof Plugins>(
73 pluginKey: K,74 implementation: Plugins[K]75): void {76 if (!plugins[pluginKey]) plugins[pluginKey] = implementation77}78/** Map / Set plugin */7980export interface MapState extends ImmerBaseState {

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 81why, one step back
81 type_: ArchType.Map

chore: added unit test for #897Michel Weststratebefore adoption607b994

lines 82–88why, one step back
82 copy_: AnyMap | undefined
83 base_: AnyMap84 revoked_: boolean85 draft_: Drafted<AnyMap, MapState>86}8788export interface SetState extends ImmerBaseState {

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 89why, one step back
89 type_: ArchType.Set

chore: added unit test for #897Michel Weststratebefore adoption607b994

lines 90–99why, one step back
90 copy_: AnySet | undefined
91 base_: AnySet92 drafts_: Map<any, Drafted> // maps the original value to the draft value in the new set93 revoked_: boolean94 draft_: Drafted<AnySet, SetState>95}9697/** Patches plugin */9899export type PatchPath = (string | number)[]