cross-state 0.34.3 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/cjs/diff.cjs +92 -0
  2. package/dist/cjs/diff.cjs.map +1 -0
  3. package/dist/cjs/index.cjs +15 -143
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/{immer → mutative}/index.cjs +2 -2
  6. package/dist/cjs/mutative/register.cjs +5 -0
  7. package/dist/cjs/mutative/register.cjs.map +1 -0
  8. package/dist/cjs/mutativeMethods.cjs +26 -0
  9. package/dist/cjs/mutativeMethods.cjs.map +1 -0
  10. package/dist/cjs/patches/index.cjs +53 -0
  11. package/dist/cjs/patches/index.cjs.map +1 -0
  12. package/dist/cjs/patches/register.cjs +34 -0
  13. package/dist/cjs/patches/register.cjs.map +1 -0
  14. package/dist/cjs/propAccess.cjs +151 -0
  15. package/dist/cjs/propAccess.cjs.map +1 -0
  16. package/dist/cjs/react/index.cjs +11 -10
  17. package/dist/cjs/react/index.cjs.map +1 -1
  18. package/dist/cjs/scope.cjs +2 -1
  19. package/dist/cjs/scope.cjs.map +1 -1
  20. package/dist/cjs/store.cjs +13 -158
  21. package/dist/cjs/store.cjs.map +1 -1
  22. package/dist/cjs/useCache.cjs +3 -2
  23. package/dist/cjs/useCache.cjs.map +1 -1
  24. package/dist/es/diff.mjs +93 -0
  25. package/dist/es/diff.mjs.map +1 -0
  26. package/dist/es/index.mjs +18 -144
  27. package/dist/es/index.mjs.map +1 -1
  28. package/dist/es/mutative/index.mjs +5 -0
  29. package/dist/es/mutative/register.mjs +4 -0
  30. package/dist/es/mutative/register.mjs.map +1 -0
  31. package/dist/es/mutativeMethods.mjs +27 -0
  32. package/dist/es/mutativeMethods.mjs.map +1 -0
  33. package/dist/es/patches/index.mjs +53 -0
  34. package/dist/es/patches/index.mjs.map +1 -0
  35. package/dist/es/patches/register.mjs +34 -0
  36. package/dist/es/patches/register.mjs.map +1 -0
  37. package/dist/es/propAccess.mjs +152 -0
  38. package/dist/es/propAccess.mjs.map +1 -0
  39. package/dist/es/react/index.mjs +2 -1
  40. package/dist/es/react/index.mjs.map +1 -1
  41. package/dist/es/scope.mjs +2 -1
  42. package/dist/es/scope.mjs.map +1 -1
  43. package/dist/es/store.mjs +10 -155
  44. package/dist/es/store.mjs.map +1 -1
  45. package/dist/es/useCache.mjs +2 -1
  46. package/dist/es/useCache.mjs.map +1 -1
  47. package/dist/types/core/commonTypes.d.ts +3 -0
  48. package/dist/types/core/store.d.ts +1 -0
  49. package/dist/types/index.d.ts +0 -1
  50. package/dist/types/lib/autobind.d.ts +1 -1
  51. package/dist/types/lib/diff.d.ts +3 -2
  52. package/dist/types/mutative/index.d.ts +1 -0
  53. package/dist/types/mutative/mutativeMethods.d.ts +10 -0
  54. package/dist/types/mutative/register.d.ts +7 -0
  55. package/dist/types/patches/index.d.ts +1 -0
  56. package/dist/types/patches/patchMethods.d.ts +33 -0
  57. package/dist/types/patches/register.d.ts +9 -0
  58. package/dist/types/react/form/customInput.d.ts +1 -1
  59. package/dist/types/react/form/form.d.ts +2 -2
  60. package/dist/types/react/form/formField.d.ts +2 -2
  61. package/dist/types/react/form/formForEach.d.ts +1 -1
  62. package/dist/types/react/loadingBoundary.d.ts +1 -1
  63. package/dist/types/react/register.d.ts +1 -1
  64. package/dist/types/react/scope.d.ts +1 -1
  65. package/package.json +58 -33
  66. package/dist/cjs/immer/register.cjs +0 -5
  67. package/dist/cjs/immer/register.cjs.map +0 -1
  68. package/dist/cjs/immerMethods.cjs +0 -23
  69. package/dist/cjs/immerMethods.cjs.map +0 -1
  70. package/dist/es/immer/index.mjs +0 -5
  71. package/dist/es/immer/register.mjs +0 -4
  72. package/dist/es/immer/register.mjs.map +0 -1
  73. package/dist/es/immerMethods.mjs +0 -24
  74. package/dist/es/immerMethods.mjs.map +0 -1
  75. package/dist/types/immer/immerMethods.d.ts +0 -10
  76. package/dist/types/immer/index.d.ts +0 -1
  77. package/dist/types/immer/register.d.ts +0 -7
  78. package/dist/types/sync/index.d.ts +0 -1
  79. package/dist/types/sync/sync.d.ts +0 -17
  80. /package/dist/cjs/{immer → mutative}/index.cjs.map +0 -0
  81. /package/dist/es/{immer → mutative}/index.mjs.map +0 -0
