Skip to content
Myr

plugins.ts

This file

Path

src/utils/plugins.ts

86 lines · 1.9 KiB · TypeScript

Last changed by

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

History of this file

Take it

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

fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173

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

lines 9–10why, one step back
9 die,
10 ImmerScope

fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173

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

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

lines 13–36why, one step back
13export const PluginMapSet = "MapSet"
14export const PluginPatches = "Patches"1516export type PatchesPlugin = {17 generatePatches_(18 state: ImmerState,19 basePath: PatchPath,20 rootScope: ImmerScope21 ): void22 generateReplacementPatches_(23 base: any,24 replacement: any,25 rootScope: ImmerScope26 ): void27 applyPatches_<T>(draft: T, patches: readonly Patch[]): T28 getPath: (state: ImmerState) => PatchPath | null29}3031export type MapSetPlugin = {32 proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): [T, ImmerState]33 proxySet_<T extends AnySet>(target: T, parent?: ImmerState): [T, ImmerState]34 fixSetContents: (state: ImmerState) => void35}36

fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173

lines 37–38why, one step back
37/** Plugin utilities */
38const plugins: {

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

lines 39–40why, one step back
39 Patches?: PatchesPlugin
40 MapSet?: MapSetPlugin

fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173

lines 41–49why, one step back
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) {

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

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

fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173

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

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

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

fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173

lines 59–67why, one step back
59export function loadPlugin<K extends keyof Plugins>(
60 pluginKey: K,61 implementation: Plugins[K]62): void {63 if (!plugins[pluginKey]) plugins[pluginKey] = implementation64}65/** Map / Set plugin */6667export interface MapState extends ImmerBaseState {

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

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

fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173

lines 69–75why, one step back
69 copy_: AnyMap | undefined
70 base_: AnyMap71 revoked_: boolean72 draft_: Drafted<AnyMap, MapState>73}7475export interface SetState extends ImmerBaseState {

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

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

fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173

lines 77–86why, one step back
77 copy_: AnySet | undefined
78 base_: AnySet79 drafts_: Map<any, Drafted> // maps the original value to the draft value in the new set80 revoked_: boolean81 draft_: Drafted<AnySet, SetState>82}8384/** Patches plugin */8586export type PatchPath = (string | number)[]