vestjs-runtime 1.0.6 → 1.2.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.
- package/dist/cjs/IsolateSerializer.development.js +12 -13
- package/dist/cjs/IsolateSerializer.development.js.map +1 -1
- package/dist/cjs/IsolateSerializer.production.js +1 -1
- package/dist/cjs/IsolateSerializer.production.js.map +1 -1
- package/dist/cjs/test-utils.development.js +43 -18
- package/dist/cjs/test-utils.development.js.map +1 -1
- package/dist/cjs/test-utils.production.js +1 -1
- package/dist/cjs/test-utils.production.js.map +1 -1
- package/dist/cjs/vestjs-runtime.development.js +43 -51
- package/dist/cjs/vestjs-runtime.development.js.map +1 -1
- package/dist/cjs/vestjs-runtime.production.js +1 -1
- package/dist/cjs/vestjs-runtime.production.js.map +1 -1
- package/dist/es/IsolateSerializer.development.js +12 -13
- package/dist/es/IsolateSerializer.development.js.map +1 -1
- package/dist/es/IsolateSerializer.production.js +1 -1
- package/dist/es/IsolateSerializer.production.js.map +1 -1
- package/dist/es/test-utils.development.js +43 -18
- package/dist/es/test-utils.development.js.map +1 -1
- package/dist/es/test-utils.production.js +1 -1
- package/dist/es/test-utils.production.js.map +1 -1
- package/dist/es/vestjs-runtime.development.js +43 -52
- package/dist/es/vestjs-runtime.development.js.map +1 -1
- package/dist/es/vestjs-runtime.production.js +1 -1
- package/dist/es/vestjs-runtime.production.js.map +1 -1
- package/dist/umd/IsolateSerializer.development.js +12 -13
- package/dist/umd/IsolateSerializer.development.js.map +1 -1
- package/dist/umd/IsolateSerializer.production.js +1 -1
- package/dist/umd/IsolateSerializer.production.js.map +1 -1
- package/dist/umd/test-utils.development.js +86 -61
- package/dist/umd/test-utils.development.js.map +1 -1
- package/dist/umd/test-utils.production.js +1 -1
- package/dist/umd/test-utils.production.js.map +1 -1
- package/dist/umd/vestjs-runtime.development.js +702 -710
- package/dist/umd/vestjs-runtime.development.js.map +1 -1
- package/dist/umd/vestjs-runtime.production.js +1 -1
- package/dist/umd/vestjs-runtime.production.js.map +1 -1
- package/package.json +3 -3
- package/types/IsolateSerializer.d.ts +6 -7
- package/types/IsolateSerializer.d.ts.map +1 -1
- package/types/test-utils.d.ts +7 -8
- package/types/test-utils.d.ts.map +1 -1
- package/types/vestjs-runtime.d.ts +29 -24
- package/types/vestjs-runtime.d.ts.map +1 -1
|
@@ -1,736 +1,728 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vest-utils'), require('context')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'vest-utils', 'context'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["vestjs-runtime"] = {}, global["vest-utils"], global.context));
|
|
5
5
|
})(this, (function (exports, vestUtils, context) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const RuntimeEvents = {
|
|
8
|
+
ISOLATE_ENTER: 'ISOLATE_ENTER',
|
|
9
|
+
ISOLATE_PENDING: 'ISOLATE_PENDING',
|
|
10
|
+
ISOLATE_DONE: 'ISOLATE_DONE',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/******************************************************************************
|
|
14
|
+
Copyright (c) Microsoft Corporation.
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
17
|
+
purpose with or without fee is hereby granted.
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
20
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
21
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
22
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
23
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
24
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
25
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
26
|
+
***************************************************************************** */
|
|
27
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
22
28
|
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
function __rest(s, e) {
|
|
31
|
+
var t = {};
|
|
32
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
33
|
+
t[p] = s[p];
|
|
34
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
35
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
36
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
37
|
+
t[p[i]] = s[p[i]];
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
40
|
+
}
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var ErrorStrings;
|
|
42
|
-
(function (ErrorStrings) {
|
|
43
|
-
ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
|
|
44
|
-
ErrorStrings["UNABLE_TO_PICK_NEXT_ISOLATE"] = "Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.";
|
|
45
|
-
ErrorStrings["ENCOUNTERED_THE_SAME_KEY_TWICE"] = "Encountered the same key \"{key}\" twice. This may lead to inconsistent or overriding of results.";
|
|
46
|
-
ErrorStrings["INVALID_ISOLATE_CANNOT_PARSE"] = "Invalid isolate was passed to IsolateSerializer. Cannot proceed.";
|
|
47
|
-
})(ErrorStrings || (ErrorStrings = {}));
|
|
48
|
-
|
|
49
|
-
class IsolateInspector {
|
|
50
|
-
static at(isolate, at) {
|
|
51
|
-
var _a, _b;
|
|
52
|
-
if (vestUtils.isNullish(isolate)) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a[at]) !== null && _b !== void 0 ? _b : null;
|
|
56
|
-
}
|
|
57
|
-
static cursor(isolate) {
|
|
58
|
-
var _a, _b;
|
|
59
|
-
if (vestUtils.isNullish(isolate)) {
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
63
|
-
}
|
|
64
|
-
static canReorder(isolate) {
|
|
65
|
-
if (vestUtils.isNullish(isolate)) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
return IsolateInspector.allowsReorder(isolate.parent);
|
|
69
|
-
}
|
|
70
|
-
static allowsReorder(isolate) {
|
|
71
|
-
return (isolate === null || isolate === void 0 ? void 0 : isolate.allowReorder) === true;
|
|
72
|
-
}
|
|
73
|
-
static usesKey(isolate) {
|
|
74
|
-
if (vestUtils.isNullish(isolate)) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
return vestUtils.isNotNullish(isolate.key);
|
|
78
|
-
}
|
|
79
|
-
static getChildByKey(isolate, key) {
|
|
80
|
-
var _a, _b;
|
|
81
|
-
if (vestUtils.isNullish(isolate)) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
return (_b = (_a = isolate.keys) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : null;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
42
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
43
|
+
var e = new Error(message);
|
|
44
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
45
|
+
};
|
|
87
46
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
47
|
+
var ErrorStrings;
|
|
48
|
+
(function (ErrorStrings) {
|
|
49
|
+
ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
|
|
50
|
+
ErrorStrings["UNABLE_TO_PICK_NEXT_ISOLATE"] = "Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.";
|
|
51
|
+
ErrorStrings["ENCOUNTERED_THE_SAME_KEY_TWICE"] = "Encountered the same key \"{key}\" twice. This may lead to inconsistent or overriding of results.";
|
|
52
|
+
ErrorStrings["INVALID_ISOLATE_CANNOT_PARSE"] = "Invalid isolate was passed to IsolateSerializer. Cannot proceed.";
|
|
53
|
+
})(ErrorStrings || (ErrorStrings = {}));
|
|
94
54
|
|
|
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
|
-
isolate.data = data;
|
|
134
|
-
}
|
|
135
|
-
static setPending(isolate) {
|
|
136
|
-
isolate.status = exports.IsolateStatus.PENDING;
|
|
137
|
-
}
|
|
138
|
-
static setDone(isolate) {
|
|
139
|
-
isolate.status = exports.IsolateStatus.DONE;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
55
|
+
class IsolateInspector {
|
|
56
|
+
static at(isolate, at) {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
if (vestUtils.isNullish(isolate)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a[at]) !== null && _b !== void 0 ? _b : null;
|
|
62
|
+
}
|
|
63
|
+
static cursor(isolate) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
if (vestUtils.isNullish(isolate)) {
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
69
|
+
}
|
|
70
|
+
static canReorder(isolate) {
|
|
71
|
+
if (vestUtils.isNullish(isolate)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return IsolateInspector.allowsReorder(isolate.parent);
|
|
75
|
+
}
|
|
76
|
+
static allowsReorder(isolate) {
|
|
77
|
+
return (isolate === null || isolate === void 0 ? void 0 : isolate.allowReorder) === true;
|
|
78
|
+
}
|
|
79
|
+
static usesKey(isolate) {
|
|
80
|
+
if (vestUtils.isNullish(isolate)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return vestUtils.isNotNullish(isolate.key);
|
|
84
|
+
}
|
|
85
|
+
static getChildByKey(isolate, key) {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
if (vestUtils.isNullish(isolate)) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return (_b = (_a = isolate.keys) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
142
93
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
return PersistedContext.run(ctxToUse.stateRef, () => cb(...args));
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
function useX() {
|
|
194
|
-
return PersistedContext.useX();
|
|
195
|
-
}
|
|
196
|
-
function useHistoryRoot() {
|
|
197
|
-
return useX().stateRef.historyRoot();
|
|
198
|
-
}
|
|
199
|
-
function useHistoryIsolate() {
|
|
200
|
-
return useX().historyNode;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Returns the history isolate at the current position.
|
|
204
|
-
* If there is a parent isolate, it returns the history node from the parent's children.
|
|
205
|
-
* Otherwise, it returns the history node.
|
|
206
|
-
* @returns {Nullable<TIsolate>} The history isolate at the current position.
|
|
207
|
-
*/
|
|
208
|
-
function useHistoryIsolateAtCurrentPosition() {
|
|
209
|
-
const parent = useIsolate();
|
|
210
|
-
// This is most likely the historic counterpart of the parent node
|
|
211
|
-
const historyNode = useHistoryIsolate();
|
|
212
|
-
if (parent) {
|
|
213
|
-
// If we have a parent, we need to get the history node from the parent's children
|
|
214
|
-
// We take the history node from the cursor of the active node's children
|
|
215
|
-
return IsolateInspector.at(historyNode, IsolateInspector.cursor(parent));
|
|
216
|
-
}
|
|
217
|
-
return historyNode;
|
|
218
|
-
}
|
|
219
|
-
function addNodeToHistory(node) {
|
|
220
|
-
const parent = useIsolate();
|
|
221
|
-
if (parent) {
|
|
222
|
-
useSetNextIsolateChild(node);
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
useSetHistory(node);
|
|
226
|
-
}
|
|
227
|
-
IsolateMutator.setParent(node, parent);
|
|
228
|
-
}
|
|
229
|
-
function useSetHistory(history) {
|
|
230
|
-
const [, setHistoryRoot] = useHistoryRoot();
|
|
231
|
-
setHistoryRoot(history);
|
|
232
|
-
}
|
|
233
|
-
function useHistoryKey(key) {
|
|
234
|
-
if (vestUtils.isNullish(key)) {
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
const historyNode = useX().historyNode;
|
|
238
|
-
return IsolateInspector.getChildByKey(historyNode, key);
|
|
239
|
-
}
|
|
240
|
-
function useIsolate() {
|
|
241
|
-
var _a;
|
|
242
|
-
return (_a = useX().runtimeNode) !== null && _a !== void 0 ? _a : null;
|
|
243
|
-
}
|
|
244
|
-
function useCurrentCursor() {
|
|
245
|
-
const isolate = useIsolate();
|
|
246
|
-
return isolate ? IsolateInspector.cursor(isolate) : 0;
|
|
247
|
-
}
|
|
248
|
-
function useRuntimeRoot() {
|
|
249
|
-
return useX().runtimeRoot;
|
|
250
|
-
}
|
|
251
|
-
function useSetNextIsolateChild(child) {
|
|
252
|
-
const currentIsolate = useIsolate();
|
|
253
|
-
vestUtils.invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
|
|
254
|
-
IsolateMutator.addChild(currentIsolate, child);
|
|
255
|
-
}
|
|
256
|
-
function useSetIsolateKey(key, node) {
|
|
257
|
-
if (!key) {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
const currentIsolate = useIsolate();
|
|
261
|
-
vestUtils.invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
|
|
262
|
-
if (vestUtils.isNullish(IsolateInspector.getChildByKey(currentIsolate, key))) {
|
|
263
|
-
IsolateMutator.addChildKey(currentIsolate, key, node);
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
vestUtils.deferThrow(vestUtils.text(ErrorStrings.ENCOUNTERED_THE_SAME_KEY_TWICE, { key }));
|
|
267
|
-
}
|
|
268
|
-
function useAvailableRoot() {
|
|
269
|
-
const root = useRuntimeRoot();
|
|
270
|
-
if (root) {
|
|
271
|
-
return root;
|
|
272
|
-
}
|
|
273
|
-
const [historyRoot] = useHistoryRoot();
|
|
274
|
-
return historyRoot;
|
|
275
|
-
}
|
|
276
|
-
function reset() {
|
|
277
|
-
const [, , resetHistoryRoot] = useHistoryRoot();
|
|
278
|
-
resetHistoryRoot();
|
|
279
|
-
}
|
|
280
|
-
function useLoadRootNode(root) {
|
|
281
|
-
useSetHistory(root);
|
|
282
|
-
}
|
|
94
|
+
class IsolateMutator {
|
|
95
|
+
static setParent(isolate, parent) {
|
|
96
|
+
isolate.parent = parent;
|
|
97
|
+
return isolate;
|
|
98
|
+
}
|
|
99
|
+
static saveOutput(isolate, output) {
|
|
100
|
+
isolate.output = output;
|
|
101
|
+
return isolate;
|
|
102
|
+
}
|
|
103
|
+
static setKey(isolate, key) {
|
|
104
|
+
isolate.key = key;
|
|
105
|
+
return isolate;
|
|
106
|
+
}
|
|
107
|
+
static addChild(isolate, child) {
|
|
108
|
+
var _a;
|
|
109
|
+
vestUtils.invariant(isolate);
|
|
110
|
+
isolate.children = (_a = isolate.children) !== null && _a !== void 0 ? _a : [];
|
|
111
|
+
isolate.children.push(child);
|
|
112
|
+
IsolateMutator.setParent(child, isolate);
|
|
113
|
+
}
|
|
114
|
+
static removeChild(isolate, node) {
|
|
115
|
+
var _a, _b;
|
|
116
|
+
isolate.children =
|
|
117
|
+
(_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.filter(child => child !== node)) !== null && _b !== void 0 ? _b : null;
|
|
118
|
+
}
|
|
119
|
+
static addChildKey(isolate, key, node) {
|
|
120
|
+
var _a;
|
|
121
|
+
vestUtils.invariant(isolate);
|
|
122
|
+
isolate.keys = (_a = isolate.keys) !== null && _a !== void 0 ? _a : {};
|
|
123
|
+
isolate.keys[key] = node;
|
|
124
|
+
}
|
|
125
|
+
static slice(isolate, at) {
|
|
126
|
+
if (vestUtils.isNullish(isolate.children)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
isolate.children.length = at;
|
|
130
|
+
}
|
|
131
|
+
static setData(isolate, data) {
|
|
132
|
+
isolate.data = data;
|
|
133
|
+
}
|
|
134
|
+
static abort(isolate, reason) {
|
|
135
|
+
if (vestUtils.isNullish(isolate.abortController)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
isolate.abortController.abort(reason);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
283
141
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
142
|
+
const PersistedContext = context.createCascade((stateRef, parentContext) => {
|
|
143
|
+
if (parentContext) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
vestUtils.invariant(stateRef.historyRoot);
|
|
147
|
+
const [historyRootNode] = stateRef.historyRoot();
|
|
148
|
+
const ctxRef = {};
|
|
149
|
+
vestUtils.assign(ctxRef, {
|
|
150
|
+
historyNode: historyRootNode,
|
|
151
|
+
runtimeNode: null,
|
|
152
|
+
runtimeRoot: null,
|
|
153
|
+
stateRef,
|
|
154
|
+
});
|
|
155
|
+
return ctxRef;
|
|
156
|
+
});
|
|
157
|
+
const Run = PersistedContext.run;
|
|
158
|
+
const RuntimeApi = {
|
|
159
|
+
Run,
|
|
160
|
+
addNodeToHistory,
|
|
161
|
+
createRef,
|
|
162
|
+
persist,
|
|
163
|
+
reset,
|
|
164
|
+
useAvailableRoot,
|
|
165
|
+
useCurrentCursor,
|
|
166
|
+
useHistoryRoot,
|
|
167
|
+
useLoadRootNode,
|
|
168
|
+
useXAppData,
|
|
169
|
+
};
|
|
170
|
+
function useXAppData() {
|
|
171
|
+
return useX().stateRef.appData;
|
|
172
|
+
}
|
|
173
|
+
function createRef(Reconciler, setter) {
|
|
174
|
+
return Object.freeze({
|
|
175
|
+
Bus: vestUtils.bus.createBus(),
|
|
176
|
+
Reconciler,
|
|
177
|
+
appData: vestUtils.optionalFunctionValue(setter),
|
|
178
|
+
historyRoot: vestUtils.tinyState.createTinyState(null),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function useReconciler() {
|
|
182
|
+
return useX().stateRef.Reconciler;
|
|
183
|
+
}
|
|
184
|
+
function persist(cb) {
|
|
185
|
+
const prev = PersistedContext.useX();
|
|
186
|
+
return ((...args) => {
|
|
187
|
+
var _a;
|
|
188
|
+
const ctxToUse = (_a = PersistedContext.use()) !== null && _a !== void 0 ? _a : prev;
|
|
189
|
+
return PersistedContext.run(ctxToUse.stateRef, () => cb(...args));
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function useX() {
|
|
193
|
+
return PersistedContext.useX();
|
|
194
|
+
}
|
|
195
|
+
function useHistoryRoot() {
|
|
196
|
+
return useX().stateRef.historyRoot();
|
|
197
|
+
}
|
|
198
|
+
function useHistoryIsolate() {
|
|
199
|
+
return useX().historyNode;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Returns the history isolate at the current position.
|
|
203
|
+
* If there is a parent isolate, it returns the history node from the parent's children.
|
|
204
|
+
* Otherwise, it returns the history node.
|
|
205
|
+
* @returns {Nullable<TIsolate>} The history isolate at the current position.
|
|
206
|
+
*/
|
|
207
|
+
function useHistoryIsolateAtCurrentPosition() {
|
|
208
|
+
const parent = useIsolate();
|
|
209
|
+
// This is most likely the historic counterpart of the parent node
|
|
210
|
+
const historyNode = useHistoryIsolate();
|
|
211
|
+
if (parent) {
|
|
212
|
+
// If we have a parent, we need to get the history node from the parent's children
|
|
213
|
+
// We take the history node from the cursor of the active node's children
|
|
214
|
+
return IsolateInspector.at(historyNode, IsolateInspector.cursor(parent));
|
|
215
|
+
}
|
|
216
|
+
return historyNode;
|
|
217
|
+
}
|
|
218
|
+
function addNodeToHistory(node) {
|
|
219
|
+
const parent = useIsolate();
|
|
220
|
+
if (parent) {
|
|
221
|
+
useSetNextIsolateChild(node);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
useSetHistory(node);
|
|
225
|
+
}
|
|
226
|
+
IsolateMutator.setParent(node, parent);
|
|
227
|
+
}
|
|
228
|
+
function useSetHistory(history) {
|
|
229
|
+
const [, setHistoryRoot] = useHistoryRoot();
|
|
230
|
+
setHistoryRoot(history);
|
|
231
|
+
}
|
|
232
|
+
function useHistoryKey(key) {
|
|
233
|
+
if (vestUtils.isNullish(key)) {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
const historyNode = useX().historyNode;
|
|
237
|
+
return IsolateInspector.getChildByKey(historyNode, key);
|
|
238
|
+
}
|
|
239
|
+
function useIsolate() {
|
|
240
|
+
var _a;
|
|
241
|
+
return (_a = useX().runtimeNode) !== null && _a !== void 0 ? _a : null;
|
|
242
|
+
}
|
|
243
|
+
function useCurrentCursor() {
|
|
244
|
+
const isolate = useIsolate();
|
|
245
|
+
return isolate ? IsolateInspector.cursor(isolate) : 0;
|
|
246
|
+
}
|
|
247
|
+
function useRuntimeRoot() {
|
|
248
|
+
return useX().runtimeRoot;
|
|
249
|
+
}
|
|
250
|
+
function useSetNextIsolateChild(child) {
|
|
251
|
+
const currentIsolate = useIsolate();
|
|
252
|
+
vestUtils.invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
|
|
253
|
+
IsolateMutator.addChild(currentIsolate, child);
|
|
254
|
+
}
|
|
255
|
+
function useSetIsolateKey(key, node) {
|
|
256
|
+
if (!key) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const currentIsolate = useIsolate();
|
|
260
|
+
vestUtils.invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
|
|
261
|
+
if (vestUtils.isNullish(IsolateInspector.getChildByKey(currentIsolate, key))) {
|
|
262
|
+
IsolateMutator.addChildKey(currentIsolate, key, node);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
vestUtils.deferThrow(vestUtils.text(ErrorStrings.ENCOUNTERED_THE_SAME_KEY_TWICE, { key }));
|
|
266
|
+
}
|
|
267
|
+
function useAvailableRoot() {
|
|
268
|
+
const root = useRuntimeRoot();
|
|
269
|
+
if (root) {
|
|
270
|
+
return root;
|
|
271
|
+
}
|
|
272
|
+
const [historyRoot] = useHistoryRoot();
|
|
273
|
+
return historyRoot;
|
|
274
|
+
}
|
|
275
|
+
function reset() {
|
|
276
|
+
const [, , resetHistoryRoot] = useHistoryRoot();
|
|
277
|
+
resetHistoryRoot();
|
|
278
|
+
}
|
|
279
|
+
function useLoadRootNode(root) {
|
|
280
|
+
useSetHistory(root);
|
|
281
|
+
}
|
|
302
282
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
283
|
+
function useBus() {
|
|
284
|
+
return useX().stateRef.Bus;
|
|
285
|
+
}
|
|
286
|
+
/*
|
|
287
|
+
Returns an emitter, but it also has a shortcut for emitting an event immediately
|
|
288
|
+
by passing an event name.
|
|
289
|
+
*/
|
|
290
|
+
function useEmit(event, data) {
|
|
291
|
+
const emit = useBus().emit;
|
|
292
|
+
if (!vestUtils.isNullish(event)) {
|
|
293
|
+
emit(event, data);
|
|
294
|
+
}
|
|
295
|
+
return persist(emit);
|
|
296
|
+
}
|
|
297
|
+
function usePrepareEmitter(event) {
|
|
298
|
+
const emit = useEmit();
|
|
299
|
+
return (arg) => emit(event, arg);
|
|
300
|
+
}
|
|
309
301
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
IsolateKeys["Data"] = "data";
|
|
317
|
-
IsolateKeys["AllowReorder"] = "allowReorder";
|
|
318
|
-
IsolateKeys["Status"] = "status";
|
|
319
|
-
})(IsolateKeys || (IsolateKeys = {}));
|
|
320
|
-
var MinifiedKeys;
|
|
321
|
-
(function (MinifiedKeys) {
|
|
322
|
-
MinifiedKeys["Type"] = "$";
|
|
323
|
-
MinifiedKeys["Keys"] = "K";
|
|
324
|
-
MinifiedKeys["Key"] = "k";
|
|
325
|
-
MinifiedKeys["Parent"] = "P";
|
|
326
|
-
MinifiedKeys["Data"] = "D";
|
|
327
|
-
MinifiedKeys["AllowReorder"] = "aR";
|
|
328
|
-
MinifiedKeys["Status"] = "S";
|
|
329
|
-
})(MinifiedKeys || (MinifiedKeys = {}));
|
|
330
|
-
const KeyToMinified = {
|
|
331
|
-
[IsolateKeys.Type]: MinifiedKeys.Type,
|
|
332
|
-
[IsolateKeys.Keys]: MinifiedKeys.Keys,
|
|
333
|
-
[IsolateKeys.Parent]: MinifiedKeys.Parent,
|
|
334
|
-
[IsolateKeys.Data]: MinifiedKeys.Data,
|
|
335
|
-
[IsolateKeys.Key]: MinifiedKeys.Key,
|
|
336
|
-
[IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,
|
|
337
|
-
[IsolateKeys.Status]: MinifiedKeys.Status,
|
|
338
|
-
};
|
|
339
|
-
// This const is an object that looks like this:
|
|
340
|
-
// {
|
|
341
|
-
// '$': '$type',
|
|
342
|
-
// 'K': 'keys',
|
|
343
|
-
// 'P': 'parent',
|
|
344
|
-
// ...
|
|
345
|
-
// }
|
|
346
|
-
const MinifiedToKey = Object.entries(KeyToMinified).reduce((acc, [key, minified]) => Object.assign(acc, {
|
|
347
|
-
[minified]: key,
|
|
348
|
-
}), {});
|
|
302
|
+
var Bus = /*#__PURE__*/Object.freeze({
|
|
303
|
+
__proto__: null,
|
|
304
|
+
useBus: useBus,
|
|
305
|
+
useEmit: useEmit,
|
|
306
|
+
usePrepareEmitter: usePrepareEmitter
|
|
307
|
+
});
|
|
349
308
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
309
|
+
var IsolateKeys;
|
|
310
|
+
(function (IsolateKeys) {
|
|
311
|
+
IsolateKeys["Type"] = "$type";
|
|
312
|
+
IsolateKeys["Keys"] = "keys";
|
|
313
|
+
IsolateKeys["Key"] = "key";
|
|
314
|
+
IsolateKeys["Parent"] = "parent";
|
|
315
|
+
IsolateKeys["Data"] = "data";
|
|
316
|
+
IsolateKeys["AllowReorder"] = "allowReorder";
|
|
317
|
+
IsolateKeys["Status"] = "status";
|
|
318
|
+
IsolateKeys["AbortController"] = "abortController";
|
|
319
|
+
})(IsolateKeys || (IsolateKeys = {}));
|
|
320
|
+
var MinifiedKeys;
|
|
321
|
+
(function (MinifiedKeys) {
|
|
322
|
+
MinifiedKeys["Type"] = "$";
|
|
323
|
+
MinifiedKeys["Keys"] = "K";
|
|
324
|
+
MinifiedKeys["Key"] = "k";
|
|
325
|
+
MinifiedKeys["Parent"] = "P";
|
|
326
|
+
MinifiedKeys["Data"] = "D";
|
|
327
|
+
MinifiedKeys["AllowReorder"] = "aR";
|
|
328
|
+
MinifiedKeys["Status"] = "S";
|
|
329
|
+
})(MinifiedKeys || (MinifiedKeys = {}));
|
|
330
|
+
const KeyToMinified = {
|
|
331
|
+
[IsolateKeys.Type]: MinifiedKeys.Type,
|
|
332
|
+
[IsolateKeys.Keys]: MinifiedKeys.Keys,
|
|
333
|
+
[IsolateKeys.Parent]: MinifiedKeys.Parent,
|
|
334
|
+
[IsolateKeys.Data]: MinifiedKeys.Data,
|
|
335
|
+
[IsolateKeys.Key]: MinifiedKeys.Key,
|
|
336
|
+
[IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,
|
|
337
|
+
[IsolateKeys.Status]: MinifiedKeys.Status,
|
|
338
|
+
};
|
|
339
|
+
// This const is an object that looks like this:
|
|
340
|
+
// {
|
|
341
|
+
// '$': '$type',
|
|
342
|
+
// 'K': 'keys',
|
|
343
|
+
// 'P': 'parent',
|
|
344
|
+
// ...
|
|
345
|
+
// }
|
|
346
|
+
const MinifiedToKey = Object.entries(KeyToMinified).reduce((acc, [key, minified]) => Object.assign(acc, {
|
|
347
|
+
[minified]: key,
|
|
348
|
+
}), {});
|
|
349
|
+
const ExcludedFromDump = [
|
|
350
|
+
IsolateKeys.AbortController,
|
|
351
|
+
IsolateKeys.Parent,
|
|
352
|
+
IsolateKeys.Keys,
|
|
353
|
+
];
|
|
359
354
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
355
|
+
function isIsolateType(node, type) {
|
|
356
|
+
return (node === null || node === void 0 ? void 0 : node[IsolateKeys.Type]) === type;
|
|
357
|
+
}
|
|
358
|
+
function isSameIsolateType(a, b) {
|
|
359
|
+
return isIsolateType(a, b[IsolateKeys.Type]);
|
|
360
|
+
}
|
|
361
|
+
function isSameIsolateIdentity(a, b) {
|
|
362
|
+
return Object.is(a, b) || (isSameIsolateType(a, b) && a.key === b.key);
|
|
363
|
+
}
|
|
366
364
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
class Reconciler {
|
|
374
|
-
/**
|
|
375
|
-
* Reconciles the current isolate with the history isolate.
|
|
376
|
-
* If the current isolate is of a different type than the history isolate,
|
|
377
|
-
* the current isolate is returned.
|
|
378
|
-
* Otherwise, the reconciler function is called to determine the next isolate.
|
|
379
|
-
* If the reconciler function returns null or undefined, the base reconciler is used.
|
|
380
|
-
* If no history isolate exists, the current isolate is returned.
|
|
381
|
-
* @param node The current isolate to reconcile.
|
|
382
|
-
* @returns The next isolate after reconciliation.
|
|
383
|
-
*/
|
|
384
|
-
static reconcile(node) {
|
|
385
|
-
const localHistoryNode = useHistoryIsolateAtCurrentPosition();
|
|
386
|
-
const nextNodeResult = pickNextNode(node, localHistoryNode);
|
|
387
|
-
vestUtils.invariant(nextNodeResult, ErrorStrings.UNABLE_TO_PICK_NEXT_ISOLATE);
|
|
388
|
-
return nextNodeResult;
|
|
389
|
-
}
|
|
390
|
-
static dropNextNodesOnReorder(reorderLogic, newNode, prevNode) {
|
|
391
|
-
const didReorder = reorderLogic(newNode, prevNode);
|
|
392
|
-
if (didReorder) {
|
|
393
|
-
removeAllNextNodesInIsolate();
|
|
394
|
-
}
|
|
395
|
-
return didReorder;
|
|
396
|
-
}
|
|
397
|
-
static handleIsolateNodeWithKey(node) {
|
|
398
|
-
vestUtils.invariant(IsolateInspector.usesKey(node));
|
|
399
|
-
const prevNodeByKey = useHistoryKey(node.key);
|
|
400
|
-
let nextNode = node;
|
|
401
|
-
if (!vestUtils.isNullish(prevNodeByKey)) {
|
|
402
|
-
nextNode = prevNodeByKey;
|
|
403
|
-
}
|
|
404
|
-
useSetIsolateKey(node.key, node);
|
|
405
|
-
return nextNode;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
function pickNextNode(currentNode, historyNode) {
|
|
409
|
-
var _a;
|
|
410
|
-
if (vestUtils.isNullish(historyNode)) {
|
|
411
|
-
return handleNoHistoryNode(currentNode);
|
|
412
|
-
}
|
|
413
|
-
if (!isSameIsolateType(currentNode, historyNode)) {
|
|
414
|
-
return currentNode;
|
|
415
|
-
}
|
|
416
|
-
const reconciler = useReconciler();
|
|
417
|
-
return ((_a = reconciler(currentNode, historyNode)) !== null && _a !== void 0 ? _a : BaseReconciler(currentNode, historyNode));
|
|
418
|
-
}
|
|
419
|
-
function handleNoHistoryNode(newNode) {
|
|
420
|
-
if (IsolateInspector.usesKey(newNode)) {
|
|
421
|
-
return Reconciler.handleIsolateNodeWithKey(newNode);
|
|
422
|
-
}
|
|
423
|
-
return newNode;
|
|
424
|
-
}
|
|
425
|
-
function removeAllNextNodesInIsolate() {
|
|
426
|
-
const currentNode = useIsolate();
|
|
427
|
-
const historyNode = useHistoryIsolate();
|
|
428
|
-
if (!historyNode || !currentNode) {
|
|
429
|
-
// This is probably unreachable, but TS is not convinced.
|
|
430
|
-
// Let's play it safe.
|
|
431
|
-
/* istanbul ignore next */
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
IsolateMutator.slice(historyNode, IsolateInspector.cursor(currentNode));
|
|
435
|
-
}
|
|
365
|
+
var IsolateSelectors = /*#__PURE__*/Object.freeze({
|
|
366
|
+
__proto__: null,
|
|
367
|
+
isIsolateType: isIsolateType,
|
|
368
|
+
isSameIsolateIdentity: isSameIsolateIdentity,
|
|
369
|
+
isSameIsolateType: isSameIsolateType
|
|
370
|
+
});
|
|
436
371
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
372
|
+
function BaseReconciler(currentNode, historyNode) {
|
|
373
|
+
if (vestUtils.isNullish(historyNode)) {
|
|
374
|
+
return currentNode;
|
|
375
|
+
}
|
|
376
|
+
return currentNode;
|
|
377
|
+
}
|
|
378
|
+
class Reconciler {
|
|
379
|
+
/**
|
|
380
|
+
* Reconciles the current isolate with the history isolate.
|
|
381
|
+
* If the current isolate is of a different type than the history isolate,
|
|
382
|
+
* the current isolate is returned.
|
|
383
|
+
* Otherwise, the reconciler function is called to determine the next isolate.
|
|
384
|
+
* If the reconciler function returns null or undefined, the base reconciler is used.
|
|
385
|
+
* If no history isolate exists, the current isolate is returned.
|
|
386
|
+
* @param node The current isolate to reconcile.
|
|
387
|
+
* @returns The next isolate after reconciliation.
|
|
388
|
+
*/
|
|
389
|
+
static reconcile(node) {
|
|
390
|
+
const localHistoryNode = useHistoryIsolateAtCurrentPosition();
|
|
391
|
+
const nextNodeResult = pickNextNode(node, localHistoryNode);
|
|
392
|
+
vestUtils.invariant(nextNodeResult, ErrorStrings.UNABLE_TO_PICK_NEXT_ISOLATE);
|
|
393
|
+
return nextNodeResult;
|
|
394
|
+
}
|
|
395
|
+
static dropNextNodesOnReorder(reorderLogic, newNode, prevNode) {
|
|
396
|
+
const didReorder = reorderLogic(newNode, prevNode);
|
|
397
|
+
if (didReorder) {
|
|
398
|
+
removeAllNextNodesInIsolate();
|
|
399
|
+
}
|
|
400
|
+
return didReorder;
|
|
401
|
+
}
|
|
402
|
+
static handleIsolateNodeWithKey(node) {
|
|
403
|
+
vestUtils.invariant(IsolateInspector.usesKey(node));
|
|
404
|
+
const prevNodeByKey = useHistoryKey(node.key);
|
|
405
|
+
let nextNode = node;
|
|
406
|
+
if (!vestUtils.isNullish(prevNodeByKey)) {
|
|
407
|
+
nextNode = prevNodeByKey;
|
|
408
|
+
}
|
|
409
|
+
useSetIsolateKey(node.key, node);
|
|
410
|
+
return nextNode;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function pickNextNode(currentNode, historyNode) {
|
|
414
|
+
var _a;
|
|
415
|
+
if (vestUtils.isNullish(historyNode)) {
|
|
416
|
+
return handleNoHistoryNode(currentNode);
|
|
417
|
+
}
|
|
418
|
+
if (!isSameIsolateType(currentNode, historyNode)) {
|
|
419
|
+
return currentNode;
|
|
420
|
+
}
|
|
421
|
+
const reconciler = useReconciler();
|
|
422
|
+
return ((_a = reconciler(currentNode, historyNode)) !== null && _a !== void 0 ? _a : BaseReconciler(currentNode, historyNode));
|
|
423
|
+
}
|
|
424
|
+
function handleNoHistoryNode(newNode) {
|
|
425
|
+
if (IsolateInspector.usesKey(newNode)) {
|
|
426
|
+
return Reconciler.handleIsolateNodeWithKey(newNode);
|
|
427
|
+
}
|
|
428
|
+
return newNode;
|
|
429
|
+
}
|
|
430
|
+
function removeAllNextNodesInIsolate() {
|
|
431
|
+
const currentNode = useIsolate();
|
|
432
|
+
const historyNode = useHistoryIsolate();
|
|
433
|
+
if (!historyNode || !currentNode) {
|
|
434
|
+
// This is probably unreachable, but TS is not convinced.
|
|
435
|
+
// Let's play it safe.
|
|
436
|
+
/* istanbul ignore next */
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
IsolateMutator.slice(historyNode, IsolateInspector.cursor(currentNode));
|
|
440
|
+
}
|
|
440
441
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
[IsolateKeys.Keys]: null,
|
|
497
|
-
[IsolateKeys.Parent]: null,
|
|
498
|
-
[IsolateKeys.Type]: type,
|
|
499
|
-
[IsolateKeys.Data]: data,
|
|
500
|
-
[IsolateKeys.Status]: exports.IsolateStatus.INITIAL,
|
|
501
|
-
children: null,
|
|
502
|
-
key,
|
|
503
|
-
output: null,
|
|
504
|
-
};
|
|
505
|
-
}
|
|
442
|
+
class Isolate {
|
|
443
|
+
static create(type, callback, payload = undefined, key) {
|
|
444
|
+
const parent = useIsolate();
|
|
445
|
+
const newCreatedNode = IsolateMutator.setParent(baseIsolate(type, payload, key), parent);
|
|
446
|
+
const nextIsolateChild = Reconciler.reconcile(newCreatedNode);
|
|
447
|
+
const localHistoryNode = useHistoryIsolateAtCurrentPosition();
|
|
448
|
+
const output = Object.is(nextIsolateChild, newCreatedNode)
|
|
449
|
+
? useRunAsNew(localHistoryNode, newCreatedNode, callback)
|
|
450
|
+
: nextIsolateChild.output;
|
|
451
|
+
IsolateMutator.setParent(nextIsolateChild, parent);
|
|
452
|
+
IsolateMutator.saveOutput(nextIsolateChild, output);
|
|
453
|
+
addNodeToHistory(nextIsolateChild);
|
|
454
|
+
return nextIsolateChild;
|
|
455
|
+
}
|
|
456
|
+
static isIsolate(node) {
|
|
457
|
+
return vestUtils.isNotNullish(node) && node[IsolateKeys.Type];
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Creates a new child isolate context where the local history node is the current history node, thus advancing the history cursor.
|
|
462
|
+
* Runs the callback function and returns its output.
|
|
463
|
+
* @param localHistoryNode The local history node.
|
|
464
|
+
* @param current The current isolate.
|
|
465
|
+
* @param callback The callback function to execute.
|
|
466
|
+
* @returns The output of the callback function.
|
|
467
|
+
*/
|
|
468
|
+
function useRunAsNew(localHistoryNode, current, callback) {
|
|
469
|
+
const runtimeRoot = useRuntimeRoot();
|
|
470
|
+
const emit = useEmit();
|
|
471
|
+
// We're creating a new child isolate context where the local history node
|
|
472
|
+
// is the current history node, thus advancing the history cursor.
|
|
473
|
+
const output = Run(Object.assign({ historyNode: localHistoryNode, runtimeNode: current }, (!runtimeRoot && { runtimeRoot: current })), () => {
|
|
474
|
+
emit(RuntimeEvents.ISOLATE_ENTER, current);
|
|
475
|
+
const output = callback(current);
|
|
476
|
+
if (vestUtils.isPromise(output)) {
|
|
477
|
+
emit(RuntimeEvents.ISOLATE_PENDING, current);
|
|
478
|
+
output.then(iso => {
|
|
479
|
+
if (Isolate.isIsolate(iso)) {
|
|
480
|
+
IsolateMutator.addChild(current, iso);
|
|
481
|
+
}
|
|
482
|
+
emit(RuntimeEvents.ISOLATE_DONE, current);
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
emit(RuntimeEvents.ISOLATE_DONE, current);
|
|
487
|
+
}
|
|
488
|
+
return output;
|
|
489
|
+
});
|
|
490
|
+
current.output = output;
|
|
491
|
+
return output;
|
|
492
|
+
}
|
|
493
|
+
function baseIsolate(type, payload = undefined, key = null) {
|
|
494
|
+
const _a = payload !== null && payload !== void 0 ? payload : {}, { allowReorder, status } = _a, data = __rest(_a, ["allowReorder", "status"]);
|
|
495
|
+
return Object.assign(Object.assign({ [IsolateKeys.AllowReorder]: allowReorder, [IsolateKeys.AbortController]: new AbortController(), [IsolateKeys.Keys]: null, [IsolateKeys.Parent]: null, [IsolateKeys.Type]: type, [IsolateKeys.Data]: data }, (status && { [IsolateKeys.Status]: status })), { children: null, key, output: null });
|
|
496
|
+
}
|
|
506
497
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
498
|
+
// eslint-disable-next-line
|
|
499
|
+
function walk(startNode, callback, visitOnly) {
|
|
500
|
+
// If the startNode has no children, there is nothing to walk.
|
|
501
|
+
if (vestUtils.isNullish(startNode.children)) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
let broke = false;
|
|
505
|
+
// For each child Isolate object, call the callback function.
|
|
506
|
+
for (const isolate of startNode.children) {
|
|
507
|
+
if (broke) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
// If visitOnly is not provided or the predicate is satisfied, call the callback function.
|
|
511
|
+
if (vestUtils.isNullish(visitOnly) || vestUtils.optionalFunctionValue(visitOnly, isolate)) {
|
|
512
|
+
callback(isolate, breakout);
|
|
513
|
+
}
|
|
514
|
+
// If the breakout function has been called, stop the walk.
|
|
515
|
+
if (broke) {
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
// Recursively walk through the child Isolate object.
|
|
519
|
+
walk(isolate, (child, innerBreakout) => {
|
|
520
|
+
callback(child, () => {
|
|
521
|
+
innerBreakout();
|
|
522
|
+
breakout();
|
|
523
|
+
});
|
|
524
|
+
}, visitOnly);
|
|
525
|
+
}
|
|
526
|
+
function breakout() {
|
|
527
|
+
broke = true;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
// This function returns true if the given predicate function returns true for any Isolate object in the tree.
|
|
531
|
+
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
532
|
+
function some(startNode, predicate, visitOnly) {
|
|
533
|
+
let hasMatch = false;
|
|
534
|
+
// Call the walk function with a callback function that sets hasMatch to true if the predicate is satisfied.
|
|
535
|
+
walk(startNode, (node, breakout) => {
|
|
536
|
+
if (predicate(node)) {
|
|
537
|
+
breakout();
|
|
538
|
+
hasMatch = true;
|
|
539
|
+
}
|
|
540
|
+
}, visitOnly);
|
|
541
|
+
return hasMatch;
|
|
542
|
+
}
|
|
543
|
+
// This function returns true if the given predicate function returns true for any Isolate object in the tree.
|
|
544
|
+
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
545
|
+
function has(startNode, match) {
|
|
546
|
+
return some(startNode, () => true, match);
|
|
547
|
+
}
|
|
548
|
+
// traverses up to a parent node that satisfies the predicate
|
|
549
|
+
// and returns the first direct descendant that satisfies the predicate
|
|
550
|
+
function findClosest(startNode, predicate) {
|
|
551
|
+
var _a, _b;
|
|
552
|
+
let found = null;
|
|
553
|
+
let current = startNode;
|
|
554
|
+
while (current) {
|
|
555
|
+
found = (_b = (_a = current.children) === null || _a === void 0 ? void 0 : _a.find(predicate)) !== null && _b !== void 0 ? _b : null;
|
|
556
|
+
if (found) {
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
current = current.parent;
|
|
560
|
+
}
|
|
561
|
+
return found;
|
|
562
|
+
}
|
|
563
|
+
// This function returns the first Isolate object in the tree that satisfies the given predicate function.
|
|
564
|
+
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
565
|
+
function find(startNode, predicate, visitOnly) {
|
|
566
|
+
let found = null;
|
|
567
|
+
// Call the walk function with a callback function that sets found to the current node if the predicate is satisfied.
|
|
568
|
+
walk(startNode, (node, breakout) => {
|
|
569
|
+
if (predicate(node)) {
|
|
570
|
+
breakout();
|
|
571
|
+
found = node;
|
|
572
|
+
}
|
|
573
|
+
}, visitOnly);
|
|
574
|
+
return found;
|
|
575
|
+
}
|
|
576
|
+
// This function returns true if the given predicate function returns true for every Isolate object in the tree.
|
|
577
|
+
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
578
|
+
function every(startNode, predicate, visitOnly) {
|
|
579
|
+
let hasMatch = true;
|
|
580
|
+
walk(startNode, (node, breakout) => {
|
|
581
|
+
if (!predicate(node)) {
|
|
582
|
+
breakout();
|
|
583
|
+
hasMatch = false;
|
|
584
|
+
}
|
|
585
|
+
}, visitOnly);
|
|
586
|
+
return hasMatch;
|
|
587
|
+
}
|
|
588
|
+
// This function removes all Isolate objects in the tree that
|
|
589
|
+
// satisfy the given predicate function and have a parent.
|
|
590
|
+
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
591
|
+
function pluck(startNode, predicate, visitOnly) {
|
|
592
|
+
walk(startNode, node => {
|
|
593
|
+
if (predicate(node) && node.parent) {
|
|
594
|
+
IsolateMutator.removeChild(node.parent, node);
|
|
595
|
+
}
|
|
596
|
+
}, visitOnly);
|
|
597
|
+
}
|
|
598
|
+
// Returns the closest ancestor Isolate object of the given
|
|
599
|
+
//startNode that satisfies the given predicate function.
|
|
600
|
+
function closest(startNode, predicate) {
|
|
601
|
+
let current = startNode;
|
|
602
|
+
do {
|
|
603
|
+
if (predicate(current)) {
|
|
604
|
+
return current;
|
|
605
|
+
}
|
|
606
|
+
current = current.parent;
|
|
607
|
+
} while (current);
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
// This function returns true if the closest ancestor Isolates of the
|
|
611
|
+
// given startNode that satisfies the given predicate function exists.
|
|
612
|
+
function closestExists(startNode, predicate) {
|
|
613
|
+
return !!closest(startNode, predicate);
|
|
614
|
+
}
|
|
624
615
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
616
|
+
var IsolateWalker = /*#__PURE__*/Object.freeze({
|
|
617
|
+
__proto__: null,
|
|
618
|
+
closest: closest,
|
|
619
|
+
closestExists: closestExists,
|
|
620
|
+
every: every,
|
|
621
|
+
find: find,
|
|
622
|
+
findClosest: findClosest,
|
|
623
|
+
has: has,
|
|
624
|
+
pluck: pluck,
|
|
625
|
+
some: some,
|
|
626
|
+
walk: walk
|
|
627
|
+
});
|
|
637
628
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
629
|
+
class IsolateSerializer {
|
|
630
|
+
// eslint-disable-next-line max-statements, complexity
|
|
631
|
+
static deserialize(node) {
|
|
632
|
+
// the assumption is that the tree is built correctly,
|
|
633
|
+
// but the children are missing the parent property to
|
|
634
|
+
// avoid circular references during serialization.
|
|
635
|
+
// in the same way, the parents are missing the `keys` property
|
|
636
|
+
// to avoid circular references during serialization.
|
|
637
|
+
// we need to rebuild the tree and add back the parent property to the children
|
|
638
|
+
// and the keys property to the parents.
|
|
639
|
+
const root = vestUtils.isStringValue(node)
|
|
640
|
+
? JSON.parse(node)
|
|
641
|
+
: Object.assign({}, node);
|
|
642
|
+
IsolateSerializer.validateIsolate(root);
|
|
643
|
+
const queue = [root];
|
|
644
|
+
while (queue.length) {
|
|
645
|
+
const current = queue.shift();
|
|
646
|
+
const children = IsolateSerializer.getChildren(current);
|
|
647
|
+
for (const key in MinifiedToKey) {
|
|
648
|
+
const value = current[key];
|
|
649
|
+
if (vestUtils.isNotNullish(value)) {
|
|
650
|
+
current[MinifiedToKey[key]] = value;
|
|
651
|
+
delete current[key];
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (!children) {
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
current.children = children.map(child => {
|
|
658
|
+
var _a;
|
|
659
|
+
const nextChild = Object.assign({}, child);
|
|
660
|
+
IsolateMutator.setParent(nextChild, current);
|
|
661
|
+
queue.push(nextChild);
|
|
662
|
+
const key = nextChild.key;
|
|
663
|
+
if (key) {
|
|
664
|
+
current.keys = (_a = current.keys) !== null && _a !== void 0 ? _a : {};
|
|
665
|
+
current.keys[key] = nextChild;
|
|
666
|
+
}
|
|
667
|
+
return nextChild;
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
return root;
|
|
671
|
+
}
|
|
672
|
+
static serialize(isolate) {
|
|
673
|
+
if (vestUtils.isNullish(isolate)) {
|
|
674
|
+
return '';
|
|
675
|
+
}
|
|
676
|
+
return JSON.stringify(transformIsolate(isolate));
|
|
677
|
+
}
|
|
678
|
+
static getChildren(node) {
|
|
679
|
+
return node.children ? [...node.children] : null;
|
|
680
|
+
}
|
|
681
|
+
static validateIsolate(node) {
|
|
682
|
+
vestUtils.invariant(vestUtils.hasOwnProperty(node, IsolateKeys.Type) ||
|
|
683
|
+
vestUtils.hasOwnProperty(node, KeyToMinified[IsolateKeys.Type]), vestUtils.text(ErrorStrings.INVALID_ISOLATE_CANNOT_PARSE));
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
// eslint-disable-next-line max-statements, complexity
|
|
687
|
+
function transformIsolate(isolate) {
|
|
688
|
+
const next = {};
|
|
689
|
+
if (isolate.children) {
|
|
690
|
+
next.children = isolate.children.map(transformIsolate);
|
|
691
|
+
}
|
|
692
|
+
for (const key in isolate) {
|
|
693
|
+
if (key === 'children') {
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
if (isKeyExcluededFromDump(key)) {
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
const value = isolate[key];
|
|
700
|
+
if (vestUtils.isNullish(value)) {
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
if (vestUtils.hasOwnProperty(KeyToMinified, key)) {
|
|
704
|
+
next[KeyToMinified[key]] = value;
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
next[key] = value;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return next;
|
|
711
|
+
}
|
|
712
|
+
function isKeyExcluededFromDump(key) {
|
|
713
|
+
return ExcludedFromDump.includes(key);
|
|
714
|
+
}
|
|
724
715
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
716
|
+
exports.Bus = Bus;
|
|
717
|
+
exports.Isolate = Isolate;
|
|
718
|
+
exports.IsolateInspector = IsolateInspector;
|
|
719
|
+
exports.IsolateMutator = IsolateMutator;
|
|
720
|
+
exports.IsolateSelectors = IsolateSelectors;
|
|
721
|
+
exports.IsolateSerializer = IsolateSerializer;
|
|
722
|
+
exports.Reconciler = Reconciler;
|
|
723
|
+
exports.RuntimeEvents = RuntimeEvents;
|
|
724
|
+
exports.VestRuntime = RuntimeApi;
|
|
725
|
+
exports.Walker = IsolateWalker;
|
|
734
726
|
|
|
735
727
|
}));
|
|
736
728
|
//# sourceMappingURL=vestjs-runtime.development.js.map
|