@@ -0,0 +1,33 @@
1
+ import type { SubscribeOptions } from '../core';
2
+ import type { Store } from '../core/store';
3
+ import { type DiffOptions, type Patch } from '../lib/diff';
4
+ declare module '../core' {
5
+ interface Store<T> {
6
+ __patches?: Store<[Patch[], Patch[]]>;
7
+ }
8
+ }
9
+ export interface SubscribePatchOptions extends SubscribeOptions, DiffOptions {
10
+ /** @default false */
11
+ runNow?: boolean;
12
+ }
13
+ export interface SyncMessage {
14
+ id: string;
15
+ previousId?: string;
16
+ patches: Patch[];
17
+ }
18
+ export type InteropPatch = Patch | {
19
+ op: 'add' | 'replace' | 'remove';
20
+ value?: any;
21
+ };
22
+ declare function subscribePatches<T>(this: Store<T>, listener: (patches: Patch[], reversePatches: Patch[]) => void, options?: SubscribePatchOptions): import("../core").DisposableCancel;
23
+ declare function applyPatches<T>(this: Store<T>, patches: InteropPatch[]): void;
24
+ declare function applyPatches<T>(this: Store<T>, ...patches: InteropPatch[]): void;
25
+ declare function sync<T>(this: Store<T>, listener: (syncMessage: SyncMessage) => void, options?: Omit<SubscribePatchOptions, 'runNow'>): import("../core").DisposableCancel;
26
+ declare function acceptSync<T>(this: Store<T>): (message: SyncMessage) => void;
27
+ export declare const patchMethods: {
28
+ subscribePatches: typeof subscribePatches;
29
+ applyPatches: typeof applyPatches;
30
+ sync: typeof sync;
31
+ acceptSync: typeof acceptSync;
32
+ };
33
+ export {};
@@ -0,0 +1,9 @@
1
+ import { patchMethods } from './patchMethods';
2
+ type PatchMethods = typeof patchMethods;
3
+ declare module '../core' {
4
+ interface Store<T> extends PatchMethods {
5
+ }
6
+ }
7
+ export declare function register(): void;
8
+ export declare function unregister(): void;
9
+ export {};
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react';
1
+ import type { ReactNode } from '../../react';
2
2
  export interface CustomInputProps extends React.HTMLAttributes<HTMLDivElement> {
3
3
  name: string;
4
4
  children?: ReactNode;
@@ -1,7 +1,7 @@
1
1
  import { type Store, type UrlStoreOptions } from '../../core';
2
2
  import { type Path, type PathAsString, type Value, type WildcardPathAsString, type WildcardValue } from '../../lib/path';
3
3
  import type { Object_ } from '../../lib/typeHelpers';
4
- import { type FormEvent, type HTMLProps, type ReactNode } from 'react';
4
+ import { type FormEvent, type HTMLProps, type ReactNode } from '../../react';
5
5
  import { type UseStoreOptions } from '../useStore';
6
6
  import { type FormFieldComponent, type FormFieldPropsWithComponent, type FormFieldPropsWithRender } from './formField';
7
7
  import { type ElementName, type ForEachPath, type FormForEachProps } from './formForEach';
@@ -74,7 +74,7 @@ export interface FormInstance<TDraft, TOriginal> extends FormDerivedState<TDraft
74
74
  }
