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