as-model 0.1.16 → 0.1.18
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/README.md +483 -483
- package/dist/index.js +176 -92
- package/esm/key/index.js +1 -2
- package/esm/store/index.js +25 -0
- package/esm/tools/index.js +13 -1
- package/esm/updater/index.js +9 -6
- package/esm/updater/notifier.js +21 -6
- package/esm/validation/index.js +5 -1
- package/index.d.ts +298 -298
- package/package.json +68 -68
package/dist/index.js
CHANGED
|
@@ -55,6 +55,37 @@
|
|
|
55
55
|
return target;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
// node_modules/@swc/helpers/esm/_object_without_properties_loose.js
|
|
59
|
+
function _object_without_properties_loose(source, excluded) {
|
|
60
|
+
if (source == null) return {};
|
|
61
|
+
var target = {};
|
|
62
|
+
var sourceKeys = Object.keys(source);
|
|
63
|
+
var key, i;
|
|
64
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
65
|
+
key = sourceKeys[i];
|
|
66
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
67
|
+
target[key] = source[key];
|
|
68
|
+
}
|
|
69
|
+
return target;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// node_modules/@swc/helpers/esm/_object_without_properties.js
|
|
73
|
+
function _object_without_properties(source, excluded) {
|
|
74
|
+
if (source == null) return {};
|
|
75
|
+
var target = _object_without_properties_loose(source, excluded);
|
|
76
|
+
var key, i;
|
|
77
|
+
if (Object.getOwnPropertySymbols) {
|
|
78
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
79
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
80
|
+
key = sourceSymbolKeys[i];
|
|
81
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
82
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
83
|
+
target[key] = source[key];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return target;
|
|
87
|
+
}
|
|
88
|
+
|
|
58
89
|
// node_modules/@swc/helpers/esm/_array_like_to_array.js
|
|
59
90
|
function _array_like_to_array(arr, len) {
|
|
60
91
|
if (len == null || len > arr.length) len = arr.length;
|
|
@@ -153,6 +184,96 @@
|
|
|
153
184
|
isModelUsage
|
|
154
185
|
};
|
|
155
186
|
|
|
187
|
+
// src/tools/proxy.ts
|
|
188
|
+
function getDescriptors(target, receiver, ownOrPrototype, handler) {
|
|
189
|
+
var it = Object.keys(ownOrPrototype);
|
|
190
|
+
var result = {};
|
|
191
|
+
it.forEach(function(key) {
|
|
192
|
+
result[key] = {
|
|
193
|
+
get: function() {
|
|
194
|
+
if (!handler.get) {
|
|
195
|
+
return target[key];
|
|
196
|
+
}
|
|
197
|
+
return handler.get(target, key, receiver);
|
|
198
|
+
},
|
|
199
|
+
set: function(v) {
|
|
200
|
+
if (!handler.set) {
|
|
201
|
+
target[key] = v;
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
var valid = handler.set(target, key, v, receiver);
|
|
205
|
+
if (!valid) {
|
|
206
|
+
throw new Error("".concat(key, " in proxy target is not mutable"));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
var createSimpleProxy = function(target, handler) {
|
|
214
|
+
var proxy = {};
|
|
215
|
+
var own = getDescriptors(target, proxy, target, handler);
|
|
216
|
+
var prototype = getDescriptors(target, proxy, Object.getPrototypeOf(target), handler);
|
|
217
|
+
Object.defineProperties(proxy, _object_spread({}, prototype, own));
|
|
218
|
+
return proxy;
|
|
219
|
+
};
|
|
220
|
+
var createProxy = function(target, handler) {
|
|
221
|
+
if (typeof Proxy !== "function") {
|
|
222
|
+
return createSimpleProxy(target, handler);
|
|
223
|
+
}
|
|
224
|
+
return new Proxy(target, handler);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// src/tools/shallowEqual.ts
|
|
228
|
+
function isObject(data) {
|
|
229
|
+
return data && (typeof data === "undefined" ? "undefined" : _type_of(data)) === "object";
|
|
230
|
+
}
|
|
231
|
+
function shallowEqual(prev, current) {
|
|
232
|
+
if (Object.is(prev, current)) {
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
if (!isObject(prev) || !isObject(current)) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
var prevKeys = Object.keys(prev);
|
|
239
|
+
var currentKeys = Object.keys(current);
|
|
240
|
+
if (prevKeys.length !== currentKeys.length) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
var pre = prev;
|
|
244
|
+
var curr = current;
|
|
245
|
+
var hasDiffKey = prevKeys.some(function(key) {
|
|
246
|
+
return !Object.prototype.hasOwnProperty.call(curr, key);
|
|
247
|
+
});
|
|
248
|
+
if (hasDiffKey) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
var hasDiffValue = currentKeys.some(function(key) {
|
|
252
|
+
var currentValue = curr[key];
|
|
253
|
+
var prevValue = pre[key];
|
|
254
|
+
return !Object.is(currentValue, prevValue);
|
|
255
|
+
});
|
|
256
|
+
return !hasDiffValue;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/tools/index.ts
|
|
260
|
+
function noop() {
|
|
261
|
+
}
|
|
262
|
+
function simpleErrorProcess(errors) {
|
|
263
|
+
return function wrap(callback) {
|
|
264
|
+
return function replaced() {
|
|
265
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
266
|
+
args[_key] = arguments[_key];
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
return callback.apply(void 0, _to_consumable_array(args));
|
|
270
|
+
} catch (e) {
|
|
271
|
+
errors.push(e);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
156
277
|
// src/updater/notifier.ts
|
|
157
278
|
function defaultNotifyImplement(dispatches, action) {
|
|
158
279
|
dispatches.forEach(function(callback) {
|
|
@@ -228,10 +349,8 @@
|
|
|
228
349
|
call(initializedAction);
|
|
229
350
|
});
|
|
230
351
|
}
|
|
231
|
-
var config2 = updater.config, model2 = updater.model;
|
|
232
352
|
var dispatch = function dispatch2(action) {
|
|
233
|
-
var dispatches = updater.dispatches, controlled = updater.controlled;
|
|
234
|
-
var dispatchCallbacks = _to_consumable_array(dispatches);
|
|
353
|
+
var dispatches = updater.dispatches, controlled = updater.controlled, model2 = updater.model, config2 = updater.config;
|
|
235
354
|
var state = action.state;
|
|
236
355
|
var nextInstance = model2(state);
|
|
237
356
|
var nextAction = _object_spread_props(_object_spread({}, action), {
|
|
@@ -246,11 +365,31 @@
|
|
|
246
365
|
});
|
|
247
366
|
});
|
|
248
367
|
}
|
|
368
|
+
var notifyAction = function notifyAction2(act) {
|
|
369
|
+
var errors = [];
|
|
370
|
+
var dispatchCallbacks = dispatches.map(simpleErrorProcess(errors));
|
|
371
|
+
defaultNotifyImplement(dispatchCallbacks, act);
|
|
372
|
+
if (!errors.length) {
|
|
373
|
+
return {
|
|
374
|
+
errors: void 0
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
errors
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
var notifyActionWithErrorThrow = function notifyActionWithErrorThrow2(act) {
|
|
382
|
+
var errors = notifyAction(act).errors;
|
|
383
|
+
if (!errors || !errors.length) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
throw errors[0];
|
|
387
|
+
};
|
|
249
388
|
try {
|
|
250
|
-
if (typeof config2.
|
|
251
|
-
config2.
|
|
389
|
+
if (typeof config2.notify === "function") {
|
|
390
|
+
config2.notify(notifyAction, nextAction);
|
|
252
391
|
} else {
|
|
253
|
-
|
|
392
|
+
notifyActionWithErrorThrow(nextAction);
|
|
254
393
|
}
|
|
255
394
|
} catch (e) {
|
|
256
395
|
updater.mutate(function(u) {
|
|
@@ -295,82 +434,6 @@
|
|
|
295
434
|
};
|
|
296
435
|
}
|
|
297
436
|
|
|
298
|
-
// src/tools/proxy.ts
|
|
299
|
-
function getDescriptors(target, receiver, ownOrPrototype, handler) {
|
|
300
|
-
var it = Object.keys(ownOrPrototype);
|
|
301
|
-
var result = {};
|
|
302
|
-
it.forEach(function(key) {
|
|
303
|
-
result[key] = {
|
|
304
|
-
get: function() {
|
|
305
|
-
if (!handler.get) {
|
|
306
|
-
return target[key];
|
|
307
|
-
}
|
|
308
|
-
return handler.get(target, key, receiver);
|
|
309
|
-
},
|
|
310
|
-
set: function(v) {
|
|
311
|
-
if (!handler.set) {
|
|
312
|
-
target[key] = v;
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
var valid = handler.set(target, key, v, receiver);
|
|
316
|
-
if (!valid) {
|
|
317
|
-
throw new Error("".concat(key, " in proxy target is not mutable"));
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
});
|
|
322
|
-
return result;
|
|
323
|
-
}
|
|
324
|
-
var createSimpleProxy = function(target, handler) {
|
|
325
|
-
var proxy = {};
|
|
326
|
-
var own = getDescriptors(target, proxy, target, handler);
|
|
327
|
-
var prototype = getDescriptors(target, proxy, Object.getPrototypeOf(target), handler);
|
|
328
|
-
Object.defineProperties(proxy, _object_spread({}, prototype, own));
|
|
329
|
-
return proxy;
|
|
330
|
-
};
|
|
331
|
-
var createProxy = function(target, handler) {
|
|
332
|
-
if (typeof Proxy !== "function") {
|
|
333
|
-
return createSimpleProxy(target, handler);
|
|
334
|
-
}
|
|
335
|
-
return new Proxy(target, handler);
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
// src/tools/shallowEqual.ts
|
|
339
|
-
function isObject(data) {
|
|
340
|
-
return data && (typeof data === "undefined" ? "undefined" : _type_of(data)) === "object";
|
|
341
|
-
}
|
|
342
|
-
function shallowEqual(prev, current) {
|
|
343
|
-
if (Object.is(prev, current)) {
|
|
344
|
-
return true;
|
|
345
|
-
}
|
|
346
|
-
if (!isObject(prev) || !isObject(current)) {
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
var prevKeys = Object.keys(prev);
|
|
350
|
-
var currentKeys = Object.keys(current);
|
|
351
|
-
if (prevKeys.length !== currentKeys.length) {
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
var pre = prev;
|
|
355
|
-
var curr = current;
|
|
356
|
-
var hasDiffKey = prevKeys.some(function(key) {
|
|
357
|
-
return !Object.prototype.hasOwnProperty.call(curr, key);
|
|
358
|
-
});
|
|
359
|
-
if (hasDiffKey) {
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
var hasDiffValue = currentKeys.some(function(key) {
|
|
363
|
-
var currentValue = curr[key];
|
|
364
|
-
var prevValue = pre[key];
|
|
365
|
-
return !Object.is(currentValue, prevValue);
|
|
366
|
-
});
|
|
367
|
-
return !hasDiffValue;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// src/tools/index.ts
|
|
371
|
-
function noop() {
|
|
372
|
-
}
|
|
373
|
-
|
|
374
437
|
// src/updater/tunnel.ts
|
|
375
438
|
function createUnInitializedUpdater() {
|
|
376
439
|
return {
|
|
@@ -516,7 +579,6 @@
|
|
|
516
579
|
updater.mutate(function(u, effect) {
|
|
517
580
|
var _args_model;
|
|
518
581
|
var model2 = (_args_model = args.model) !== null && _args_model !== void 0 ? _args_model : u.model;
|
|
519
|
-
var initialState = "initialState" in args ? args.initialState : u.state;
|
|
520
582
|
var state = "state" in args ? args.state : u.state;
|
|
521
583
|
if (u.controlled) {
|
|
522
584
|
var instance = model2(state);
|
|
@@ -529,15 +591,15 @@
|
|
|
529
591
|
if (u.isDestroyed) {
|
|
530
592
|
return u;
|
|
531
593
|
}
|
|
532
|
-
if (!u.initialized && !("
|
|
533
|
-
throw new Error("
|
|
594
|
+
if (!u.initialized && !("state" in args)) {
|
|
595
|
+
throw new Error("The updater has not been initialized, it should be updated with a state for initializing.");
|
|
534
596
|
}
|
|
535
597
|
if (!u.initialized) {
|
|
536
|
-
var instance1 = model2(
|
|
598
|
+
var instance1 = model2(state);
|
|
537
599
|
var initializedUpdater = createInitializedUpdater(u, middleWare);
|
|
538
600
|
return _object_spread(_object_spread_props(_object_spread({}, u), {
|
|
539
601
|
model: model2,
|
|
540
|
-
state
|
|
602
|
+
state,
|
|
541
603
|
instance: instance1,
|
|
542
604
|
initialized: true
|
|
543
605
|
}), initializedUpdater);
|
|
@@ -560,7 +622,9 @@
|
|
|
560
622
|
state,
|
|
561
623
|
model: model2,
|
|
562
624
|
instance: instance2,
|
|
563
|
-
initialized: true
|
|
625
|
+
initialized: true,
|
|
626
|
+
cacheFields: {},
|
|
627
|
+
cacheMethods: {}
|
|
564
628
|
});
|
|
565
629
|
});
|
|
566
630
|
};
|
|
@@ -1095,6 +1159,29 @@
|
|
|
1095
1159
|
},
|
|
1096
1160
|
getInstance,
|
|
1097
1161
|
update: function update(args) {
|
|
1162
|
+
var updateArgs = args !== null && args !== void 0 ? args : {};
|
|
1163
|
+
if ("key" in updateArgs && updateArgs.key) {
|
|
1164
|
+
var updatingKey = updateArgs.key, updatingModel = updateArgs.model, rest = _object_without_properties(updateArgs, [
|
|
1165
|
+
"key",
|
|
1166
|
+
"model"
|
|
1167
|
+
]);
|
|
1168
|
+
updater.update(_object_spread_props(_object_spread({}, rest), {
|
|
1169
|
+
model: updatingKey.source
|
|
1170
|
+
}));
|
|
1171
|
+
store.key = updatingKey;
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
if ("model" in updateArgs && updateArgs.model) {
|
|
1175
|
+
var updatingKey1 = updateArgs.key, updatingModel1 = updateArgs.model, rest1 = _object_without_properties(updateArgs, [
|
|
1176
|
+
"key",
|
|
1177
|
+
"model"
|
|
1178
|
+
]);
|
|
1179
|
+
updater.update(_object_spread_props(_object_spread({}, rest1), {
|
|
1180
|
+
model: updatingModel1
|
|
1181
|
+
}));
|
|
1182
|
+
store.key = createPrimaryKey(updatingModel1, config2);
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1098
1185
|
updater.update(args);
|
|
1099
1186
|
},
|
|
1100
1187
|
destroy: function destroy2() {
|
|
@@ -1172,11 +1259,8 @@
|
|
|
1172
1259
|
}
|
|
1173
1260
|
var ifIsModelKey = validations.isModelKey(keyLike);
|
|
1174
1261
|
var key = ifIsModelKey ? keyLike : keyLike.key;
|
|
1175
|
-
Object.assign(un, {
|
|
1176
|
-
key
|
|
1177
|
-
});
|
|
1178
1262
|
un.update({
|
|
1179
|
-
|
|
1263
|
+
key
|
|
1180
1264
|
});
|
|
1181
1265
|
});
|
|
1182
1266
|
},
|
package/esm/key/index.js
CHANGED
|
@@ -66,9 +66,8 @@ function createStores(modelKeys, config = {}) {
|
|
|
66
66
|
}
|
|
67
67
|
const ifIsModelKey = validations.isModelKey(keyLike);
|
|
68
68
|
const key = ifIsModelKey ? keyLike : keyLike.key;
|
|
69
|
-
Object.assign(un, { key });
|
|
70
69
|
un.update({
|
|
71
|
-
|
|
70
|
+
key
|
|
72
71
|
});
|
|
73
72
|
});
|
|
74
73
|
},
|
package/esm/store/index.js
CHANGED
|
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
20
32
|
import { createUpdater } from "../updater";
|
|
21
33
|
import { isModelKey, isModelUsage } from "../validation";
|
|
22
34
|
import { modelKeyIdentifier, modelStoreIdentifier } from "../identifiers";
|
|
@@ -87,6 +99,19 @@ function createStore(modelLike, config = {}) {
|
|
|
87
99
|
},
|
|
88
100
|
getInstance,
|
|
89
101
|
update(args) {
|
|
102
|
+
const updateArgs = args != null ? args : {};
|
|
103
|
+
if ("key" in updateArgs && updateArgs.key) {
|
|
104
|
+
const _a = updateArgs, { key: updatingKey, model: updatingModel } = _a, rest = __objRest(_a, ["key", "model"]);
|
|
105
|
+
updater.update(__spreadProps(__spreadValues({}, rest), { model: updatingKey.source }));
|
|
106
|
+
store.key = updatingKey;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if ("model" in updateArgs && updateArgs.model) {
|
|
110
|
+
const _b = updateArgs, { key: updatingKey, model: updatingModel } = _b, rest = __objRest(_b, ["key", "model"]);
|
|
111
|
+
updater.update(__spreadProps(__spreadValues({}, rest), { model: updatingModel }));
|
|
112
|
+
store.key = createPrimaryKey(updatingModel, config);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
90
115
|
updater.update(args);
|
|
91
116
|
},
|
|
92
117
|
destroy() {
|
package/esm/tools/index.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
function noop() {
|
|
2
2
|
}
|
|
3
|
+
function simpleErrorProcess(errors) {
|
|
4
|
+
return function wrap(callback) {
|
|
5
|
+
return function replaced(...args) {
|
|
6
|
+
try {
|
|
7
|
+
return callback(...args);
|
|
8
|
+
} catch (e) {
|
|
9
|
+
errors.push(e);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
3
14
|
import { createSimpleProxy, createProxy } from "./proxy";
|
|
4
15
|
import { shallowEqual } from "./shallowEqual";
|
|
5
16
|
export {
|
|
6
17
|
createProxy,
|
|
7
18
|
createSimpleProxy,
|
|
8
19
|
noop,
|
|
9
|
-
shallowEqual
|
|
20
|
+
shallowEqual,
|
|
21
|
+
simpleErrorProcess
|
|
10
22
|
};
|
package/esm/updater/index.js
CHANGED
|
@@ -36,7 +36,6 @@ function createUpdateFn(updater, middleWare) {
|
|
|
36
36
|
updater.mutate((u, effect) => {
|
|
37
37
|
var _a;
|
|
38
38
|
const model = (_a = args.model) != null ? _a : u.model;
|
|
39
|
-
const initialState = "initialState" in args ? args.initialState : u.state;
|
|
40
39
|
const state = "state" in args ? args.state : u.state;
|
|
41
40
|
if (u.controlled) {
|
|
42
41
|
const instance2 = model(state);
|
|
@@ -45,15 +44,17 @@ function createUpdateFn(updater, middleWare) {
|
|
|
45
44
|
if (u.isDestroyed) {
|
|
46
45
|
return u;
|
|
47
46
|
}
|
|
48
|
-
if (!u.initialized && !("
|
|
49
|
-
throw new Error(
|
|
47
|
+
if (!u.initialized && !("state" in args)) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"The updater has not been initialized, it should be updated with a state for initializing."
|
|
50
|
+
);
|
|
50
51
|
}
|
|
51
52
|
if (!u.initialized) {
|
|
52
|
-
const instance2 = model(
|
|
53
|
+
const instance2 = model(state);
|
|
53
54
|
const initializedUpdater = createInitializedUpdater(u, middleWare);
|
|
54
55
|
return __spreadValues(__spreadProps(__spreadValues({}, u), {
|
|
55
56
|
model,
|
|
56
|
-
state
|
|
57
|
+
state,
|
|
57
58
|
instance: instance2,
|
|
58
59
|
initialized: true
|
|
59
60
|
}), initializedUpdater);
|
|
@@ -76,7 +77,9 @@ function createUpdateFn(updater, middleWare) {
|
|
|
76
77
|
state,
|
|
77
78
|
model,
|
|
78
79
|
instance,
|
|
79
|
-
initialized: true
|
|
80
|
+
initialized: true,
|
|
81
|
+
cacheFields: {},
|
|
82
|
+
cacheMethods: {}
|
|
80
83
|
});
|
|
81
84
|
});
|
|
82
85
|
};
|
package/esm/updater/notifier.js
CHANGED
|
@@ -17,6 +17,7 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { simpleErrorProcess } from "../tools";
|
|
20
21
|
function defaultNotifyImplement(dispatches, action) {
|
|
21
22
|
dispatches.forEach((callback) => {
|
|
22
23
|
callback(action);
|
|
@@ -78,10 +79,8 @@ function generateNotifier(updater, middleWare) {
|
|
|
78
79
|
call(initializedAction);
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
|
-
const { config, model } = updater;
|
|
82
82
|
const dispatch = function dispatch2(action) {
|
|
83
|
-
const { dispatches, controlled } = updater;
|
|
84
|
-
const dispatchCallbacks = [...dispatches];
|
|
83
|
+
const { dispatches, controlled, model, config } = updater;
|
|
85
84
|
const { state } = action;
|
|
86
85
|
const nextInstance = model(state);
|
|
87
86
|
const nextAction = __spreadProps(__spreadValues({}, action), { instance: nextInstance });
|
|
@@ -92,11 +91,27 @@ function generateNotifier(updater, middleWare) {
|
|
|
92
91
|
version: u.version + 1
|
|
93
92
|
}));
|
|
94
93
|
}
|
|
94
|
+
const notifyAction = function notifyAction2(act) {
|
|
95
|
+
const errors = [];
|
|
96
|
+
const dispatchCallbacks = dispatches.map(simpleErrorProcess(errors));
|
|
97
|
+
defaultNotifyImplement(dispatchCallbacks, act);
|
|
98
|
+
if (!errors.length) {
|
|
99
|
+
return { errors: void 0 };
|
|
100
|
+
}
|
|
101
|
+
return { errors };
|
|
102
|
+
};
|
|
103
|
+
const notifyActionWithErrorThrow = function notifyActionWithErrorThrow2(act) {
|
|
104
|
+
const { errors } = notifyAction(act);
|
|
105
|
+
if (!errors || !errors.length) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
throw errors[0];
|
|
109
|
+
};
|
|
95
110
|
try {
|
|
96
|
-
if (typeof config.
|
|
97
|
-
config.
|
|
111
|
+
if (typeof config.notify === "function") {
|
|
112
|
+
config.notify(notifyAction, nextAction);
|
|
98
113
|
} else {
|
|
99
|
-
|
|
114
|
+
notifyActionWithErrorThrow(nextAction);
|
|
100
115
|
}
|
|
101
116
|
} catch (e) {
|
|
102
117
|
updater.mutate((u) => __spreadProps(__spreadValues({}, u), { dispatching: void 0 }));
|
package/esm/validation/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
modelKeyIdentifier,
|
|
3
|
+
modelStoreIdentifier,
|
|
4
|
+
modelUsageIdentifier
|
|
5
|
+
} from "../identifiers";
|
|
2
6
|
const noStateAModelKey = "no-state-a-model-key";
|
|
3
7
|
function createNoStateModel() {
|
|
4
8
|
return function noStateModel(state) {
|