75
75
  export declare class Form<TDraft, TOriginal extends TDraft = TDraft> {
76
76
  readonly options: FormOptions<TDraft, TOriginal>;
77
- context: import("react").Context<FormContext<TDraft, TOriginal> | null>;
77
+ context: import("../../react").Context<FormContext<TDraft, TOriginal> | null>;
78
78
  constructor(options: FormOptions<TDraft, TOriginal>);
79
79
  useForm(): FormContext<TDraft, TOriginal>;
80
80
  useFormState<S>(selector: (state: FormInstance<TDraft, TOriginal>) => S, useStoreOptions?: UseStoreOptions<S>): S;
@@ -1,6 +1,6 @@
1
1
  import { type PathAsString } from '../../index';
2
2
  import { type Value } from '../../lib/path';
3
- import { type Component, type ComponentPropsWithoutRef, type ReactNode } from 'react';
3
+ import { type Component, type ComponentPropsWithoutRef, type ReactNode } from '../../react';
4
4
  import { type Form } from './form';
5
5
  export interface FormFieldComponentProps<TValue, TPath> {
6
6
  name: TPath;
@@ -59,5 +59,5 @@ export type FormFieldPropsWithComponent<TDraft, TPath extends PathAsString<TDraf
59
59
  } : {
60
60
  deserialize: (value: FieldChangeValue<TComponent>) => Value<TDraft, TPath>;
61
61
  });
62
- export declare function FormField<TDraft, TPath extends PathAsString<TDraft>, TComponent extends FormFieldComponent>(this: Form<TDraft, any>, { name, component, commitOnBlur, commitDebounce, render, inputFilter, defaultValue, serialize, deserialize, ...restProps }: FormFieldPropsWithRender<TDraft, TPath> | FormFieldPropsWithComponent<TDraft, TPath, TComponent>): string | number | boolean | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null;
62
+ export declare function FormField<TDraft, TPath extends PathAsString<TDraft>, TComponent extends FormFieldComponent>(this: Form<TDraft, any>, { name, component, commitOnBlur, commitDebounce, render, inputFilter, defaultValue, serialize, deserialize, ...restProps }: FormFieldPropsWithRender<TDraft, TPath> | FormFieldPropsWithComponent<TDraft, TPath, TComponent>): string | number | boolean | import("../../react").ReactElement<any, string | import("../../react").JSXElementConstructor<any>> | Iterable<ReactNode> | null;
63
63
  export {};
@@ -1,5 +1,5 @@
1
1
  import { type GetKeys, type Join, type PathAsString, type Value } from '../../lib/path';
2
- import { type ReactNode } from 'react';
2
+ import { type ReactNode } from '../../react';
3
3
  import { type FieldHelperMethods, type Form } from './form';
4
4
  export type ForEachPath<T> = PathAsString<T>;
5
5
  export type ElementName<TDraft, TPath extends PathAsString<TDraft>> = Join<TPath, GetKeys<NonNullable<Value<TDraft, TPath>>> & (string | number)>;
@@ -1,4 +1,4 @@
1
- import { type ReactNode } from 'react';
1
+ import { type ReactNode } from '../react';
2
2
  export interface LoadingBoundaryEntry {
3
3
  label?: ReactNode;
4
4
  }
@@ -15,7 +15,7 @@ declare module '../core' {
15
15
  }
16
16
  }
17
17
  declare const cacheMethods: {
18
- useCache<T>(this: Cache<T>, options?: UseCacheOptions<T> | undefined): import("./useCache").UseCacheValue<T>;
18
+ useCache<T>(this: Cache<T>, options?: UseCacheOptions<T>): import("./useCache").UseCacheValue<T>;
19
19
  };
