as-model 0.1.23 → 0.1.24
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 +35 -14
- package/esm/updater/notifier.js +14 -3
- package/esm/updater/tunnel.js +12 -9
- package/index.d.ts +311 -311
- package/package.json +68 -68
package/dist/index.js
CHANGED
|
@@ -369,8 +369,11 @@
|
|
|
369
369
|
type: null,
|
|
370
370
|
method: null
|
|
371
371
|
};
|
|
372
|
-
temporaryDispatches.forEach(function(
|
|
373
|
-
|
|
372
|
+
temporaryDispatches.forEach(function(d) {
|
|
373
|
+
if (!d.accessible) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
d.dispatch(initializedAction);
|
|
374
377
|
});
|
|
375
378
|
}
|
|
376
379
|
var dispatch = function dispatch2(action) {
|
|
@@ -392,7 +395,15 @@
|
|
|
392
395
|
}
|
|
393
396
|
var notifyAction = function notifyAction2(act) {
|
|
394
397
|
var errors = [];
|
|
395
|
-
var
|
|
398
|
+
var dispatchWrap = simpleErrorProcess(errors);
|
|
399
|
+
var dispatchCallbacks = dispatches.map(function(d) {
|
|
400
|
+
return dispatchWrap(function dispatchCallback(ac) {
|
|
401
|
+
if (!d.accessible) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
d.dispatch(ac);
|
|
405
|
+
});
|
|
406
|
+
});
|
|
396
407
|
defaultNotifyImplement(dispatchCallbacks, act);
|
|
397
408
|
if (!errors.length) {
|
|
398
409
|
return {
|
|
@@ -511,7 +522,9 @@
|
|
|
511
522
|
function subscribe(dispatchFn) {
|
|
512
523
|
var dispatches = updater.dispatches, temporaryDispatches = updater.temporaryDispatches, isControlled = updater.controlled;
|
|
513
524
|
var copied = _to_consumable_array(dispatches).concat(_to_consumable_array(temporaryDispatches));
|
|
514
|
-
var exist = copied.
|
|
525
|
+
var exist = copied.some(function(d) {
|
|
526
|
+
return d.dispatch === dispatchFn;
|
|
527
|
+
});
|
|
515
528
|
if (exist) {
|
|
516
529
|
return updater.mutate(function(u) {
|
|
517
530
|
return _object_spread_props(_object_spread({}, u), {
|
|
@@ -519,11 +532,15 @@
|
|
|
519
532
|
});
|
|
520
533
|
});
|
|
521
534
|
}
|
|
535
|
+
var dispatcher = {
|
|
536
|
+
dispatch: dispatchFn,
|
|
537
|
+
accessible: true
|
|
538
|
+
};
|
|
522
539
|
if (isControlled) {
|
|
523
540
|
return updater.mutate(function(u) {
|
|
524
541
|
return _object_spread_props(_object_spread({}, u), {
|
|
525
542
|
dispatches: [
|
|
526
|
-
|
|
543
|
+
dispatcher
|
|
527
544
|
],
|
|
528
545
|
isDestroyed: false
|
|
529
546
|
});
|
|
@@ -532,7 +549,7 @@
|
|
|
532
549
|
return updater.mutate(function(u, effect) {
|
|
533
550
|
var tds = u.temporaryDispatches, ds = u.dispatches;
|
|
534
551
|
var nextTds = _to_consumable_array(tds).concat([
|
|
535
|
-
|
|
552
|
+
dispatcher
|
|
536
553
|
]);
|
|
537
554
|
if (u.dispatching) {
|
|
538
555
|
return _object_spread_props(_object_spread({}, u), {
|
|
@@ -550,7 +567,7 @@
|
|
|
550
567
|
method: null
|
|
551
568
|
};
|
|
552
569
|
nextTds.forEach(function(td) {
|
|
553
|
-
td(initializedAction);
|
|
570
|
+
td.dispatch(initializedAction);
|
|
554
571
|
});
|
|
555
572
|
});
|
|
556
573
|
return _object_spread_props(_object_spread({}, u), {
|
|
@@ -560,19 +577,23 @@
|
|
|
560
577
|
});
|
|
561
578
|
});
|
|
562
579
|
}
|
|
563
|
-
return function tunnel(
|
|
580
|
+
return function tunnel(dispatchFn) {
|
|
564
581
|
function disconnect() {
|
|
565
582
|
updater.mutate(function(u) {
|
|
566
583
|
var ds = u.dispatches, tds = u.temporaryDispatches;
|
|
584
|
+
var found = _to_consumable_array(ds).concat(_to_consumable_array(tds)).find(function(d) {
|
|
585
|
+
return d.dispatch === dispatchFn;
|
|
586
|
+
});
|
|
587
|
+
if (!found) {
|
|
588
|
+
return u;
|
|
589
|
+
}
|
|
590
|
+
found.accessible = false;
|
|
567
591
|
var nextDs = ds.filter(function(d) {
|
|
568
|
-
return d !==
|
|
592
|
+
return d !== found;
|
|
569
593
|
});
|
|
570
594
|
var nextTds = tds.filter(function(d) {
|
|
571
|
-
return d !==
|
|
595
|
+
return d !== found;
|
|
572
596
|
});
|
|
573
|
-
if (ds.length === nextDs.length && tds.length === nextTds.length) {
|
|
574
|
-
return u;
|
|
575
|
-
}
|
|
576
597
|
return _object_spread_props(_object_spread({}, u), {
|
|
577
598
|
dispatches: nextDs,
|
|
578
599
|
temporaryDispatches: nextTds
|
|
@@ -581,7 +602,7 @@
|
|
|
581
602
|
}
|
|
582
603
|
return {
|
|
583
604
|
connect: function connect() {
|
|
584
|
-
subscribe(
|
|
605
|
+
subscribe(dispatchFn);
|
|
585
606
|
},
|
|
586
607
|
disconnect: function disconnect1() {
|
|
587
608
|
disconnect();
|
package/esm/updater/notifier.js
CHANGED
|
@@ -76,8 +76,11 @@ function generateNotifier(updater, middleWare) {
|
|
|
76
76
|
type: null,
|
|
77
77
|
method: null
|
|
78
78
|
};
|
|
79
|
-
temporaryDispatches.forEach((
|
|
80
|
-
|
|
79
|
+
temporaryDispatches.forEach((d) => {
|
|
80
|
+
if (!d.accessible) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
d.dispatch(initializedAction);
|
|
81
84
|
});
|
|
82
85
|
}
|
|
83
86
|
const dispatch = function dispatch2(action) {
|
|
@@ -95,7 +98,15 @@ function generateNotifier(updater, middleWare) {
|
|
|
95
98
|
}
|
|
96
99
|
const notifyAction = function notifyAction2(act) {
|
|
97
100
|
const errors = [];
|
|
98
|
-
const
|
|
101
|
+
const dispatchWrap = simpleErrorProcess(errors);
|
|
102
|
+
const dispatchCallbacks = dispatches.map((d) => {
|
|
103
|
+
return dispatchWrap(function dispatchCallback(ac) {
|
|
104
|
+
if (!d.accessible) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
d.dispatch(ac);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
99
110
|
defaultNotifyImplement(dispatchCallbacks, act);
|
|
100
111
|
if (!errors.length) {
|
|
101
112
|
return { errors: void 0 };
|
package/esm/updater/tunnel.js
CHANGED
|
@@ -65,19 +65,20 @@ function generateTunnelCreator(updater) {
|
|
|
65
65
|
controlled: isControlled
|
|
66
66
|
} = updater;
|
|
67
67
|
const copied = [...dispatches, ...temporaryDispatches];
|
|
68
|
-
const exist = copied.
|
|
68
|
+
const exist = copied.some((d) => d.dispatch === dispatchFn);
|
|
69
69
|
if (exist) {
|
|
70
70
|
return updater.mutate((u) => __spreadProps(__spreadValues({}, u), { isDestroyed: false }));
|
|
71
71
|
}
|
|
72
|
+
const dispatcher = { dispatch: dispatchFn, accessible: true };
|
|
72
73
|
if (isControlled) {
|
|
73
74
|
return updater.mutate((u) => __spreadProps(__spreadValues({}, u), {
|
|
74
|
-
dispatches: [
|
|
75
|
+
dispatches: [dispatcher],
|
|
75
76
|
isDestroyed: false
|
|
76
77
|
}));
|
|
77
78
|
}
|
|
78
79
|
return updater.mutate((u, effect) => {
|
|
79
80
|
const { temporaryDispatches: tds, dispatches: ds } = u;
|
|
80
|
-
const nextTds = [...tds,
|
|
81
|
+
const nextTds = [...tds, dispatcher];
|
|
81
82
|
if (u.dispatching) {
|
|
82
83
|
return __spreadProps(__spreadValues({}, u), {
|
|
83
84
|
temporaryDispatches: nextTds,
|
|
@@ -94,7 +95,7 @@ function generateTunnelCreator(updater) {
|
|
|
94
95
|
method: null
|
|
95
96
|
};
|
|
96
97
|
nextTds.forEach((td) => {
|
|
97
|
-
td(initializedAction);
|
|
98
|
+
td.dispatch(initializedAction);
|
|
98
99
|
});
|
|
99
100
|
});
|
|
100
101
|
return __spreadProps(__spreadValues({}, u), {
|
|
@@ -104,15 +105,17 @@ function generateTunnelCreator(updater) {
|
|
|
104
105
|
});
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
|
-
return function tunnel(
|
|
108
|
+
return function tunnel(dispatchFn) {
|
|
108
109
|
function disconnect() {
|
|
109
110
|
updater.mutate((u) => {
|
|
110
111
|
const { dispatches: ds, temporaryDispatches: tds } = u;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
if (ds.length === nextDs.length && tds.length === nextTds.length) {
|
|
112
|
+
const found = [...ds, ...tds].find((d) => d.dispatch === dispatchFn);
|
|
113
|
+
if (!found) {
|
|
114
114
|
return u;
|
|
115
115
|
}
|
|
116
|
+
found.accessible = false;
|
|
117
|
+
const nextDs = ds.filter((d) => d !== found);
|
|
118
|
+
const nextTds = tds.filter((d) => d !== found);
|
|
116
119
|
return __spreadProps(__spreadValues({}, u), {
|
|
117
120
|
dispatches: nextDs,
|
|
118
121
|
temporaryDispatches: nextTds
|
|
@@ -121,7 +124,7 @@ function generateTunnelCreator(updater) {
|
|
|
121
124
|
}
|
|
122
125
|
return {
|
|
123
126
|
connect() {
|
|
124
|
-
subscribe(
|
|
127
|
+
subscribe(dispatchFn);
|
|
125
128
|
},
|
|
126
129
|
disconnect() {
|
|
127
130
|
disconnect();
|