cx 26.4.2 → 26.4.4
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.
- package/build/data/AugmentedViewBase.d.ts.map +1 -1
- package/build/data/AugmentedViewBase.js +5 -4
- package/build/data/View.d.ts +0 -1
- package/build/data/View.d.ts.map +1 -1
- package/build/data/View.js +1 -3
- package/build/jsx-dev-runtime.d.ts +1 -0
- package/build/jsx-dev-runtime.d.ts.map +1 -1
- package/build/jsx-dev-runtime.js +1 -0
- package/build/widgets/form/LookupField.js +2 -1
- package/dist/data.js +5 -4
- package/dist/manifest.js +809 -809
- package/dist/widgets.css +9 -3
- package/dist/widgets.js +5 -1
- package/package.json +1 -1
- package/src/data/AugmentedViewBase.ts +89 -88
- package/src/data/View.ts +301 -346
- package/src/jsx-dev-runtime.ts +1 -0
- package/src/widgets/form/LookupField.scss +234 -227
- package/src/widgets/form/LookupField.tsx +4 -1
package/src/data/View.ts
CHANGED
|
@@ -1,346 +1,301 @@
|
|
|
1
|
-
import { Binding } from "./Binding";
|
|
2
|
-
import { isArray } from "../util/isArray";
|
|
3
|
-
import { isDefined } from "../util/isDefined";
|
|
4
|
-
import { StoreRef } from "./StoreRef";
|
|
5
|
-
import { isObject } from "../util/isObject";
|
|
6
|
-
import { isFunction } from "../util/isFunction";
|
|
7
|
-
import { AccessorChain } from "./createAccessorModelProxy";
|
|
8
|
-
import { Ref } from "./Ref";
|
|
9
|
-
|
|
10
|
-
type Path = string | Binding;
|
|
11
|
-
|
|
12
|
-
export interface ViewConfig {
|
|
13
|
-
store?: View;
|
|
14
|
-
immutable?: boolean;
|
|
15
|
-
sealed?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface ViewMethods<D = Record<string, any>> {
|
|
19
|
-
getData(): D;
|
|
20
|
-
|
|
21
|
-
init(path: Path, value: unknown): boolean;
|
|
22
|
-
init<V>(path: AccessorChain<V>, value: V): boolean;
|
|
23
|
-
init<T extends Record<string, unknown>>(initObject: T): boolean;
|
|
24
|
-
|
|
25
|
-
set(path: Path, value: any): boolean;
|
|
26
|
-
set<T extends Record<string, any>>(changes: T): boolean;
|
|
27
|
-
set<V>(path: AccessorChain<V>, value: V): boolean;
|
|
28
|
-
|
|
29
|
-
get(path: Path): any;
|
|
30
|
-
get(paths: Path[]): any[];
|
|
31
|
-
get(...paths: Path[]): any[];
|
|
32
|
-
get<V>(path: AccessorChain<V>): V;
|
|
33
|
-
get<T extends any[]>(...paths: { [K in keyof T]: AccessorChain<T[K]> }): T;
|
|
34
|
-
get<T extends any[]>(paths: { [K in keyof T]: AccessorChain<T[K]> }): T;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Removes data from the Store.
|
|
38
|
-
* @param paths - One or more paths to be deleted.
|
|
39
|
-
* @return {boolean}
|
|
40
|
-
*/
|
|
41
|
-
delete(path: Path): boolean;
|
|
42
|
-
delete(paths: Path[]): boolean;
|
|
43
|
-
delete(...paths: Path[]): boolean;
|
|
44
|
-
delete<V>(path: AccessorChain<V>): boolean;
|
|
45
|
-
delete<T extends any[]>(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
): boolean;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return this.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
):
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}):
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
):
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
load(data: Record<string, any>): boolean {
|
|
305
|
-
return this.set(data);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
dispatch(action: any): void {
|
|
309
|
-
if (this.store) return this.store.dispatch(action);
|
|
310
|
-
|
|
311
|
-
throw new Error("The underlying store doesn't support dispatch.");
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
getMeta() {
|
|
315
|
-
return this.meta;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
setStore(store: View) {
|
|
319
|
-
this.store = store;
|
|
320
|
-
this.meta = store.getMeta();
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
ref<T = any>(path: string | AccessorChain<T>, defaultValue?: T): Ref<T> {
|
|
324
|
-
if (isDefined(defaultValue)) this.init(path as any, defaultValue);
|
|
325
|
-
return StoreRef.create({
|
|
326
|
-
store: this,
|
|
327
|
-
path,
|
|
328
|
-
}) as Ref<T>;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
getMethods(): ViewMethods<D> {
|
|
332
|
-
return {
|
|
333
|
-
getData: this.getData.bind(this),
|
|
334
|
-
set: this.set.bind(this),
|
|
335
|
-
get: this.get.bind(this),
|
|
336
|
-
update: this.update.bind(this),
|
|
337
|
-
delete: this.delete.bind(this),
|
|
338
|
-
toggle: this.toggle.bind(this),
|
|
339
|
-
init: this.init.bind(this),
|
|
340
|
-
ref: this.ref.bind(this),
|
|
341
|
-
mutate: this.mutate.bind(this),
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
View.prototype.sealed = false; //indicate that data should be copied before virtual items are added
|
|
1
|
+
import { Binding } from "./Binding";
|
|
2
|
+
import { isArray } from "../util/isArray";
|
|
3
|
+
import { isDefined } from "../util/isDefined";
|
|
4
|
+
import { StoreRef } from "./StoreRef";
|
|
5
|
+
import { isObject } from "../util/isObject";
|
|
6
|
+
import { isFunction } from "../util/isFunction";
|
|
7
|
+
import { AccessorChain } from "./createAccessorModelProxy";
|
|
8
|
+
import { Ref } from "./Ref";
|
|
9
|
+
|
|
10
|
+
type Path = string | Binding;
|
|
11
|
+
|
|
12
|
+
export interface ViewConfig {
|
|
13
|
+
store?: View;
|
|
14
|
+
immutable?: boolean;
|
|
15
|
+
sealed?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ViewMethods<D = Record<string, any>> {
|
|
19
|
+
getData(): D;
|
|
20
|
+
|
|
21
|
+
init(path: Path, value: unknown): boolean;
|
|
22
|
+
init<V>(path: AccessorChain<V>, value: V): boolean;
|
|
23
|
+
init<T extends Record<string, unknown>>(initObject: T): boolean;
|
|
24
|
+
|
|
25
|
+
set(path: Path, value: any): boolean;
|
|
26
|
+
set<T extends Record<string, any>>(changes: T): boolean;
|
|
27
|
+
set<V>(path: AccessorChain<V>, value: V): boolean;
|
|
28
|
+
|
|
29
|
+
get(path: Path): any;
|
|
30
|
+
get(paths: Path[]): any[];
|
|
31
|
+
get(...paths: Path[]): any[];
|
|
32
|
+
get<V>(path: AccessorChain<V>): V;
|
|
33
|
+
get<T extends any[]>(...paths: { [K in keyof T]: AccessorChain<T[K]> }): T;
|
|
34
|
+
get<T extends any[]>(paths: { [K in keyof T]: AccessorChain<T[K]> }): T;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Removes data from the Store.
|
|
38
|
+
* @param paths - One or more paths to be deleted.
|
|
39
|
+
* @return {boolean}
|
|
40
|
+
*/
|
|
41
|
+
delete(path: Path): boolean;
|
|
42
|
+
delete(paths: Path[]): boolean;
|
|
43
|
+
delete(...paths: Path[]): boolean;
|
|
44
|
+
delete<V>(path: AccessorChain<V>): boolean;
|
|
45
|
+
delete<T extends any[]>(...paths: { [K in keyof T]: AccessorChain<T[K]> }): boolean;
|
|
46
|
+
delete<T extends any[]>(paths: {
|
|
47
|
+
[K in keyof T]: AccessorChain<T[K]>;
|
|
48
|
+
}): boolean;
|
|
49
|
+
|
|
50
|
+
toggle(path: Path): boolean;
|
|
51
|
+
toggle(path: AccessorChain<boolean>): boolean;
|
|
52
|
+
|
|
53
|
+
update<V>(path: AccessorChain<V>, updateFn: (currentValue: V) => V): boolean;
|
|
54
|
+
update<V, A extends any[]>(
|
|
55
|
+
path: AccessorChain<V>,
|
|
56
|
+
updateFn: (currentValue: V, ...args: A) => V,
|
|
57
|
+
...args: A
|
|
58
|
+
): boolean;
|
|
59
|
+
update<A extends any[]>(updateFn: (currentValue: D, ...args: A) => D, ...args: any): boolean;
|
|
60
|
+
update<A extends any[]>(path: Path, updateFn: (currentValue: any, ...args: A) => any, ...args: A): boolean;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Mutates the content of the store using Immer
|
|
64
|
+
*/
|
|
65
|
+
mutate(updateFn: (currentValue: D, ...args: any[]) => void, ...args: any[]): boolean;
|
|
66
|
+
mutate<A extends any[]>(path: Path, updateFn: (currentValue: any, ...args: A) => void, ...args: A): boolean;
|
|
67
|
+
mutate<V, A extends any[]>(
|
|
68
|
+
path: AccessorChain<V>,
|
|
69
|
+
updateFn: (currentValue: V, ...args: A) => void,
|
|
70
|
+
...args: A
|
|
71
|
+
): boolean;
|
|
72
|
+
|
|
73
|
+
ref<T = any>(path: string | AccessorChain<T>, defaultValue?: T): Ref<T>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class View<D = any> implements ViewMethods<D> {
|
|
77
|
+
declare store?: View;
|
|
78
|
+
declare meta: any;
|
|
79
|
+
declare sealed: boolean;
|
|
80
|
+
cache: {
|
|
81
|
+
version: number;
|
|
82
|
+
data?: any;
|
|
83
|
+
result?: any;
|
|
84
|
+
itemIndex?: number;
|
|
85
|
+
key?: string;
|
|
86
|
+
};
|
|
87
|
+
notificationsSuspended: number = 0;
|
|
88
|
+
dirty: boolean = false;
|
|
89
|
+
|
|
90
|
+
constructor(config?: ViewConfig) {
|
|
91
|
+
Object.assign(this, config);
|
|
92
|
+
this.cache = {
|
|
93
|
+
version: -1,
|
|
94
|
+
};
|
|
95
|
+
if (this.store) this.setStore(this.store);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getData(): D {
|
|
99
|
+
throw new Error("abstract method");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
init(path: Path, value: unknown): boolean;
|
|
103
|
+
init<V>(path: AccessorChain<V>, value: V): boolean;
|
|
104
|
+
init<T extends Record<string, unknown>>(initObject: T): boolean;
|
|
105
|
+
init(path: any, value?: any): boolean {
|
|
106
|
+
if (typeof path == "object" && path != null) {
|
|
107
|
+
let changed = false;
|
|
108
|
+
for (let key in path)
|
|
109
|
+
if (path.hasOwnProperty(key) && this.get(key) === undefined && this.setItem(key, path[key])) changed = true;
|
|
110
|
+
return changed;
|
|
111
|
+
}
|
|
112
|
+
let binding = Binding.get(path);
|
|
113
|
+
if (this.get(binding.path) === undefined) return this.setItem(binding.path, value);
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
set(path: Path, value: any): boolean;
|
|
118
|
+
set<T extends Record<string, any>>(changes: T): boolean;
|
|
119
|
+
set<V>(path: AccessorChain<V>, value: V): boolean;
|
|
120
|
+
set(path: any, value?: any): boolean {
|
|
121
|
+
if (typeof path == "object" && path != null) {
|
|
122
|
+
let changed = false;
|
|
123
|
+
for (let key in path) if (path.hasOwnProperty(key) && this.setItem(key, path[key])) changed = true;
|
|
124
|
+
return changed;
|
|
125
|
+
}
|
|
126
|
+
let binding = Binding.get(path);
|
|
127
|
+
return this.setItem(binding.path, value);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
copy(from: Path, to: Path): boolean;
|
|
131
|
+
copy<V>(from: AccessorChain<V>, to: AccessorChain<V>): boolean;
|
|
132
|
+
copy(from: any, to: any): boolean {
|
|
133
|
+
let value = this.get(from);
|
|
134
|
+
return this.set(to, value);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
move(from: Path, to: Path): boolean;
|
|
138
|
+
move<V>(from: AccessorChain<V>, to: AccessorChain<V>): boolean;
|
|
139
|
+
move(from: any, to: any): boolean {
|
|
140
|
+
return this.batch(() => {
|
|
141
|
+
this.copy(from, to);
|
|
142
|
+
this.delete(from);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
//protected
|
|
147
|
+
setItem(path: string, value: any): boolean {
|
|
148
|
+
if (this.store) return this.store.setItem(path, value);
|
|
149
|
+
throw new Error("abstract method");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
delete(path: Path): boolean;
|
|
153
|
+
delete(paths: Path[]): boolean;
|
|
154
|
+
delete(...paths: Path[]): boolean;
|
|
155
|
+
delete<V>(path: AccessorChain<V>): boolean;
|
|
156
|
+
delete<T extends any[]>(...paths: { [K in keyof T]: AccessorChain<T[K]> }): boolean;
|
|
157
|
+
delete<T extends any[]>(paths: {
|
|
158
|
+
[K in keyof T]: AccessorChain<T[K]>;
|
|
159
|
+
}): boolean;
|
|
160
|
+
delete(path?: any): boolean {
|
|
161
|
+
if (arguments.length > 1) path = Array.from(arguments);
|
|
162
|
+
if (isArray(path)) return path.map((arg) => this.delete(arg as Path)).some(Boolean);
|
|
163
|
+
|
|
164
|
+
let binding = Binding.get(path);
|
|
165
|
+
return this.deleteItem(binding.path);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//protected
|
|
169
|
+
deleteItem(path: string): boolean {
|
|
170
|
+
if (this.store) return this.store.deleteItem(path);
|
|
171
|
+
|
|
172
|
+
throw new Error("abstract method");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
clear(): void {
|
|
176
|
+
if (this.store) return this.store.clear();
|
|
177
|
+
|
|
178
|
+
throw new Error("abstract method");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
get(path: Path): any;
|
|
182
|
+
get(paths: Path[]): any[];
|
|
183
|
+
get(...paths: Path[]): any[];
|
|
184
|
+
get<V>(path: AccessorChain<V>): V;
|
|
185
|
+
get<T extends any[]>(...paths: { [K in keyof T]: AccessorChain<T[K]> }): T;
|
|
186
|
+
get<T extends any[]>(paths: { [K in keyof T]: AccessorChain<T[K]> }): T;
|
|
187
|
+
get(path?: any, ...args: any[]): any {
|
|
188
|
+
let storeData = this.getData();
|
|
189
|
+
|
|
190
|
+
if (arguments.length > 1) path = Array.from(arguments);
|
|
191
|
+
|
|
192
|
+
if (isArray(path)) return path.map((arg) => Binding.get(arg as any).value(storeData));
|
|
193
|
+
|
|
194
|
+
return Binding.get(path).value(storeData);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
toggle(path: Path): boolean;
|
|
198
|
+
toggle(path: AccessorChain<boolean>): boolean;
|
|
199
|
+
toggle(path: any): boolean {
|
|
200
|
+
return this.set(path, !this.get(path));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
update<V>(path: AccessorChain<V>, updateFn: (currentValue: V) => V): boolean;
|
|
204
|
+
update<V, A extends any[]>(
|
|
205
|
+
path: AccessorChain<V>,
|
|
206
|
+
updateFn: (currentValue: V, ...args: A) => V,
|
|
207
|
+
...args: A
|
|
208
|
+
): boolean;
|
|
209
|
+
update(updateFn: (currentValue: D, ...args: any[]) => any, ...args: any): boolean;
|
|
210
|
+
update<A extends any[]>(path: Path, updateFn: (currentValue: any, ...args: A) => any, ...args: A): boolean;
|
|
211
|
+
update(path: any, updateFn?: any, ...args: any[]): boolean {
|
|
212
|
+
if (arguments.length == 1 && isFunction(path))
|
|
213
|
+
return this.load(path.apply(null, [this.getData(), updateFn, ...args]));
|
|
214
|
+
return this.set(path, updateFn.apply(null, [this.get(path), ...args]));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
mutate(updateFn: (currentValue: D, ...args: any[]) => void, ...args: any[]): boolean;
|
|
218
|
+
mutate<A extends any[]>(path: Path, updateFn: (currentValue: any, ...args: A) => void, ...args: A): boolean;
|
|
219
|
+
mutate<V, A extends any[]>(
|
|
220
|
+
path: AccessorChain<V>,
|
|
221
|
+
updateFn: (currentValue: V, ...args: A) => void,
|
|
222
|
+
...args: A
|
|
223
|
+
): boolean;
|
|
224
|
+
mutate(path?: any, updateFn?: any, ...args: any[]): boolean {
|
|
225
|
+
throw new Error(
|
|
226
|
+
"Mutate requires Immer. Please install 'immer' and 'cx-immer' packages and enable store mutation by calling enableImmerMutate().",
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
batch(callback: (store?: View) => void): boolean {
|
|
231
|
+
let dirty = this.silently(callback);
|
|
232
|
+
if (dirty) this.notify();
|
|
233
|
+
return dirty;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
silently(callback: (store?: View) => void): boolean {
|
|
237
|
+
if (this.store) return this.store.silently(callback);
|
|
238
|
+
|
|
239
|
+
throw new Error("abstract method");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
notify(path?: string): void {
|
|
243
|
+
if (this.notificationsSuspended) this.dirty = true;
|
|
244
|
+
else this.doNotify(path);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
doNotify(path?: string): void {
|
|
248
|
+
if (this.store) return this.store.notify(path);
|
|
249
|
+
|
|
250
|
+
throw new Error("abstract method");
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
subscribe(callback: (changes?: any) => void): () => void {
|
|
254
|
+
if (this.store) return this.store.subscribe(callback);
|
|
255
|
+
|
|
256
|
+
throw new Error("abstract method");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
load(data: Record<string, any>): boolean {
|
|
260
|
+
return this.set(data);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
dispatch(action: any): void {
|
|
264
|
+
if (this.store) return this.store.dispatch(action);
|
|
265
|
+
|
|
266
|
+
throw new Error("The underlying store doesn't support dispatch.");
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
getMeta() {
|
|
270
|
+
return this.meta;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
setStore(store: View) {
|
|
274
|
+
this.store = store;
|
|
275
|
+
this.meta = store.getMeta();
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
ref<T = any>(path: string | AccessorChain<T>, defaultValue?: T): Ref<T> {
|
|
279
|
+
if (isDefined(defaultValue)) this.init(path as any, defaultValue);
|
|
280
|
+
return StoreRef.create({
|
|
281
|
+
store: this,
|
|
282
|
+
path,
|
|
283
|
+
}) as Ref<T>;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
getMethods(): ViewMethods<D> {
|
|
287
|
+
return {
|
|
288
|
+
getData: this.getData.bind(this),
|
|
289
|
+
set: this.set.bind(this),
|
|
290
|
+
get: this.get.bind(this),
|
|
291
|
+
update: this.update.bind(this),
|
|
292
|
+
delete: this.delete.bind(this),
|
|
293
|
+
toggle: this.toggle.bind(this),
|
|
294
|
+
init: this.init.bind(this),
|
|
295
|
+
ref: this.ref.bind(this),
|
|
296
|
+
mutate: this.mutate.bind(this),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
View.prototype.sealed = false; //indicate that data should be copied before virtual items are added
|
package/src/jsx-dev-runtime.ts
CHANGED