|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.6 KB
|
| Line | |
|---|
| 1 | import {
|
|---|
| 2 | ImmerState,
|
|---|
| 3 | Patch,
|
|---|
| 4 | Drafted,
|
|---|
| 5 | ImmerBaseState,
|
|---|
| 6 | AnyMap,
|
|---|
| 7 | AnySet,
|
|---|
| 8 | ArchType,
|
|---|
| 9 | die
|
|---|
| 10 | } from "../internal"
|
|---|
| 11 |
|
|---|
| 12 | /** Plugin utilities */
|
|---|
| 13 | const plugins: {
|
|---|
| 14 | Patches?: {
|
|---|
| 15 | generatePatches_(
|
|---|
| 16 | state: ImmerState,
|
|---|
| 17 | basePath: PatchPath,
|
|---|
| 18 | patches: Patch[],
|
|---|
| 19 | inversePatches: Patch[]
|
|---|
| 20 | ): void
|
|---|
| 21 | generateReplacementPatches_(
|
|---|
| 22 | base: any,
|
|---|
| 23 | replacement: any,
|
|---|
| 24 | patches: Patch[],
|
|---|
| 25 | inversePatches: Patch[]
|
|---|
| 26 | ): void
|
|---|
| 27 | applyPatches_<T>(draft: T, patches: readonly Patch[]): T
|
|---|
| 28 | }
|
|---|
| 29 | MapSet?: {
|
|---|
| 30 | proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): T
|
|---|
| 31 | proxySet_<T extends AnySet>(target: T, parent?: ImmerState): T
|
|---|
| 32 | }
|
|---|
| 33 | } = {}
|
|---|
| 34 |
|
|---|
| 35 | type Plugins = typeof plugins
|
|---|
| 36 |
|
|---|
| 37 | export function getPlugin<K extends keyof Plugins>(
|
|---|
| 38 | pluginKey: K
|
|---|
| 39 | ): Exclude<Plugins[K], undefined> {
|
|---|
| 40 | const plugin = plugins[pluginKey]
|
|---|
| 41 | if (!plugin) {
|
|---|
| 42 | die(0, pluginKey)
|
|---|
| 43 | }
|
|---|
| 44 | // @ts-ignore
|
|---|
| 45 | return plugin
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | export function loadPlugin<K extends keyof Plugins>(
|
|---|
| 49 | pluginKey: K,
|
|---|
| 50 | implementation: Plugins[K]
|
|---|
| 51 | ): void {
|
|---|
| 52 | if (!plugins[pluginKey]) plugins[pluginKey] = implementation
|
|---|
| 53 | }
|
|---|
| 54 | /** Map / Set plugin */
|
|---|
| 55 |
|
|---|
| 56 | export interface MapState extends ImmerBaseState {
|
|---|
| 57 | type_: ArchType.Map
|
|---|
| 58 | copy_: AnyMap | undefined
|
|---|
| 59 | assigned_: Map<any, boolean> | undefined
|
|---|
| 60 | base_: AnyMap
|
|---|
| 61 | revoked_: boolean
|
|---|
| 62 | draft_: Drafted<AnyMap, MapState>
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | export interface SetState extends ImmerBaseState {
|
|---|
| 66 | type_: ArchType.Set
|
|---|
| 67 | copy_: AnySet | undefined
|
|---|
| 68 | base_: AnySet
|
|---|
| 69 | drafts_: Map<any, Drafted> // maps the original value to the draft value in the new set
|
|---|
| 70 | revoked_: boolean
|
|---|
| 71 | draft_: Drafted<AnySet, SetState>
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | /** Patches plugin */
|
|---|
| 75 |
|
|---|
| 76 | export type PatchPath = (string | number)[]
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.