vestjs-runtime 0.1.0-dev-ae6b14
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/vestjs-runtime.development.js +388 -0
- package/dist/cjs/vestjs-runtime.js +7 -0
- package/dist/cjs/vestjs-runtime.production.js +1 -0
- package/dist/es/package.json +1 -0
- package/dist/es/vestjs-runtime.development.js +383 -0
- package/dist/es/vestjs-runtime.production.js +1 -0
- package/dist/umd/vestjs-runtime.development.js +391 -0
- package/dist/umd/vestjs-runtime.production.js +1 -0
- package/package.json +48 -0
- package/types/vestjs-runtime.d.ts +143 -0
- package/types/vestjs-runtime.d.ts.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 ealush
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vestUtils = require('vest-utils');
|
|
4
|
+
var context = require('context');
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line
|
|
7
|
+
function walk(startNode, callback, visitOnly) {
|
|
8
|
+
// If the startNode has no children, there is nothing to walk.
|
|
9
|
+
if (vestUtils.isNullish(startNode.children)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
let broke = false;
|
|
13
|
+
// For each child Isolate object, call the callback function.
|
|
14
|
+
for (const isolate of startNode.children) {
|
|
15
|
+
if (broke) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
// If visitOnly is not provided or the predicate is satisfied, call the callback function.
|
|
19
|
+
if (vestUtils.isNullish(visitOnly) || vestUtils.optionalFunctionValue(visitOnly, isolate)) {
|
|
20
|
+
callback(isolate, breakout);
|
|
21
|
+
}
|
|
22
|
+
// If the breakout function has been called, stop the walk.
|
|
23
|
+
if (broke) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// Recursively walk through the child Isolate object.
|
|
27
|
+
walk(isolate, (child, innerBreakout) => {
|
|
28
|
+
callback(child, () => {
|
|
29
|
+
innerBreakout();
|
|
30
|
+
breakout();
|
|
31
|
+
});
|
|
32
|
+
}, visitOnly);
|
|
33
|
+
}
|
|
34
|
+
function breakout() {
|
|
35
|
+
broke = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// This function returns true if the given predicate function returns true for any Isolate object in the tree.
|
|
39
|
+
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
40
|
+
function some(startNode, predicate, visitOnly) {
|
|
41
|
+
let hasMatch = false;
|
|
42
|
+
// Call the walk function with a callback function that sets hasMatch to true if the predicate is satisfied.
|
|
43
|
+
walk(startNode, (node, breakout) => {
|
|
44
|
+
if (predicate(node)) {
|
|
45
|
+
breakout();
|
|
46
|
+
hasMatch = true;
|
|
47
|
+
}
|
|
48
|
+
}, visitOnly);
|
|
49
|
+
return hasMatch;
|
|
50
|
+
}
|
|
51
|
+
// This function returns true if the given predicate function returns true for any Isolate object in the tree.
|
|
52
|
+
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
53
|
+
function has(startNode, match) {
|
|
54
|
+
return some(startNode, () => true, match);
|
|
55
|
+
}
|
|
56
|
+
// This function returns the first Isolate object in the tree that satisfies the given predicate function.
|
|
57
|
+
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
58
|
+
function find(startNode, predicate, visitOnly) {
|
|
59
|
+
let found = null;
|
|
60
|
+
// Call the walk function with a callback function that sets found to the current node if the predicate is satisfied.
|
|
61
|
+
walk(startNode, (node, breakout) => {
|
|
62
|
+
if (predicate(node)) {
|
|
63
|
+
breakout();
|
|
64
|
+
found = node;
|
|
65
|
+
}
|
|
66
|
+
}, visitOnly);
|
|
67
|
+
return found;
|
|
68
|
+
}
|
|
69
|
+
// This function returns true if the given predicate function returns true for every Isolate object in the tree.
|
|
70
|
+
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
71
|
+
function every(startNode, predicate, visitOnly) {
|
|
72
|
+
let hasMatch = true;
|
|
73
|
+
walk(startNode, (node, breakout) => {
|
|
74
|
+
if (!predicate(node)) {
|
|
75
|
+
breakout();
|
|
76
|
+
hasMatch = false;
|
|
77
|
+
}
|
|
78
|
+
}, visitOnly);
|
|
79
|
+
return hasMatch;
|
|
80
|
+
}
|
|
81
|
+
// This function removes all Isolate objects in the tree that
|
|
82
|
+
// satisfy the given predicate function and have a parent.
|
|
83
|
+
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
84
|
+
function pluck(startNode, predicate, visitOnly) {
|
|
85
|
+
walk(startNode, node => {
|
|
86
|
+
if (predicate(node) && node.parent) {
|
|
87
|
+
node.parent.removeChild(node);
|
|
88
|
+
}
|
|
89
|
+
}, visitOnly);
|
|
90
|
+
}
|
|
91
|
+
// Returns the closest ancestor Isolate object of the given
|
|
92
|
+
//startNode that satisfies the given predicate function.
|
|
93
|
+
function closest(startNode, predicate) {
|
|
94
|
+
let current = startNode;
|
|
95
|
+
while (current.parent) {
|
|
96
|
+
if (predicate(current)) {
|
|
97
|
+
return current;
|
|
98
|
+
}
|
|
99
|
+
current = current.parent;
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
// This function returns true if the closest ancestor Isolates of the
|
|
104
|
+
// given startNode that satisfies the given predicate function exists.
|
|
105
|
+
function closestExists(startNode, predicate) {
|
|
106
|
+
return !!closest(startNode, predicate);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var IsolateWalker = /*#__PURE__*/Object.freeze({
|
|
110
|
+
__proto__: null,
|
|
111
|
+
closest: closest,
|
|
112
|
+
closestExists: closestExists,
|
|
113
|
+
every: every,
|
|
114
|
+
find: find,
|
|
115
|
+
has: has,
|
|
116
|
+
pluck: pluck,
|
|
117
|
+
some: some,
|
|
118
|
+
walk: walk
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
var ErrorStrings;
|
|
122
|
+
(function (ErrorStrings) {
|
|
123
|
+
ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
|
|
124
|
+
ErrorStrings["ENCOUNTERED_THE_SAME_KEY_TWICE"] = "Encountered the same test key \"{key}\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.";
|
|
125
|
+
})(ErrorStrings || (ErrorStrings = {}));
|
|
126
|
+
|
|
127
|
+
const PersistedContext = context.createCascade((stateRef, parentContext) => {
|
|
128
|
+
if (parentContext) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
vestUtils.invariant(stateRef.historyRoot);
|
|
132
|
+
const [historyRootNode] = stateRef.historyRoot();
|
|
133
|
+
const ctxRef = {};
|
|
134
|
+
vestUtils.assign(ctxRef, {
|
|
135
|
+
historyNode: historyRootNode,
|
|
136
|
+
runtimeNode: null,
|
|
137
|
+
runtimeRoot: null,
|
|
138
|
+
stateRef,
|
|
139
|
+
});
|
|
140
|
+
return ctxRef;
|
|
141
|
+
});
|
|
142
|
+
const Run = PersistedContext.run;
|
|
143
|
+
const RuntimeApi = {
|
|
144
|
+
Run,
|
|
145
|
+
createRef,
|
|
146
|
+
persist,
|
|
147
|
+
reset,
|
|
148
|
+
useAvailableRoot,
|
|
149
|
+
useBus,
|
|
150
|
+
useCurrentCursor,
|
|
151
|
+
useEmit,
|
|
152
|
+
usePrepareEmitter,
|
|
153
|
+
useXAppData,
|
|
154
|
+
};
|
|
155
|
+
function useBus() {
|
|
156
|
+
return useX().stateRef.Bus;
|
|
157
|
+
}
|
|
158
|
+
/*
|
|
159
|
+
Returns an emitter, but it also has a shortcut for emitting an event immediately
|
|
160
|
+
by passing an event name.
|
|
161
|
+
*/
|
|
162
|
+
function useEmit() {
|
|
163
|
+
return persist(useBus().emit);
|
|
164
|
+
}
|
|
165
|
+
function usePrepareEmitter(event) {
|
|
166
|
+
const emit = useEmit();
|
|
167
|
+
return (arg) => emit(event, arg);
|
|
168
|
+
}
|
|
169
|
+
function useXAppData() {
|
|
170
|
+
return useX().stateRef.appData;
|
|
171
|
+
}
|
|
172
|
+
function createRef(setter) {
|
|
173
|
+
return Object.freeze({
|
|
174
|
+
historyRoot: vestUtils.tinyState.createTinyState(null),
|
|
175
|
+
Bus: vestUtils.bus.createBus(),
|
|
176
|
+
appData: vestUtils.optionalFunctionValue(setter),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function persist(cb) {
|
|
180
|
+
const prev = PersistedContext.useX();
|
|
181
|
+
return ((...args) => {
|
|
182
|
+
var _a;
|
|
183
|
+
const ctxToUse = (_a = PersistedContext.use()) !== null && _a !== void 0 ? _a : prev;
|
|
184
|
+
return PersistedContext.run(ctxToUse.stateRef, () => cb(...args));
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function useX() {
|
|
188
|
+
return PersistedContext.useX();
|
|
189
|
+
}
|
|
190
|
+
function useHistoryRoot() {
|
|
191
|
+
return useX().stateRef.historyRoot();
|
|
192
|
+
}
|
|
193
|
+
function useHistoryNode() {
|
|
194
|
+
return useX().historyNode;
|
|
195
|
+
}
|
|
196
|
+
function useSetHistory(history) {
|
|
197
|
+
const [, setHistoryRoot] = useHistoryRoot();
|
|
198
|
+
setHistoryRoot(history);
|
|
199
|
+
}
|
|
200
|
+
function useHistoryKey(key) {
|
|
201
|
+
var _a;
|
|
202
|
+
if (vestUtils.isNullish(key)) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const historyNode = useX().historyNode;
|
|
206
|
+
return (_a = historyNode === null || historyNode === void 0 ? void 0 : historyNode.keys[key]) !== null && _a !== void 0 ? _a : null;
|
|
207
|
+
}
|
|
208
|
+
function useIsolate() {
|
|
209
|
+
var _a;
|
|
210
|
+
return (_a = useX().runtimeNode) !== null && _a !== void 0 ? _a : null;
|
|
211
|
+
}
|
|
212
|
+
function useCurrentCursor() {
|
|
213
|
+
var _a, _b;
|
|
214
|
+
return (_b = (_a = useIsolate()) === null || _a === void 0 ? void 0 : _a.cursor()) !== null && _b !== void 0 ? _b : 0;
|
|
215
|
+
}
|
|
216
|
+
function useRuntimeRoot() {
|
|
217
|
+
return useX().runtimeRoot;
|
|
218
|
+
}
|
|
219
|
+
function useSetNextIsolateChild(child) {
|
|
220
|
+
const currentIsolate = useIsolate();
|
|
221
|
+
vestUtils.invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
|
|
222
|
+
currentIsolate.addChild(child);
|
|
223
|
+
}
|
|
224
|
+
function useSetIsolateKey(key, value) {
|
|
225
|
+
if (!key) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const currentIsolate = useIsolate();
|
|
229
|
+
vestUtils.invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
|
|
230
|
+
if (vestUtils.isNullish(currentIsolate.keys[key])) {
|
|
231
|
+
currentIsolate.keys[key] = value;
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
vestUtils.deferThrow(vestUtils.text(ErrorStrings.ENCOUNTERED_THE_SAME_KEY_TWICE, { key }));
|
|
235
|
+
}
|
|
236
|
+
function useAvailableRoot() {
|
|
237
|
+
const root = useRuntimeRoot();
|
|
238
|
+
if (root) {
|
|
239
|
+
return root;
|
|
240
|
+
}
|
|
241
|
+
const [historyRoot] = useHistoryRoot();
|
|
242
|
+
return historyRoot;
|
|
243
|
+
}
|
|
244
|
+
function reset() {
|
|
245
|
+
const [, , resetHistoryRoot] = useHistoryRoot();
|
|
246
|
+
resetHistoryRoot();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function BaseReconciler(currentNode, historicNode) {
|
|
250
|
+
if (vestUtils.isNullish(historicNode)) {
|
|
251
|
+
return currentNode;
|
|
252
|
+
}
|
|
253
|
+
return currentNode;
|
|
254
|
+
}
|
|
255
|
+
class Reconciler {
|
|
256
|
+
static reconcile(reconciler, node, callback) {
|
|
257
|
+
var _a;
|
|
258
|
+
const parent = useIsolate();
|
|
259
|
+
const historyNode = useHistoryNode();
|
|
260
|
+
let localHistoryNode = historyNode;
|
|
261
|
+
if (parent) {
|
|
262
|
+
// If we have a parent, we need to get the history node from the parent's children
|
|
263
|
+
// We take the history node from the cursor of the active node's children
|
|
264
|
+
localHistoryNode =
|
|
265
|
+
(_a = historyNode === null || historyNode === void 0 ? void 0 : historyNode.at(useCurrentCursor())) !== null && _a !== void 0 ? _a : null;
|
|
266
|
+
}
|
|
267
|
+
const nextNode = reconciler(node, localHistoryNode);
|
|
268
|
+
vestUtils.invariant(nextNode);
|
|
269
|
+
if (Object.is(nextNode, node)) {
|
|
270
|
+
return [node, useRunAsNew(localHistoryNode, node, callback)];
|
|
271
|
+
}
|
|
272
|
+
return [nextNode, nextNode.output];
|
|
273
|
+
}
|
|
274
|
+
static removeAllNextNodesInIsolate() {
|
|
275
|
+
const testIsolate = useIsolate();
|
|
276
|
+
const historyNode = useHistoryNode();
|
|
277
|
+
if (!historyNode || !testIsolate) {
|
|
278
|
+
// This is probably unreachable, but TS is not convinced.
|
|
279
|
+
// Let's play it safe.
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
historyNode.slice(useCurrentCursor());
|
|
283
|
+
}
|
|
284
|
+
static handleIsolateNodeWithKey(node) {
|
|
285
|
+
vestUtils.invariant(node.usesKey());
|
|
286
|
+
const prevNodeByKey = useHistoryKey(node.key);
|
|
287
|
+
let nextNode = node;
|
|
288
|
+
if (!vestUtils.isNullish(prevNodeByKey)) {
|
|
289
|
+
nextNode = prevNodeByKey;
|
|
290
|
+
}
|
|
291
|
+
useSetIsolateKey(node.key, node);
|
|
292
|
+
return nextNode;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function useRunAsNew(localHistoryNode, current, callback) {
|
|
296
|
+
const runtimeRoot = useRuntimeRoot();
|
|
297
|
+
// We're creating a new child isolate context where the local history node
|
|
298
|
+
// is the current history node, thus advancing the history cursor.
|
|
299
|
+
const output = Run(Object.assign({ historyNode: localHistoryNode, runtimeNode: current }, (!runtimeRoot && { runtimeRoot: current })), () => callback(current));
|
|
300
|
+
current.output = output;
|
|
301
|
+
return output;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
class Isolate {
|
|
305
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
|
306
|
+
constructor(_data) {
|
|
307
|
+
this.children = [];
|
|
308
|
+
this.keys = {};
|
|
309
|
+
this.parent = null;
|
|
310
|
+
this.key = null;
|
|
311
|
+
this.allowReorder = false;
|
|
312
|
+
}
|
|
313
|
+
setParent(parent) {
|
|
314
|
+
this.parent = parent;
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
saveOutput(output) {
|
|
318
|
+
this.output = output;
|
|
319
|
+
return this;
|
|
320
|
+
}
|
|
321
|
+
setKey(key) {
|
|
322
|
+
this.key = key;
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
usesKey() {
|
|
326
|
+
return vestUtils.isNotNullish(this.key);
|
|
327
|
+
}
|
|
328
|
+
addChild(child) {
|
|
329
|
+
vestUtils.invariant(this.children);
|
|
330
|
+
this.children.push(child);
|
|
331
|
+
}
|
|
332
|
+
removeChild(node) {
|
|
333
|
+
var _a, _b;
|
|
334
|
+
this.children = (_b = (_a = this.children) === null || _a === void 0 ? void 0 : _a.filter(child => child !== node)) !== null && _b !== void 0 ? _b : null;
|
|
335
|
+
}
|
|
336
|
+
slice(at) {
|
|
337
|
+
if (vestUtils.isNullish(this.children)) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
this.children.length = at;
|
|
341
|
+
}
|
|
342
|
+
at(at) {
|
|
343
|
+
var _a, _b;
|
|
344
|
+
return (_b = (_a = this.children) === null || _a === void 0 ? void 0 : _a[at]) !== null && _b !== void 0 ? _b : null;
|
|
345
|
+
}
|
|
346
|
+
cursor() {
|
|
347
|
+
var _a, _b;
|
|
348
|
+
return (_b = (_a = this.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
349
|
+
}
|
|
350
|
+
shouldAllowReorder() {
|
|
351
|
+
var _a;
|
|
352
|
+
return (_a = closestExists(this, node => node.allowReorder)) !== null && _a !== void 0 ? _a : false;
|
|
353
|
+
}
|
|
354
|
+
get rootNode() {
|
|
355
|
+
var _a;
|
|
356
|
+
return (_a = closest(this, node => vestUtils.isNullish(node.parent))) !== null && _a !== void 0 ? _a : this;
|
|
357
|
+
}
|
|
358
|
+
static create(callback, data) {
|
|
359
|
+
return this.createImplementation(callback, data);
|
|
360
|
+
}
|
|
361
|
+
static createImplementation(callback, data) {
|
|
362
|
+
const parent = useIsolate();
|
|
363
|
+
const newCreatedNode = new this(data).setParent(parent);
|
|
364
|
+
const [nextIsolateChild, output] = Reconciler.reconcile(this.reconciler, newCreatedNode, callback);
|
|
365
|
+
nextIsolateChild.saveOutput(output);
|
|
366
|
+
this.setNode(nextIsolateChild);
|
|
367
|
+
return nextIsolateChild;
|
|
368
|
+
}
|
|
369
|
+
static setNode(node) {
|
|
370
|
+
const parent = useIsolate();
|
|
371
|
+
if (parent) {
|
|
372
|
+
useSetNextIsolateChild(node);
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
useSetHistory(node);
|
|
376
|
+
}
|
|
377
|
+
node.setParent(parent);
|
|
378
|
+
}
|
|
379
|
+
static is(node) {
|
|
380
|
+
return node instanceof Isolate;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
Isolate.reconciler = BaseReconciler;
|
|
384
|
+
|
|
385
|
+
exports.Isolate = Isolate;
|
|
386
|
+
exports.Reconciler = Reconciler;
|
|
387
|
+
exports.VestRuntime = RuntimeApi;
|
|
388
|
+
exports.Walker = IsolateWalker;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("vest-utils"),e=require("context");function n(e,r,i){if(t.isNullish(e.children))return;let s=!1;for(const o of e.children){if(s)return;if((t.isNullish(i)||t.optionalFunctionValue(i,o))&&r(o,u),s)return;n(o,((t,e)=>{r(t,(()=>{e(),u()}))}),i)}function u(){s=!0}}function r(t,e,r){let i=!1;return n(t,((t,n)=>{e(t)&&(n(),i=!0)}),r),i}function i(t,e){let n=t;for(;n.parent;){if(e(n))return n;n=n.parent}return null}function s(t,e){return!!i(t,e)}var u,o=Object.freeze({__proto__:null,closest:i,closestExists:s,every:function(t,e,r){let i=!0;return n(t,((t,n)=>{e(t)||(n(),i=!1)}),r),i},find:function(t,e,r){let i=null;return n(t,((t,n)=>{e(t)&&(n(),i=t)}),r),i},has:function(t,e){return r(t,(()=>!0),e)},pluck:function(t,e,r){n(t,(t=>{e(t)&&t.parent&&t.parent.removeChild(t)}),r)},some:r,walk:n});!function(t){t.NO_ACTIVE_ISOLATE="Not within an active isolate",t.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same test key "{key}" twice. This may lead to tests overriding each other\'s results, or to tests being unexpectedly omitted.'}(u||(u={}));const l=e.createCascade(((e,n)=>{if(n)return null;t.invariant(e.historyRoot);const[r]=e.historyRoot(),i={};return t.assign(i,{historyNode:r,runtimeNode:null,runtimeRoot:null,stateRef:e}),i})),c=l.run,a={Run:c,createRef:function(e){return Object.freeze({historyRoot:t.tinyState.createTinyState(null),Bus:t.bus.createBus(),appData:t.optionalFunctionValue(e)})},persist:f,reset:function(){const[,,t]=p();t()},useAvailableRoot:function(){const t=R();if(t)return t;const[e]=p();return e},useBus:h,useCurrentCursor:E,useEmit:d,usePrepareEmitter:function(t){const e=d();return n=>e(t,n)},useXAppData:function(){return v().stateRef.appData}};function h(){return v().stateRef.Bus}function d(){return f(h().emit)}function f(t){const e=l.useX();return(...n)=>{var r;const i=null!==(r=l.use())&&void 0!==r?r:e;return l.run(i.stateRef,(()=>t(...n)))}}function v(){return l.useX()}function p(){return v().stateRef.historyRoot()}function N(){return v().historyNode}function y(){var t;return null!==(t=v().runtimeNode)&&void 0!==t?t:null}function E(){var t,e;return null!==(e=null===(t=y())||void 0===t?void 0:t.cursor())&&void 0!==e?e:0}function R(){return v().runtimeRoot}class m{static reconcile(e,n,r){var i;const s=y(),u=N();let o=u;s&&(o=null!==(i=null==u?void 0:u.at(E()))&&void 0!==i?i:null);const l=e(n,o);return t.invariant(l),Object.is(l,n)?[n,_(o,n,r)]:[l,l.output]}static removeAllNextNodesInIsolate(){const t=y(),e=N();e&&t&&e.slice(E())}static handleIsolateNodeWithKey(e){t.invariant(e.usesKey());const n=function(e){var n;if(t.isNullish(e))return null;const r=v().historyNode;return null!==(n=null==r?void 0:r.keys[e])&&void 0!==n?n:null}(e.key);let r=e;return t.isNullish(n)||(r=n),function(e,n){if(!e)return;const r=y();t.invariant(r,u.NO_ACTIVE_ISOLATE),t.isNullish(r.keys[e])?r.keys[e]=n:t.deferThrow(t.text(u.ENCOUNTERED_THE_SAME_KEY_TWICE,{key:e}))}(e.key,e),r}}function _(t,e,n){const r=R(),i=c(Object.assign({historyNode:t,runtimeNode:e},!r&&{runtimeRoot:e}),(()=>n(e)));return e.output=i,i}class k{constructor(t){this.children=[],this.keys={},this.parent=null,this.key=null,this.allowReorder=!1}setParent(t){return this.parent=t,this}saveOutput(t){return this.output=t,this}setKey(t){return this.key=t,this}usesKey(){return t.isNotNullish(this.key)}addChild(e){t.invariant(this.children),this.children.push(e)}removeChild(t){var e,n;this.children=null!==(n=null===(e=this.children)||void 0===e?void 0:e.filter((e=>e!==t)))&&void 0!==n?n:null}slice(e){t.isNullish(this.children)||(this.children.length=e)}at(t){var e,n;return null!==(n=null===(e=this.children)||void 0===e?void 0:e[t])&&void 0!==n?n:null}cursor(){var t,e;return null!==(e=null===(t=this.children)||void 0===t?void 0:t.length)&&void 0!==e?e:0}shouldAllowReorder(){var t;return null!==(t=s(this,(t=>t.allowReorder)))&&void 0!==t&&t}get rootNode(){var e;return null!==(e=i(this,(e=>t.isNullish(e.parent))))&&void 0!==e?e:this}static create(t,e){return this.createImplementation(t,e)}static createImplementation(t,e){const n=y(),r=new this(e).setParent(n),[i,s]=m.reconcile(this.reconciler,r,t);return i.saveOutput(s),this.setNode(i),i}static setNode(e){const n=y();n?function(e){const n=y();t.invariant(n,u.NO_ACTIVE_ISOLATE),n.addChild(e)}(e):function(t){const[,e]=p();e(t)}(e),e.setParent(n)}static is(t){return t instanceof k}}k.reconciler=function(e,n){return t.isNullish(n),e},exports.Isolate=k,exports.Reconciler=m,exports.VestRuntime=a,exports.Walker=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|