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 fileTake it
The walk stopped after 200 commits: lines older than 16a3d0f point at it.
chore(deps): bump prismjs from 1.23.0 to 1.24.0 in /website (#822)dependabot[bot]before adoption16a3d0f
lines 1–7why, one step back1import {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 back8 ArchType,perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
line 9why, one step back9 die,feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0
lines 10–11why, one step back10 ImmerScope,11 ProxyArrayStatechore(deps): bump prismjs from 1.23.0 to 1.24.0 in /website (#822)dependabot[bot]before adoption16a3d0f
lines 12–13why, one step back12} from "../internal"13perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
lines 14–15why, one step back14export 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 back16export 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 back1718export 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}38feat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0
lines 39–44why, one step back39export type ArrayMethodsPlugin = {40 createMethodInterceptor: (state: ProxyArrayState, method: string) => Function41 isArrayOperationMethod: (method: string) => boolean42 isMutatingArrayMethod: (method: string) => boolean43}44chore(deps): bump prismjs from 1.23.0 to 1.24.0 in /website (#822)dependabot[bot]before adoption16a3d0f
lines 45–46why, one step back45/** 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 back47 Patches?: PatchesPlugin48 MapSet?: MapSetPluginfeat: Override array methods to avoid proxy creation while iterating and updating (#1184)Mark Eriksonbefore adoptiond38a9d0
line 49why, one step back49 ArrayMethods?: ArrayMethodsPluginchore(deps): bump prismjs from 1.23.0 to 1.24.0 in /website (#822)dependabot[bot]before adoption16a3d0f
lines 50–58why, one step back50} = {}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 back59 die(0, pluginKey)chore(deps): bump prismjs from 1.23.0 to 1.24.0 in /website (#822)dependabot[bot]before adoption16a3d0f
lines 60–64why, one step back60 }61 // @ts-ignore62 return plugin63}64perf: Rewrite finalization system to use a callback approach instead of tree traversal (#1183)Mark Eriksonbefore adoptiond6c1202
lines 65–66why, one step back65export 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 back6768export 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 back71chore(deps): bump prismjs from 1.23.0 to 1.24.0 in /website (#822)dependabot[bot]before adoption16a3d0f
lines 72–80why, one step back72export 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 back81 type_: ArchType.Mapchore(deps): bump prismjs from 1.23.0 to 1.24.0 in /website (#822)dependabot[bot]before adoption16a3d0f
lines 82–88why, one step back82 copy_: AnyMap | undefined83 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 back89 type_: ArchType.Setchore(deps): bump prismjs from 1.23.0 to 1.24.0 in /website (#822)dependabot[bot]before adoption16a3d0f
lines 90–99why, one step back90 copy_: AnySet | undefined91 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)[]