20
20
  declare const scopeMethods: {
21
21
  useScope<T>(this: Scope<T>): Store<T>;
@@ -1,4 +1,4 @@
1
- import type { Context, ReactNode } from 'react';
1
+ import type { Context, ReactNode } from '../react';
2
2
  import { type UseStoreOptions } from './useStore';
3
3
  import type { Store } from '../core/store';
4
4
  import type { Scope } from '../core';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-state",
3
- "version": "0.34.3",
3
+ "version": "0.35.0",
4
4
  "description": "(React) state library",
5
5
  "license": "ISC",
6
6
  "repository": "schummar/cross-state",
@@ -11,9 +11,11 @@
11
11
  "type": "module",
12
12
  "sideEffects": [
13
13
  "dist/es/react/register.mjs",
14
- "dist/es/immer/register.mjs",
14
+ "dist/es/mutative/register.mjs",
15
15
  "dist/cjs/react/register.cjs",
16
- "dist/cjs/immer/register.cjs"
16
+ "dist/cjs/mutative/register.cjs",
17
+ "dist/es/patches/register.mjs",
18
+ "dist/cjs/patches/register.cjs"
17
19
  ],
18
20
  "files": [
19
21
  "dist"
@@ -40,17 +42,29 @@
40
42
  "require": "./dist/cjs/react/register.cjs",
41
43
  "default": "./dist/es/react/register.mjs"
42
44
  },
43
- "./immer": {
44
- "types": "./dist/types/immer/index.d.ts",
45
- "import": "./dist/es/immer/index.mjs",
46
- "require": "./dist/cjs/immer/index.cjs",
47
- "default": "./dist/es/immer/index.mjs"
48
- },
49
- "./immer/register": {
50
- "types": "./dist/types/immer/register.d.ts",
51
- "import": "./dist/es/immer/register.mjs",
52
- "require": "./dist/cjs/immer/register.cjs",
53
- "default": "./dist/es/immer/register.mjs"
45
+ "./mutative": {
46
+ "types": "./dist/types/mutative/index.d.ts",
47
+ "import": "./dist/es/mutative/index.mjs",
48
+ "require": "./dist/cjs/mutative/index.cjs",
49
+ "default": "./dist/es/mutative/index.mjs"
50
+ },
51
+ "./mutative/register": {
52
+ "types": "./dist/types/mutative/register.d.ts",
53
+ "import": "./dist/es/mutative/register.mjs",
54
+ "require": "./dist/cjs/mutative/register.cjs",
55
+ "default": "./dist/es/mutative/register.mjs"
56
+ },
57
+ "./patches": {
58
+ "types": "./dist/types/patches/index.d.ts",
59
+ "import": "./dist/es/patches/index.mjs",
60
+ "require": "./dist/cjs/patches/index.cjs",
61
+ "default": "./dist/es/patches/index.mjs"
62
+ },
63
+ "./patches/register": {
64
+ "types": "./dist/types/patches/register.d.ts",
65
+ "import": "./dist/es/patches/register.mjs",
66
+ "require": "./dist/cjs/patches/register.cjs",
67
+ "default": "./dist/es/patches/register.mjs"
54
68
  }
55
69
  },
56
70
  "typesVersions": {
@@ -64,11 +78,17 @@
64
78
  "react/register": [
65
79
  "dist/types/react/register.d.ts"
66
80
  ],
67
- "immer": [
68
- "dist/types/immer/index.d.ts"
81
+ "mutative": [
82
+ "dist/types/mutative/index.d.ts"
69
83
  ],
70
- "immer/register": [
71
- "dist/types/immer/register.d.ts"
84
+ "mutative/register": [
85
+ "dist/types/mutative/register.d.ts"
86
+ ],
87
+ "patches": [
88
+ "dist/types/patches/index.d.ts"
89
+ ],
90
+ "patches/register": [
91
+ "dist/types/patches/register.d.ts"
72
92
  ]
73
93
  }
74
94
  },
@@ -91,14 +111,14 @@
91
111
  },
92
112
  "peerDependencies": {
93
113
  "@types/react": ">=16.8.0",
94
- "immer": ">=9.0.0",
114
+ "mutative": ">=1.0.3",
95
115
  "react": ">=16.8.0"
96
116
  },
97
117
  "peerDependenciesMeta": {
98
118
  "@types/react": {
99
119
  "optional": true
100
120
  },
101
- "immer": {
121
+ "mutative": {
102
122
  "optional": true
103
123
  },
104
124
  "react": {
@@ -107,25 +127,25 @@
107
127
  },
108
128
  "devDependencies": {
109
129
  "@emotion/styled": "11.11.0",
110
- "@mantine/core": "7.5.3",
111
- "@mui/material": "5.15.10",
130
+ "@mantine/core": "7.6.2",
131
+ "@mui/material": "5.15.12",
112
132
  "@schummar/eslint-config": "github:schummar/eslint-config",
113
133
  "@schummar/prettier-config": "github:schummar/prettier-config",
114
134
  "@schummar/runp": "2.0.2",
115
- "@size-limit/preset-small-lib": "11.0.2",
135
+ "@size-limit/preset-small-lib": "11.0.3",
116
136
  "@testing-library/react": "14.2.1",
117
- "@types/react": "18.2.57",
118
- "@types/react-dom": "18.2.19",
137
+ "@types/react": "18.2.65",
138
+ "@types/react-dom": "18.2.21",
119
139
  "@types/seedrandom": "3.0.8",
120
140
  "@types/use-sync-external-store": "0.0.6",
121
141
  "@types/ws": "8.5.10",
122
142
  "@vitejs/plugin-react": "4.2.1",
123
143
  "@vitest/coverage-v8": "1.3.1",
124
144
  "esbuild": "0.20.1",
125
- "eslint": "8.56.0",
126
- "happy-dom": "13.3.8",
127
- "immer": "10.0.3",
145
+ "eslint": "8.57.0",
146
+ "happy-dom": "13.8.2",
128
147
  "jsdom": "24.0.0",
148
+ "mutative": "1.0.3",
129
149
  "prettier": "3.2.5",
130
150
  "publint": "0.2.7",
131
151
  "react": "18.2.0",
@@ -133,11 +153,11 @@
133
153
  "rimraf": "5.0.5",
134
154
  "seedrandom": "3.0.5",
135
155
  "semantic-release": "23.0.2",
136
- "size-limit": "11.0.2",
156
+ "size-limit": "11.0.3",
137
157
  "tsc-alias": "1.8.8",
138
- "typescript": "5.3.3",
158
+ "typescript": "5.4.2",
139
159
  "use-sync-external-store": "1.2.0",
140
- "vite": "5.1.3",
160
+ "vite": "5.1.6",
141
161
  "vite-tsconfig-paths": "4.3.1",
142
162
  "vitest": "1.3.1"
143
163
  },
@@ -208,10 +228,15 @@
208
228
  "limit": "6 KB"
209
229
  },
210
230
  {
211
- "name": "/immer",
212
- "path": "dist/es/immer/index.mjs",
231
+ "name": "/mutative",
232
+ "path": "dist/es/mutative/index.mjs",
213
233
  "limit": "250 B"
214
234
  },
235
+ {
236
+ "name": "/patches",
237
+ "path": "dist/es/patches/index.mjs",
238
+ "limit": "2 KB"
239
+ },
215
240
  {
216
241
  "name": "empty",
217
242
  "path": "dist/es/index.mjs",
@@ -1,5 +0,0 @@
1
- "use strict";
2
- const immerMethods = require("../immerMethods.cjs");
3
- const store = require("../store.cjs");
4
- Object.assign(store.Store.prototype, immerMethods.immerMethods);
5
- //# sourceMappingURL=register.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"register.cjs","sources":["../../../src/immer/register.ts"],"sourcesContent":["import { immerMethods } from './immerMethods';\nimport { Store } from '@core';\n\ntype ImmerMethods = typeof immerMethods;\n\ndeclare module '@core' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> extends ImmerMethods {}\n}\n\nObject.assign(Store.prototype, immerMethods);\n"],"names":["Store","immerMethods"],"mappings":";;;AAUA,OAAO,OAAOA,MAAAA,MAAM,WAAWC,yBAAY;"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- const immer = require("immer");
3
- function update(...args) {
4
- if (args.length === 1) {
5
- this.set(
6
- (value) => immer.produce(value, (draft) => {
7
- args[0](draft);
8
- })
9
- );
10
- } else {
11
- this.set(
12
- args[0],
13
- (value) => immer.produce(value, (draft) => {
14
- args[1](draft);
15
- })
16
- );
17
- }
18
- }
19
- const immerMethods = {
20
- update
21
- };
22
- exports.immerMethods = immerMethods;
23
- //# sourceMappingURL=immerMethods.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"immerMethods.cjs","sources":["../../src/immer/immerMethods.ts"],"sourcesContent":["import type { Draft } from 'immer';\nimport { produce } from 'immer';\nimport type { Store } from '@core/store';\nimport { type Path, type Value } from '@lib/path';\n\ntype Recipe<T> = (draft: Draft<T>) => void;\n\nfunction update<T>(this: Store<T>, recipe: Recipe<T>): void;\n\nfunction update<T, const P extends Path<T>>(\n this: Store<T>,\n path: P,\n recipe: Recipe<Value<T, P>>,\n): void;\n\nfunction update<T, P extends Path<T>>(\n this: Store<T>,\n ...args: [recipe: Recipe<T>] | [P: P, recipe: Recipe<Value<T, P>>]\n) {\n if (args.length === 1) {\n this.set((value) =>\n produce(value, (draft) => {\n args[0](draft);\n }),\n );\n } else {\n this.set(args[0], (value) =>\n produce(value, (draft) => {\n args[1](draft);\n }),\n );\n }\n}\n\nexport const immerMethods = {\n update,\n};\n"],"names":["produce"],"mappings":";;AAeA,SAAS,UAEJ,MACH;AACI,MAAA,KAAK,WAAW,GAAG;AAChB,SAAA;AAAA,MAAI,CAAC,UACRA,MAAAA,QAAQ,OAAO,CAAC,UAAU;AACnB,aAAA,CAAC,EAAE,KAAK;AAAA,MAAA,CACd;AAAA,IAAA;AAAA,EACH,OACK;AACA,SAAA;AAAA,MAAI,KAAK,CAAC;AAAA,MAAG,CAAC,UACjBA,MAAAA,QAAQ,OAAO,CAAC,UAAU;AACnB,aAAA,CAAC,EAAE,KAAK;AAAA,MAAA,CACd;AAAA,IAAA;AAAA,EAEL;AACF;AAEO,MAAM,eAAe;AAAA,EAC1B;AACF;;"}
@@ -1,5 +0,0 @@
1
- import { i } from "../immerMethods.mjs";
2
- export {
3
- i as immerMethods
4
- };
5
- //# sourceMappingURL=index.mjs.map
@@ -1,4 +0,0 @@
1
- import { i as immerMethods } from "../immerMethods.mjs";
2
- import { S as Store } from "../store.mjs";
3
- Object.assign(Store.prototype, immerMethods);
4
- //# sourceMappingURL=register.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"register.mjs","sources":["../../../src/immer/register.ts"],"sourcesContent":["import { immerMethods } from './immerMethods';\nimport { Store } from '@core';\n\ntype ImmerMethods = typeof immerMethods;\n\ndeclare module '@core' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> extends ImmerMethods {}\n}\n\nObject.assign(Store.prototype, immerMethods);\n"],"names":[],"mappings":";;AAUA,OAAO,OAAO,MAAM,WAAW,YAAY;"}
@@ -1,24 +0,0 @@
1
- import { produce } from "immer";
2
- function update(...args) {
3
- if (args.length === 1) {
4
- this.set(
5
- (value) => produce(value, (draft) => {
6
- args[0](draft);
7
- })
8
- );
9
- } else {
10
- this.set(
11
- args[0],
12
- (value) => produce(value, (draft) => {
13
- args[1](draft);
14
- })
15
- );
16
- }
17
- }
18
- const immerMethods = {
19
- update
20
- };
21
- export {
22
- immerMethods as i
23
- };
24
- //# sourceMappingURL=immerMethods.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"immerMethods.mjs","sources":["../../src/immer/immerMethods.ts"],"sourcesContent":["import type { Draft } from 'immer';\nimport { produce } from 'immer';\nimport type { Store } from '@core/store';\nimport { type Path, type Value } from '@lib/path';\n\ntype Recipe<T> = (draft: Draft<T>) => void;\n\nfunction update<T>(this: Store<T>, recipe: Recipe<T>): void;\n\nfunction update<T, const P extends Path<T>>(\n this: Store<T>,\n path: P,\n recipe: Recipe<Value<T, P>>,\n): void;\n\nfunction update<T, P extends Path<T>>(\n this: Store<T>,\n ...args: [recipe: Recipe<T>] | [P: P, recipe: Recipe<Value<T, P>>]\n) {\n if (args.length === 1) {\n this.set((value) =>\n produce(value, (draft) => {\n args[0](draft);\n }),\n );\n } else {\n this.set(args[0], (value) =>\n produce(value, (draft) => {\n args[1](draft);\n }),\n );\n }\n}\n\nexport const immerMethods = {\n update,\n};\n"],"names":[],"mappings":";AAeA,SAAS,UAEJ,MACH;AACI,MAAA,KAAK,WAAW,GAAG;AAChB,SAAA;AAAA,MAAI,CAAC,UACR,QAAQ,OAAO,CAAC,UAAU;AACnB,aAAA,CAAC,EAAE,KAAK;AAAA,MAAA,CACd;AAAA,IAAA;AAAA,EACH,OACK;AACA,SAAA;AAAA,MAAI,KAAK,CAAC;AAAA,MAAG,CAAC,UACjB,QAAQ,OAAO,CAAC,UAAU;AACnB,aAAA,CAAC,EAAE,KAAK;AAAA,MAAA,CACd;AAAA,IAAA;AAAA,EAEL;AACF;AAEO,MAAM,eAAe;AAAA,EAC1B;AACF;"}
@@ -1,10 +0,0 @@
1
- import type { Draft } from 'immer';
2
- import type { Store } from '../core/store';
3
- import { type Path, type Value } from '../lib/path';
4
- type Recipe<T> = (draft: Draft<T>) => void;
5
- declare function update<T>(this: Store<T>, recipe: Recipe<T>): void;
6
- declare function update<T, const P extends Path<T>>(this: Store<T>, path: P, recipe: Recipe<Value<T, P>>): void;
7
- export declare const immerMethods: {
8
- update: typeof update;
9
- };
10
- export {};
@@ -1 +0,0 @@
1
- export { immerMethods } from './immerMethods';
@@ -1,7 +0,0 @@
1
- import { immerMethods } from './immerMethods';
2
- type ImmerMethods = typeof immerMethods;
3
- declare module '../core' {
4
- interface Store<T> extends ImmerMethods {
5
- }
6
- }
7
- export {};
@@ -1 +0,0 @@
1
- export * from './sync';
@@ -1,17 +0,0 @@
1
- import { type Store } from '../core';
2
- import { type Patch } from '../lib/diff';
3
- export interface Message<T> {
4
- id: string;
5
- previousId?: string;
6
- patches: Patch[];
7
- }
8
- export declare class Sync<T> {
9
- readonly store: Store<T>;
10
- private previousId;
11
- private previousState;
12
- private patchStream;
13
- constructor(store: Store<T>);
14
- connectToClient(listener: (message: Message<T>) => void): import("../core").DisposableCancel;
15
- connectToServer(stream: AsyncIterable<Message<T>>): Promise<void>;
16
- }
17
- export declare function createSync<T>(store: Store<T>): Sync<T>;
File without changes
File without changes