vestjs-runtime 0.0.2-next-1b0637 → 0.0.2-next-2cf993
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/vestjs-runtime.development.js +112 -90
- package/dist/cjs/vestjs-runtime.js +0 -1
- package/dist/cjs/vestjs-runtime.production.js +1 -1
- package/dist/es/vestjs-runtime.development.js +111 -92
- package/dist/es/vestjs-runtime.production.js +1 -1
- package/dist/umd/vestjs-runtime.development.js +112 -90
- package/dist/umd/vestjs-runtime.production.js +1 -1
- package/package.json +5 -4
- package/types/vestjs-runtime.d.ts +44 -49
- package/types/vestjs-runtime.d.ts.map +1 -1
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
var vestUtils = require('vest-utils');
|
|
4
4
|
var context = require('context');
|
|
5
5
|
|
|
6
|
+
class IsolateMutator {
|
|
7
|
+
static setParent(isolate, parent) {
|
|
8
|
+
isolate.parent = parent;
|
|
9
|
+
return isolate;
|
|
10
|
+
}
|
|
11
|
+
static saveOutput(isolate, output) {
|
|
12
|
+
isolate.output = output;
|
|
13
|
+
return isolate;
|
|
14
|
+
}
|
|
15
|
+
static setKey(isolate, key) {
|
|
16
|
+
isolate.key = key;
|
|
17
|
+
return isolate;
|
|
18
|
+
}
|
|
19
|
+
static addChild(isolate, child) {
|
|
20
|
+
vestUtils.invariant(isolate.children);
|
|
21
|
+
isolate.children.push(child);
|
|
22
|
+
}
|
|
23
|
+
static removeChild(isolate, node) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
isolate.children =
|
|
26
|
+
(_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.filter(child => child !== node)) !== null && _b !== void 0 ? _b : null;
|
|
27
|
+
}
|
|
28
|
+
static slice(isolate, at) {
|
|
29
|
+
if (vestUtils.isNullish(isolate.children)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
isolate.children.length = at;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
6
36
|
// eslint-disable-next-line
|
|
7
37
|
function walk(startNode, callback, visitOnly) {
|
|
8
38
|
// If the startNode has no children, there is nothing to walk.
|
|
@@ -84,7 +114,7 @@ function every(startNode, predicate, visitOnly) {
|
|
|
84
114
|
function pluck(startNode, predicate, visitOnly) {
|
|
85
115
|
walk(startNode, node => {
|
|
86
116
|
if (predicate(node) && node.parent) {
|
|
87
|
-
|
|
117
|
+
IsolateMutator.removeChild(node.parent, node);
|
|
88
118
|
}
|
|
89
119
|
}, visitOnly);
|
|
90
120
|
}
|
|
@@ -118,6 +148,36 @@ var IsolateWalker = /*#__PURE__*/Object.freeze({
|
|
|
118
148
|
walk: walk
|
|
119
149
|
});
|
|
120
150
|
|
|
151
|
+
class IsolateInspector {
|
|
152
|
+
static at(isolate, at) {
|
|
153
|
+
var _a, _b;
|
|
154
|
+
if (vestUtils.isNullish(isolate)) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a[at]) !== null && _b !== void 0 ? _b : null;
|
|
158
|
+
}
|
|
159
|
+
static cursor(isolate) {
|
|
160
|
+
var _a, _b;
|
|
161
|
+
if (vestUtils.isNullish(isolate)) {
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
164
|
+
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
165
|
+
}
|
|
166
|
+
static shouldAllowReorder(isolate) {
|
|
167
|
+
var _a;
|
|
168
|
+
if (vestUtils.isNullish(isolate)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
return (_a = closestExists(isolate, node => node.allowReorder)) !== null && _a !== void 0 ? _a : false;
|
|
172
|
+
}
|
|
173
|
+
static usesKey(isolate) {
|
|
174
|
+
if (vestUtils.isNullish(isolate)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return vestUtils.isNotNullish(isolate.key);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
121
181
|
var ErrorStrings;
|
|
122
182
|
(function (ErrorStrings) {
|
|
123
183
|
ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
|
|
@@ -142,30 +202,14 @@ const PersistedContext = context.createCascade((stateRef, parentContext) => {
|
|
|
142
202
|
const Run = PersistedContext.run;
|
|
143
203
|
const RuntimeApi = {
|
|
144
204
|
Run,
|
|
205
|
+
addNodeToHistory,
|
|
145
206
|
createRef,
|
|
146
207
|
persist,
|
|
147
208
|
reset,
|
|
148
209
|
useAvailableRoot,
|
|
149
|
-
useBus,
|
|
150
210
|
useCurrentCursor,
|
|
151
|
-
useEmit,
|
|
152
|
-
usePrepareEmitter,
|
|
153
211
|
useXAppData,
|
|
154
212
|
};
|
|
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
213
|
function useXAppData() {
|
|
170
214
|
return useX().stateRef.appData;
|
|
171
215
|
}
|
|
@@ -193,6 +237,16 @@ function useHistoryRoot() {
|
|
|
193
237
|
function useHistoryNode() {
|
|
194
238
|
return useX().historyNode;
|
|
195
239
|
}
|
|
240
|
+
function addNodeToHistory(node) {
|
|
241
|
+
const parent = useIsolate();
|
|
242
|
+
if (parent) {
|
|
243
|
+
useSetNextIsolateChild(node);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
useSetHistory(node);
|
|
247
|
+
}
|
|
248
|
+
IsolateMutator.setParent(node, parent);
|
|
249
|
+
}
|
|
196
250
|
function useSetHistory(history) {
|
|
197
251
|
const [, setHistoryRoot] = useHistoryRoot();
|
|
198
252
|
setHistoryRoot(history);
|
|
@@ -210,8 +264,8 @@ function useIsolate() {
|
|
|
210
264
|
return (_a = useX().runtimeNode) !== null && _a !== void 0 ? _a : null;
|
|
211
265
|
}
|
|
212
266
|
function useCurrentCursor() {
|
|
213
|
-
|
|
214
|
-
return
|
|
267
|
+
const isolate = useIsolate();
|
|
268
|
+
return isolate ? IsolateInspector.cursor(isolate) : 0;
|
|
215
269
|
}
|
|
216
270
|
function useRuntimeRoot() {
|
|
217
271
|
return useX().runtimeRoot;
|
|
@@ -219,7 +273,7 @@ function useRuntimeRoot() {
|
|
|
219
273
|
function useSetNextIsolateChild(child) {
|
|
220
274
|
const currentIsolate = useIsolate();
|
|
221
275
|
vestUtils.invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
|
|
222
|
-
|
|
276
|
+
IsolateMutator.addChild(currentIsolate, child);
|
|
223
277
|
}
|
|
224
278
|
function useSetIsolateKey(key, value) {
|
|
225
279
|
if (!key) {
|
|
@@ -254,15 +308,13 @@ function BaseReconciler(currentNode, historicNode) {
|
|
|
254
308
|
}
|
|
255
309
|
class Reconciler {
|
|
256
310
|
static reconcile(reconciler, node, callback) {
|
|
257
|
-
var _a;
|
|
258
311
|
const parent = useIsolate();
|
|
259
312
|
const historyNode = useHistoryNode();
|
|
260
313
|
let localHistoryNode = historyNode;
|
|
261
314
|
if (parent) {
|
|
262
315
|
// If we have a parent, we need to get the history node from the parent's children
|
|
263
316
|
// 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;
|
|
317
|
+
localHistoryNode = IsolateInspector.at(historyNode, IsolateInspector.cursor(parent));
|
|
266
318
|
}
|
|
267
319
|
const nextNode = reconciler(node, localHistoryNode);
|
|
268
320
|
vestUtils.invariant(nextNode);
|
|
@@ -277,12 +329,13 @@ class Reconciler {
|
|
|
277
329
|
if (!historyNode || !testIsolate) {
|
|
278
330
|
// This is probably unreachable, but TS is not convinced.
|
|
279
331
|
// Let's play it safe.
|
|
332
|
+
/* istanbul ignore next */
|
|
280
333
|
return;
|
|
281
334
|
}
|
|
282
|
-
|
|
335
|
+
IsolateMutator.slice(historyNode, IsolateInspector.cursor(testIsolate));
|
|
283
336
|
}
|
|
284
337
|
static handleIsolateNodeWithKey(node) {
|
|
285
|
-
vestUtils.invariant(
|
|
338
|
+
vestUtils.invariant(IsolateInspector.usesKey(node));
|
|
286
339
|
const prevNodeByKey = useHistoryKey(node.key);
|
|
287
340
|
let nextNode = node;
|
|
288
341
|
if (!vestUtils.isNullish(prevNodeByKey)) {
|
|
@@ -309,80 +362,49 @@ class Isolate {
|
|
|
309
362
|
this.parent = null;
|
|
310
363
|
this.key = null;
|
|
311
364
|
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;
|
|
365
|
+
this.type = Symbol('Isolate');
|
|
357
366
|
}
|
|
358
367
|
static create(callback, data) {
|
|
359
|
-
return this.createImplementation(callback, data);
|
|
360
|
-
}
|
|
361
|
-
static createImplementation(callback, data) {
|
|
362
368
|
const parent = useIsolate();
|
|
363
|
-
const newCreatedNode = new this(data)
|
|
369
|
+
const newCreatedNode = IsolateMutator.setParent(new this(data), parent);
|
|
364
370
|
const [nextIsolateChild, output] = Reconciler.reconcile(this.reconciler, newCreatedNode, callback);
|
|
365
|
-
|
|
366
|
-
|
|
371
|
+
IsolateMutator.saveOutput(nextIsolateChild, output);
|
|
372
|
+
addNodeToHistory(nextIsolateChild);
|
|
367
373
|
return nextIsolateChild;
|
|
368
374
|
}
|
|
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
375
|
}
|
|
383
376
|
Isolate.reconciler = BaseReconciler;
|
|
384
377
|
|
|
378
|
+
function useBus() {
|
|
379
|
+
return useX().stateRef.Bus;
|
|
380
|
+
}
|
|
381
|
+
/*
|
|
382
|
+
Returns an emitter, but it also has a shortcut for emitting an event immediately
|
|
383
|
+
by passing an event name.
|
|
384
|
+
*/
|
|
385
|
+
function useEmit(event, data) {
|
|
386
|
+
const emit = useBus().emit;
|
|
387
|
+
if (!vestUtils.isNullish(event)) {
|
|
388
|
+
emit(event, data);
|
|
389
|
+
}
|
|
390
|
+
return persist(emit);
|
|
391
|
+
}
|
|
392
|
+
function usePrepareEmitter(event) {
|
|
393
|
+
const emit = useEmit();
|
|
394
|
+
return (arg) => emit(event, arg);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
var Bus = /*#__PURE__*/Object.freeze({
|
|
398
|
+
__proto__: null,
|
|
399
|
+
useBus: useBus,
|
|
400
|
+
useEmit: useEmit,
|
|
401
|
+
usePrepareEmitter: usePrepareEmitter
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
exports.Bus = Bus;
|
|
385
405
|
exports.Isolate = Isolate;
|
|
406
|
+
exports.IsolateInspector = IsolateInspector;
|
|
407
|
+
exports.IsolateMutator = IsolateMutator;
|
|
386
408
|
exports.Reconciler = Reconciler;
|
|
387
409
|
exports.VestRuntime = RuntimeApi;
|
|
388
410
|
exports.Walker = IsolateWalker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("vest-utils"),e=require("context");
|
|
1
|
+
"use strict";var t=require("vest-utils"),e=require("context");class n{static setParent(t,e){return t.parent=e,t}static saveOutput(t,e){return t.output=e,t}static setKey(t,e){return t.key=e,t}static addChild(e,n){t.invariant(e.children),e.children.push(n)}static removeChild(t,e){var n,r;t.children=null!==(r=null===(n=t.children)||void 0===n?void 0:n.filter((t=>t!==e)))&&void 0!==r?r:null}static slice(e,n){t.isNullish(e.children)||(e.children.length=n)}}function r(e,n,i){if(t.isNullish(e.children))return;let s=!1;for(const u of e.children){if(s)return;if((t.isNullish(i)||t.optionalFunctionValue(i,u))&&n(u,o),s)return;r(u,((t,e)=>{n(t,(()=>{e(),o()}))}),i)}function o(){s=!0}}function i(t,e,n){let i=!1;return r(t,((t,n)=>{e(t)&&(n(),i=!0)}),n),i}function s(t,e){let n=t;for(;n.parent;){if(e(n))return n;n=n.parent}return null}function o(t,e){return!!s(t,e)}var u,l=Object.freeze({__proto__:null,closest:s,closestExists:o,every:function(t,e,n){let i=!0;return r(t,((t,n)=>{e(t)||(n(),i=!1)}),n),i},find:function(t,e,n){let i=null;return r(t,((t,n)=>{e(t)&&(n(),i=t)}),n),i},has:function(t,e){return i(t,(()=>!0),e)},pluck:function(t,e,i){r(t,(t=>{e(t)&&t.parent&&n.removeChild(t.parent,t)}),i)},some:i,walk:r});class c{static at(e,n){var r,i;return t.isNullish(e)?null:null!==(i=null===(r=e.children)||void 0===r?void 0:r[n])&&void 0!==i?i:null}static cursor(e){var n,r;return t.isNullish(e)?0:null!==(r=null===(n=e.children)||void 0===n?void 0:n.length)&&void 0!==r?r:0}static shouldAllowReorder(e){var n;return!t.isNullish(e)&&(null!==(n=o(e,(t=>t.allowReorder)))&&void 0!==n&&n)}static usesKey(e){return!t.isNullish(e)&&t.isNotNullish(e.key)}}!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 a=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})),d=a.run,h={Run:d,addNodeToHistory:y,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},useCurrentCursor:function(){const t=E();return t?c.cursor(t):0},useXAppData:function(){return v().stateRef.appData}};function f(t){const e=a.useX();return(...n)=>{var r;const i=null!==(r=a.use())&&void 0!==r?r:e;return a.run(i.stateRef,(()=>t(...n)))}}function v(){return a.useX()}function p(){return v().stateRef.historyRoot()}function N(){return v().historyNode}function y(e){const r=E();r?function(e){const r=E();t.invariant(r,u.NO_ACTIVE_ISOLATE),n.addChild(r,e)}(e):function(t){const[,e]=p();e(t)}(e),n.setParent(e,r)}function E(){var t;return null!==(t=v().runtimeNode)&&void 0!==t?t:null}function R(){return v().runtimeRoot}class _{static reconcile(e,n,r){const i=E(),s=N();let o=s;i&&(o=c.at(s,c.cursor(i)));const u=e(n,o);return t.invariant(u),Object.is(u,n)?[n,m(o,n,r)]:[u,u.output]}static removeAllNextNodesInIsolate(){const t=E(),e=N();e&&t&&n.slice(e,c.cursor(t))}static handleIsolateNodeWithKey(e){t.invariant(c.usesKey(e));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=E();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 m(t,e,n){const r=R(),i=d(Object.assign({historyNode:t,runtimeNode:e},!r&&{runtimeRoot:e}),(()=>n(e)));return e.output=i,i}class I{constructor(t){this.children=[],this.keys={},this.parent=null,this.key=null,this.allowReorder=!1,this.type=Symbol("Isolate")}static create(t,e){const r=E(),i=n.setParent(new this(e),r),[s,o]=_.reconcile(this.reconciler,i,t);return n.saveOutput(s,o),y(s),s}}function T(){return v().stateRef.Bus}function k(e,n){const r=T().emit;return t.isNullish(e)||r(e,n),f(r)}I.reconciler=function(e,n){return t.isNullish(n),e};var O=Object.freeze({__proto__:null,useBus:T,useEmit:k,usePrepareEmitter:function(t){const e=k();return n=>e(t,n)}});exports.Bus=O,exports.Isolate=I,exports.IsolateInspector=c,exports.IsolateMutator=n,exports.Reconciler=_,exports.VestRuntime=h,exports.Walker=l;
|
|
@@ -1,6 +1,36 @@
|
|
|
1
|
-
import { isNullish, optionalFunctionValue,
|
|
1
|
+
import { invariant, isNullish, optionalFunctionValue, isNotNullish, assign, tinyState, bus, deferThrow, text } from 'vest-utils';
|
|
2
2
|
import { createCascade } from 'context';
|
|
3
3
|
|
|
4
|
+
class IsolateMutator {
|
|
5
|
+
static setParent(isolate, parent) {
|
|
6
|
+
isolate.parent = parent;
|
|
7
|
+
return isolate;
|
|
8
|
+
}
|
|
9
|
+
static saveOutput(isolate, output) {
|
|
10
|
+
isolate.output = output;
|
|
11
|
+
return isolate;
|
|
12
|
+
}
|
|
13
|
+
static setKey(isolate, key) {
|
|
14
|
+
isolate.key = key;
|
|
15
|
+
return isolate;
|
|
16
|
+
}
|
|
17
|
+
static addChild(isolate, child) {
|
|
18
|
+
invariant(isolate.children);
|
|
19
|
+
isolate.children.push(child);
|
|
20
|
+
}
|
|
21
|
+
static removeChild(isolate, node) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
isolate.children =
|
|
24
|
+
(_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.filter(child => child !== node)) !== null && _b !== void 0 ? _b : null;
|
|
25
|
+
}
|
|
26
|
+
static slice(isolate, at) {
|
|
27
|
+
if (isNullish(isolate.children)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
isolate.children.length = at;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
4
34
|
// eslint-disable-next-line
|
|
5
35
|
function walk(startNode, callback, visitOnly) {
|
|
6
36
|
// If the startNode has no children, there is nothing to walk.
|
|
@@ -82,7 +112,7 @@ function every(startNode, predicate, visitOnly) {
|
|
|
82
112
|
function pluck(startNode, predicate, visitOnly) {
|
|
83
113
|
walk(startNode, node => {
|
|
84
114
|
if (predicate(node) && node.parent) {
|
|
85
|
-
|
|
115
|
+
IsolateMutator.removeChild(node.parent, node);
|
|
86
116
|
}
|
|
87
117
|
}, visitOnly);
|
|
88
118
|
}
|
|
@@ -116,6 +146,36 @@ var IsolateWalker = /*#__PURE__*/Object.freeze({
|
|
|
116
146
|
walk: walk
|
|
117
147
|
});
|
|
118
148
|
|
|
149
|
+
class IsolateInspector {
|
|
150
|
+
static at(isolate, at) {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
if (isNullish(isolate)) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a[at]) !== null && _b !== void 0 ? _b : null;
|
|
156
|
+
}
|
|
157
|
+
static cursor(isolate) {
|
|
158
|
+
var _a, _b;
|
|
159
|
+
if (isNullish(isolate)) {
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
163
|
+
}
|
|
164
|
+
static shouldAllowReorder(isolate) {
|
|
165
|
+
var _a;
|
|
166
|
+
if (isNullish(isolate)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
return (_a = closestExists(isolate, node => node.allowReorder)) !== null && _a !== void 0 ? _a : false;
|
|
170
|
+
}
|
|
171
|
+
static usesKey(isolate) {
|
|
172
|
+
if (isNullish(isolate)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return isNotNullish(isolate.key);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
119
179
|
var ErrorStrings;
|
|
120
180
|
(function (ErrorStrings) {
|
|
121
181
|
ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
|
|
@@ -140,30 +200,14 @@ const PersistedContext = createCascade((stateRef, parentContext) => {
|
|
|
140
200
|
const Run = PersistedContext.run;
|
|
141
201
|
const RuntimeApi = {
|
|
142
202
|
Run,
|
|
203
|
+
addNodeToHistory,
|
|
143
204
|
createRef,
|
|
144
205
|
persist,
|
|
145
206
|
reset,
|
|
146
207
|
useAvailableRoot,
|
|
147
|
-
useBus,
|
|
148
208
|
useCurrentCursor,
|
|
149
|
-
useEmit,
|
|
150
|
-
usePrepareEmitter,
|
|
151
209
|
useXAppData,
|
|
152
210
|
};
|
|
153
|
-
function useBus() {
|
|
154
|
-
return useX().stateRef.Bus;
|
|
155
|
-
}
|
|
156
|
-
/*
|
|
157
|
-
Returns an emitter, but it also has a shortcut for emitting an event immediately
|
|
158
|
-
by passing an event name.
|
|
159
|
-
*/
|
|
160
|
-
function useEmit() {
|
|
161
|
-
return persist(useBus().emit);
|
|
162
|
-
}
|
|
163
|
-
function usePrepareEmitter(event) {
|
|
164
|
-
const emit = useEmit();
|
|
165
|
-
return (arg) => emit(event, arg);
|
|
166
|
-
}
|
|
167
211
|
function useXAppData() {
|
|
168
212
|
return useX().stateRef.appData;
|
|
169
213
|
}
|
|
@@ -191,6 +235,16 @@ function useHistoryRoot() {
|
|
|
191
235
|
function useHistoryNode() {
|
|
192
236
|
return useX().historyNode;
|
|
193
237
|
}
|
|
238
|
+
function addNodeToHistory(node) {
|
|
239
|
+
const parent = useIsolate();
|
|
240
|
+
if (parent) {
|
|
241
|
+
useSetNextIsolateChild(node);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
useSetHistory(node);
|
|
245
|
+
}
|
|
246
|
+
IsolateMutator.setParent(node, parent);
|
|
247
|
+
}
|
|
194
248
|
function useSetHistory(history) {
|
|
195
249
|
const [, setHistoryRoot] = useHistoryRoot();
|
|
196
250
|
setHistoryRoot(history);
|
|
@@ -208,8 +262,8 @@ function useIsolate() {
|
|
|
208
262
|
return (_a = useX().runtimeNode) !== null && _a !== void 0 ? _a : null;
|
|
209
263
|
}
|
|
210
264
|
function useCurrentCursor() {
|
|
211
|
-
|
|
212
|
-
return
|
|
265
|
+
const isolate = useIsolate();
|
|
266
|
+
return isolate ? IsolateInspector.cursor(isolate) : 0;
|
|
213
267
|
}
|
|
214
268
|
function useRuntimeRoot() {
|
|
215
269
|
return useX().runtimeRoot;
|
|
@@ -217,7 +271,7 @@ function useRuntimeRoot() {
|
|
|
217
271
|
function useSetNextIsolateChild(child) {
|
|
218
272
|
const currentIsolate = useIsolate();
|
|
219
273
|
invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
|
|
220
|
-
|
|
274
|
+
IsolateMutator.addChild(currentIsolate, child);
|
|
221
275
|
}
|
|
222
276
|
function useSetIsolateKey(key, value) {
|
|
223
277
|
if (!key) {
|
|
@@ -252,15 +306,13 @@ function BaseReconciler(currentNode, historicNode) {
|
|
|
252
306
|
}
|
|
253
307
|
class Reconciler {
|
|
254
308
|
static reconcile(reconciler, node, callback) {
|
|
255
|
-
var _a;
|
|
256
309
|
const parent = useIsolate();
|
|
257
310
|
const historyNode = useHistoryNode();
|
|
258
311
|
let localHistoryNode = historyNode;
|
|
259
312
|
if (parent) {
|
|
260
313
|
// If we have a parent, we need to get the history node from the parent's children
|
|
261
314
|
// We take the history node from the cursor of the active node's children
|
|
262
|
-
localHistoryNode =
|
|
263
|
-
(_a = historyNode === null || historyNode === void 0 ? void 0 : historyNode.at(useCurrentCursor())) !== null && _a !== void 0 ? _a : null;
|
|
315
|
+
localHistoryNode = IsolateInspector.at(historyNode, IsolateInspector.cursor(parent));
|
|
264
316
|
}
|
|
265
317
|
const nextNode = reconciler(node, localHistoryNode);
|
|
266
318
|
invariant(nextNode);
|
|
@@ -275,12 +327,13 @@ class Reconciler {
|
|
|
275
327
|
if (!historyNode || !testIsolate) {
|
|
276
328
|
// This is probably unreachable, but TS is not convinced.
|
|
277
329
|
// Let's play it safe.
|
|
330
|
+
/* istanbul ignore next */
|
|
278
331
|
return;
|
|
279
332
|
}
|
|
280
|
-
|
|
333
|
+
IsolateMutator.slice(historyNode, IsolateInspector.cursor(testIsolate));
|
|
281
334
|
}
|
|
282
335
|
static handleIsolateNodeWithKey(node) {
|
|
283
|
-
invariant(
|
|
336
|
+
invariant(IsolateInspector.usesKey(node));
|
|
284
337
|
const prevNodeByKey = useHistoryKey(node.key);
|
|
285
338
|
let nextNode = node;
|
|
286
339
|
if (!isNullish(prevNodeByKey)) {
|
|
@@ -307,77 +360,43 @@ class Isolate {
|
|
|
307
360
|
this.parent = null;
|
|
308
361
|
this.key = null;
|
|
309
362
|
this.allowReorder = false;
|
|
310
|
-
|
|
311
|
-
setParent(parent) {
|
|
312
|
-
this.parent = parent;
|
|
313
|
-
return this;
|
|
314
|
-
}
|
|
315
|
-
saveOutput(output) {
|
|
316
|
-
this.output = output;
|
|
317
|
-
return this;
|
|
318
|
-
}
|
|
319
|
-
setKey(key) {
|
|
320
|
-
this.key = key;
|
|
321
|
-
return this;
|
|
322
|
-
}
|
|
323
|
-
usesKey() {
|
|
324
|
-
return isNotNullish(this.key);
|
|
325
|
-
}
|
|
326
|
-
addChild(child) {
|
|
327
|
-
invariant(this.children);
|
|
328
|
-
this.children.push(child);
|
|
329
|
-
}
|
|
330
|
-
removeChild(node) {
|
|
331
|
-
var _a, _b;
|
|
332
|
-
this.children = (_b = (_a = this.children) === null || _a === void 0 ? void 0 : _a.filter(child => child !== node)) !== null && _b !== void 0 ? _b : null;
|
|
333
|
-
}
|
|
334
|
-
slice(at) {
|
|
335
|
-
if (isNullish(this.children)) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
this.children.length = at;
|
|
339
|
-
}
|
|
340
|
-
at(at) {
|
|
341
|
-
var _a, _b;
|
|
342
|
-
return (_b = (_a = this.children) === null || _a === void 0 ? void 0 : _a[at]) !== null && _b !== void 0 ? _b : null;
|
|
343
|
-
}
|
|
344
|
-
cursor() {
|
|
345
|
-
var _a, _b;
|
|
346
|
-
return (_b = (_a = this.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
347
|
-
}
|
|
348
|
-
shouldAllowReorder() {
|
|
349
|
-
var _a;
|
|
350
|
-
return (_a = closestExists(this, node => node.allowReorder)) !== null && _a !== void 0 ? _a : false;
|
|
351
|
-
}
|
|
352
|
-
get rootNode() {
|
|
353
|
-
var _a;
|
|
354
|
-
return (_a = closest(this, node => isNullish(node.parent))) !== null && _a !== void 0 ? _a : this;
|
|
363
|
+
this.type = Symbol('Isolate');
|
|
355
364
|
}
|
|
356
365
|
static create(callback, data) {
|
|
357
|
-
return this.createImplementation(callback, data);
|
|
358
|
-
}
|
|
359
|
-
static createImplementation(callback, data) {
|
|
360
366
|
const parent = useIsolate();
|
|
361
|
-
const newCreatedNode = new this(data)
|
|
367
|
+
const newCreatedNode = IsolateMutator.setParent(new this(data), parent);
|
|
362
368
|
const [nextIsolateChild, output] = Reconciler.reconcile(this.reconciler, newCreatedNode, callback);
|
|
363
|
-
|
|
364
|
-
|
|
369
|
+
IsolateMutator.saveOutput(nextIsolateChild, output);
|
|
370
|
+
addNodeToHistory(nextIsolateChild);
|
|
365
371
|
return nextIsolateChild;
|
|
366
372
|
}
|
|
367
|
-
static setNode(node) {
|
|
368
|
-
const parent = useIsolate();
|
|
369
|
-
if (parent) {
|
|
370
|
-
useSetNextIsolateChild(node);
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
useSetHistory(node);
|
|
374
|
-
}
|
|
375
|
-
node.setParent(parent);
|
|
376
|
-
}
|
|
377
|
-
static is(node) {
|
|
378
|
-
return node instanceof Isolate;
|
|
379
|
-
}
|
|
380
373
|
}
|
|
381
374
|
Isolate.reconciler = BaseReconciler;
|
|
382
375
|
|
|
383
|
-
|
|
376
|
+
function useBus() {
|
|
377
|
+
return useX().stateRef.Bus;
|
|
378
|
+
}
|
|
379
|
+
/*
|
|
380
|
+
Returns an emitter, but it also has a shortcut for emitting an event immediately
|
|
381
|
+
by passing an event name.
|
|
382
|
+
*/
|
|
383
|
+
function useEmit(event, data) {
|
|
384
|
+
const emit = useBus().emit;
|
|
385
|
+
if (!isNullish(event)) {
|
|
386
|
+
emit(event, data);
|
|
387
|
+
}
|
|
388
|
+
return persist(emit);
|
|
389
|
+
}
|
|
390
|
+
function usePrepareEmitter(event) {
|
|
391
|
+
const emit = useEmit();
|
|
392
|
+
return (arg) => emit(event, arg);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
var Bus = /*#__PURE__*/Object.freeze({
|
|
396
|
+
__proto__: null,
|
|
397
|
+
useBus: useBus,
|
|
398
|
+
useEmit: useEmit,
|
|
399
|
+
usePrepareEmitter: usePrepareEmitter
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
export { Bus, Isolate, IsolateInspector, IsolateMutator, Reconciler, RuntimeApi as VestRuntime, IsolateWalker as Walker };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{invariant as t,isNullish as e,optionalFunctionValue as n,isNotNullish as r,assign as o,tinyState as u,bus as i,deferThrow as s,text as c}from"vest-utils";import{createCascade as l}from"context";class a{static setParent(t,e){return t.parent=e,t}static saveOutput(t,e){return t.output=e,t}static setKey(t,e){return t.key=e,t}static addChild(e,n){t(e.children),e.children.push(n)}static removeChild(t,e){var n,r;t.children=null!==(r=null===(n=t.children)||void 0===n?void 0:n.filter((t=>t!==e)))&&void 0!==r?r:null}static slice(t,n){e(t.children)||(t.children.length=n)}}function d(t,r,o){if(e(t.children))return;let u=!1;for(const s of t.children){if(u)return;if((e(o)||n(o,s))&&r(s,i),u)return;d(s,((t,e)=>{r(t,(()=>{e(),i()}))}),o)}function i(){u=!0}}function f(t,e,n){let r=!1;return d(t,((t,n)=>{e(t)&&(n(),r=!0)}),n),r}function h(t,e){let n=t;for(;n.parent;){if(e(n))return n;n=n.parent}return null}function v(t,e){return!!h(t,e)}var y,p=Object.freeze({__proto__:null,closest:h,closestExists:v,every:function(t,e,n){let r=!0;return d(t,((t,n)=>{e(t)||(n(),r=!1)}),n),r},find:function(t,e,n){let r=null;return d(t,((t,n)=>{e(t)&&(n(),r=t)}),n),r},has:function(t,e){return f(t,(()=>!0),e)},pluck:function(t,e,n){d(t,(t=>{e(t)&&t.parent&&a.removeChild(t.parent,t)}),n)},some:f,walk:d});class E{static at(t,n){var r,o;return e(t)?null:null!==(o=null===(r=t.children)||void 0===r?void 0:r[n])&&void 0!==o?o:null}static cursor(t){var n,r;return e(t)?0:null!==(r=null===(n=t.children)||void 0===n?void 0:n.length)&&void 0!==r?r:0}static shouldAllowReorder(t){var n;return!e(t)&&(null!==(n=v(t,(t=>t.allowReorder)))&&void 0!==n&&n)}static usesKey(t){return!e(t)&&r(t.key)}}!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.'}(y||(y={}));const m=l(((e,n)=>{if(n)return null;t(e.historyRoot);const[r]=e.historyRoot(),u={};return o(u,{historyNode:r,runtimeNode:null,runtimeRoot:null,stateRef:e}),u})),_=m.run,R={Run:_,addNodeToHistory:C,createRef:function(t){return Object.freeze({historyRoot:u.createTinyState(null),Bus:i.createBus(),appData:n(t)})},persist:N,reset:function(){const[,,t]=O();t()},useAvailableRoot:function(){const t=I();if(t)return t;const[e]=O();return e},useCurrentCursor:function(){const t=A();return t?E.cursor(t):0},useXAppData:function(){return k().stateRef.appData}};function N(t){const e=m.useX();return(...n)=>{var r;const o=null!==(r=m.use())&&void 0!==r?r:e;return m.run(o.stateRef,(()=>t(...n)))}}function k(){return m.useX()}function O(){return k().stateRef.historyRoot()}function T(){return k().historyNode}function C(e){const n=A();n?function(e){const n=A();t(n,y.NO_ACTIVE_ISOLATE),a.addChild(n,e)}(e):function(t){const[,e]=O();e(t)}(e),a.setParent(e,n)}function A(){var t;return null!==(t=k().runtimeNode)&&void 0!==t?t:null}function I(){return k().runtimeRoot}class b{static reconcile(e,n,r){const o=A(),u=T();let i=u;o&&(i=E.at(u,E.cursor(o)));const s=e(n,i);return t(s),Object.is(s,n)?[n,w(i,n,r)]:[s,s.output]}static removeAllNextNodesInIsolate(){const t=A(),e=T();e&&t&&a.slice(e,E.cursor(t))}static handleIsolateNodeWithKey(n){t(E.usesKey(n));const r=function(t){var n;if(e(t))return null;const r=k().historyNode;return null!==(n=null==r?void 0:r.keys[t])&&void 0!==n?n:null}(n.key);let o=n;return e(r)||(o=r),function(n,r){if(!n)return;const o=A();t(o,y.NO_ACTIVE_ISOLATE),e(o.keys[n])?o.keys[n]=r:s(c(y.ENCOUNTERED_THE_SAME_KEY_TWICE,{key:n}))}(n.key,n),o}}function w(t,e,n){const r=I(),o=_(Object.assign({historyNode:t,runtimeNode:e},!r&&{runtimeRoot:e}),(()=>n(e)));return e.output=o,o}class S{constructor(t){this.children=[],this.keys={},this.parent=null,this.key=null,this.allowReorder=!1,this.type=Symbol("Isolate")}static create(t,e){const n=A(),r=a.setParent(new this(e),n),[o,u]=b.reconcile(this.reconciler,r,t);return a.saveOutput(o,u),C(o),o}}function K(){return k().stateRef.Bus}function g(t,n){const r=K().emit;return e(t)||r(t,n),N(r)}S.reconciler=function(t,n){return e(n),t};var j=Object.freeze({__proto__:null,useBus:K,useEmit:g,usePrepareEmitter:function(t){const e=g();return n=>e(t,n)}});export{j as Bus,S as Isolate,E as IsolateInspector,a as IsolateMutator,b as Reconciler,R as VestRuntime,p as Walker};
|
|
@@ -4,6 +4,36 @@
|
|
|
4
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
|
+
class IsolateMutator {
|
|
8
|
+
static setParent(isolate, parent) {
|
|
9
|
+
isolate.parent = parent;
|
|
10
|
+
return isolate;
|
|
11
|
+
}
|
|
12
|
+
static saveOutput(isolate, output) {
|
|
13
|
+
isolate.output = output;
|
|
14
|
+
return isolate;
|
|
15
|
+
}
|
|
16
|
+
static setKey(isolate, key) {
|
|
17
|
+
isolate.key = key;
|
|
18
|
+
return isolate;
|
|
19
|
+
}
|
|
20
|
+
static addChild(isolate, child) {
|
|
21
|
+
vestUtils.invariant(isolate.children);
|
|
22
|
+
isolate.children.push(child);
|
|
23
|
+
}
|
|
24
|
+
static removeChild(isolate, node) {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
isolate.children =
|
|
27
|
+
(_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.filter(child => child !== node)) !== null && _b !== void 0 ? _b : null;
|
|
28
|
+
}
|
|
29
|
+
static slice(isolate, at) {
|
|
30
|
+
if (vestUtils.isNullish(isolate.children)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
isolate.children.length = at;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
7
37
|
// eslint-disable-next-line
|
|
8
38
|
function walk(startNode, callback, visitOnly) {
|
|
9
39
|
// If the startNode has no children, there is nothing to walk.
|
|
@@ -85,7 +115,7 @@
|
|
|
85
115
|
function pluck(startNode, predicate, visitOnly) {
|
|
86
116
|
walk(startNode, node => {
|
|
87
117
|
if (predicate(node) && node.parent) {
|
|
88
|
-
|
|
118
|
+
IsolateMutator.removeChild(node.parent, node);
|
|
89
119
|
}
|
|
90
120
|
}, visitOnly);
|
|
91
121
|
}
|
|
@@ -119,6 +149,36 @@
|
|
|
119
149
|
walk: walk
|
|
120
150
|
});
|
|
121
151
|
|
|
152
|
+
class IsolateInspector {
|
|
153
|
+
static at(isolate, at) {
|
|
154
|
+
var _a, _b;
|
|
155
|
+
if (vestUtils.isNullish(isolate)) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a[at]) !== null && _b !== void 0 ? _b : null;
|
|
159
|
+
}
|
|
160
|
+
static cursor(isolate) {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
if (vestUtils.isNullish(isolate)) {
|
|
163
|
+
return 0;
|
|
164
|
+
}
|
|
165
|
+
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
166
|
+
}
|
|
167
|
+
static shouldAllowReorder(isolate) {
|
|
168
|
+
var _a;
|
|
169
|
+
if (vestUtils.isNullish(isolate)) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
return (_a = closestExists(isolate, node => node.allowReorder)) !== null && _a !== void 0 ? _a : false;
|
|
173
|
+
}
|
|
174
|
+
static usesKey(isolate) {
|
|
175
|
+
if (vestUtils.isNullish(isolate)) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
return vestUtils.isNotNullish(isolate.key);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
122
182
|
var ErrorStrings;
|
|
123
183
|
(function (ErrorStrings) {
|
|
124
184
|
ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
|
|
@@ -143,30 +203,14 @@
|
|
|
143
203
|
const Run = PersistedContext.run;
|
|
144
204
|
const RuntimeApi = {
|
|
145
205
|
Run,
|
|
206
|
+
addNodeToHistory,
|
|
146
207
|
createRef,
|
|
147
208
|
persist,
|
|
148
209
|
reset,
|
|
149
210
|
useAvailableRoot,
|
|
150
|
-
useBus,
|
|
151
211
|
useCurrentCursor,
|
|
152
|
-
useEmit,
|
|
153
|
-
usePrepareEmitter,
|
|
154
212
|
useXAppData,
|
|
155
213
|
};
|
|
156
|
-
function useBus() {
|
|
157
|
-
return useX().stateRef.Bus;
|
|
158
|
-
}
|
|
159
|
-
/*
|
|
160
|
-
Returns an emitter, but it also has a shortcut for emitting an event immediately
|
|
161
|
-
by passing an event name.
|
|
162
|
-
*/
|
|
163
|
-
function useEmit() {
|
|
164
|
-
return persist(useBus().emit);
|
|
165
|
-
}
|
|
166
|
-
function usePrepareEmitter(event) {
|
|
167
|
-
const emit = useEmit();
|
|
168
|
-
return (arg) => emit(event, arg);
|
|
169
|
-
}
|
|
170
214
|
function useXAppData() {
|
|
171
215
|
return useX().stateRef.appData;
|
|
172
216
|
}
|
|
@@ -194,6 +238,16 @@
|
|
|
194
238
|
function useHistoryNode() {
|
|
195
239
|
return useX().historyNode;
|
|
196
240
|
}
|
|
241
|
+
function addNodeToHistory(node) {
|
|
242
|
+
const parent = useIsolate();
|
|
243
|
+
if (parent) {
|
|
244
|
+
useSetNextIsolateChild(node);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
useSetHistory(node);
|
|
248
|
+
}
|
|
249
|
+
IsolateMutator.setParent(node, parent);
|
|
250
|
+
}
|
|
197
251
|
function useSetHistory(history) {
|
|
198
252
|
const [, setHistoryRoot] = useHistoryRoot();
|
|
199
253
|
setHistoryRoot(history);
|
|
@@ -211,8 +265,8 @@
|
|
|
211
265
|
return (_a = useX().runtimeNode) !== null && _a !== void 0 ? _a : null;
|
|
212
266
|
}
|
|
213
267
|
function useCurrentCursor() {
|
|
214
|
-
|
|
215
|
-
return
|
|
268
|
+
const isolate = useIsolate();
|
|
269
|
+
return isolate ? IsolateInspector.cursor(isolate) : 0;
|
|
216
270
|
}
|
|
217
271
|
function useRuntimeRoot() {
|
|
218
272
|
return useX().runtimeRoot;
|
|
@@ -220,7 +274,7 @@
|
|
|
220
274
|
function useSetNextIsolateChild(child) {
|
|
221
275
|
const currentIsolate = useIsolate();
|
|
222
276
|
vestUtils.invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
|
|
223
|
-
|
|
277
|
+
IsolateMutator.addChild(currentIsolate, child);
|
|
224
278
|
}
|
|
225
279
|
function useSetIsolateKey(key, value) {
|
|
226
280
|
if (!key) {
|
|
@@ -255,15 +309,13 @@
|
|
|
255
309
|
}
|
|
256
310
|
class Reconciler {
|
|
257
311
|
static reconcile(reconciler, node, callback) {
|
|
258
|
-
var _a;
|
|
259
312
|
const parent = useIsolate();
|
|
260
313
|
const historyNode = useHistoryNode();
|
|
261
314
|
let localHistoryNode = historyNode;
|
|
262
315
|
if (parent) {
|
|
263
316
|
// If we have a parent, we need to get the history node from the parent's children
|
|
264
317
|
// We take the history node from the cursor of the active node's children
|
|
265
|
-
localHistoryNode =
|
|
266
|
-
(_a = historyNode === null || historyNode === void 0 ? void 0 : historyNode.at(useCurrentCursor())) !== null && _a !== void 0 ? _a : null;
|
|
318
|
+
localHistoryNode = IsolateInspector.at(historyNode, IsolateInspector.cursor(parent));
|
|
267
319
|
}
|
|
268
320
|
const nextNode = reconciler(node, localHistoryNode);
|
|
269
321
|
vestUtils.invariant(nextNode);
|
|
@@ -278,12 +330,13 @@
|
|
|
278
330
|
if (!historyNode || !testIsolate) {
|
|
279
331
|
// This is probably unreachable, but TS is not convinced.
|
|
280
332
|
// Let's play it safe.
|
|
333
|
+
/* istanbul ignore next */
|
|
281
334
|
return;
|
|
282
335
|
}
|
|
283
|
-
|
|
336
|
+
IsolateMutator.slice(historyNode, IsolateInspector.cursor(testIsolate));
|
|
284
337
|
}
|
|
285
338
|
static handleIsolateNodeWithKey(node) {
|
|
286
|
-
vestUtils.invariant(
|
|
339
|
+
vestUtils.invariant(IsolateInspector.usesKey(node));
|
|
287
340
|
const prevNodeByKey = useHistoryKey(node.key);
|
|
288
341
|
let nextNode = node;
|
|
289
342
|
if (!vestUtils.isNullish(prevNodeByKey)) {
|
|
@@ -310,80 +363,49 @@
|
|
|
310
363
|
this.parent = null;
|
|
311
364
|
this.key = null;
|
|
312
365
|
this.allowReorder = false;
|
|
313
|
-
|
|
314
|
-
setParent(parent) {
|
|
315
|
-
this.parent = parent;
|
|
316
|
-
return this;
|
|
317
|
-
}
|
|
318
|
-
saveOutput(output) {
|
|
319
|
-
this.output = output;
|
|
320
|
-
return this;
|
|
321
|
-
}
|
|
322
|
-
setKey(key) {
|
|
323
|
-
this.key = key;
|
|
324
|
-
return this;
|
|
325
|
-
}
|
|
326
|
-
usesKey() {
|
|
327
|
-
return vestUtils.isNotNullish(this.key);
|
|
328
|
-
}
|
|
329
|
-
addChild(child) {
|
|
330
|
-
vestUtils.invariant(this.children);
|
|
331
|
-
this.children.push(child);
|
|
332
|
-
}
|
|
333
|
-
removeChild(node) {
|
|
334
|
-
var _a, _b;
|
|
335
|
-
this.children = (_b = (_a = this.children) === null || _a === void 0 ? void 0 : _a.filter(child => child !== node)) !== null && _b !== void 0 ? _b : null;
|
|
336
|
-
}
|
|
337
|
-
slice(at) {
|
|
338
|
-
if (vestUtils.isNullish(this.children)) {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
this.children.length = at;
|
|
342
|
-
}
|
|
343
|
-
at(at) {
|
|
344
|
-
var _a, _b;
|
|
345
|
-
return (_b = (_a = this.children) === null || _a === void 0 ? void 0 : _a[at]) !== null && _b !== void 0 ? _b : null;
|
|
346
|
-
}
|
|
347
|
-
cursor() {
|
|
348
|
-
var _a, _b;
|
|
349
|
-
return (_b = (_a = this.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
350
|
-
}
|
|
351
|
-
shouldAllowReorder() {
|
|
352
|
-
var _a;
|
|
353
|
-
return (_a = closestExists(this, node => node.allowReorder)) !== null && _a !== void 0 ? _a : false;
|
|
354
|
-
}
|
|
355
|
-
get rootNode() {
|
|
356
|
-
var _a;
|
|
357
|
-
return (_a = closest(this, node => vestUtils.isNullish(node.parent))) !== null && _a !== void 0 ? _a : this;
|
|
366
|
+
this.type = Symbol('Isolate');
|
|
358
367
|
}
|
|
359
368
|
static create(callback, data) {
|
|
360
|
-
return this.createImplementation(callback, data);
|
|
361
|
-
}
|
|
362
|
-
static createImplementation(callback, data) {
|
|
363
369
|
const parent = useIsolate();
|
|
364
|
-
const newCreatedNode = new this(data)
|
|
370
|
+
const newCreatedNode = IsolateMutator.setParent(new this(data), parent);
|
|
365
371
|
const [nextIsolateChild, output] = Reconciler.reconcile(this.reconciler, newCreatedNode, callback);
|
|
366
|
-
|
|
367
|
-
|
|
372
|
+
IsolateMutator.saveOutput(nextIsolateChild, output);
|
|
373
|
+
addNodeToHistory(nextIsolateChild);
|
|
368
374
|
return nextIsolateChild;
|
|
369
375
|
}
|
|
370
|
-
static setNode(node) {
|
|
371
|
-
const parent = useIsolate();
|
|
372
|
-
if (parent) {
|
|
373
|
-
useSetNextIsolateChild(node);
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
useSetHistory(node);
|
|
377
|
-
}
|
|
378
|
-
node.setParent(parent);
|
|
379
|
-
}
|
|
380
|
-
static is(node) {
|
|
381
|
-
return node instanceof Isolate;
|
|
382
|
-
}
|
|
383
376
|
}
|
|
384
377
|
Isolate.reconciler = BaseReconciler;
|
|
385
378
|
|
|
379
|
+
function useBus() {
|
|
380
|
+
return useX().stateRef.Bus;
|
|
381
|
+
}
|
|
382
|
+
/*
|
|
383
|
+
Returns an emitter, but it also has a shortcut for emitting an event immediately
|
|
384
|
+
by passing an event name.
|
|
385
|
+
*/
|
|
386
|
+
function useEmit(event, data) {
|
|
387
|
+
const emit = useBus().emit;
|
|
388
|
+
if (!vestUtils.isNullish(event)) {
|
|
389
|
+
emit(event, data);
|
|
390
|
+
}
|
|
391
|
+
return persist(emit);
|
|
392
|
+
}
|
|
393
|
+
function usePrepareEmitter(event) {
|
|
394
|
+
const emit = useEmit();
|
|
395
|
+
return (arg) => emit(event, arg);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
var Bus = /*#__PURE__*/Object.freeze({
|
|
399
|
+
__proto__: null,
|
|
400
|
+
useBus: useBus,
|
|
401
|
+
useEmit: useEmit,
|
|
402
|
+
usePrepareEmitter: usePrepareEmitter
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
exports.Bus = Bus;
|
|
386
406
|
exports.Isolate = Isolate;
|
|
407
|
+
exports.IsolateInspector = IsolateInspector;
|
|
408
|
+
exports.IsolateMutator = IsolateMutator;
|
|
387
409
|
exports.Reconciler = Reconciler;
|
|
388
410
|
exports.VestRuntime = RuntimeApi;
|
|
389
411
|
exports.Walker = IsolateWalker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vest-utils"),require("context")):"function"==typeof define&&define.amd?define(["exports","vest-utils","context"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["vestjs-runtime"]={},t["vest-utils"],t.context)}(this,(function(t,e,n){"use strict";function i(t,n,r){if(e.isNullish(t.children))return;let
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vest-utils"),require("context")):"function"==typeof define&&define.amd?define(["exports","vest-utils","context"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["vestjs-runtime"]={},t["vest-utils"],t.context)}(this,(function(t,e,n){"use strict";class r{static setParent(t,e){return t.parent=e,t}static saveOutput(t,e){return t.output=e,t}static setKey(t,e){return t.key=e,t}static addChild(t,n){e.invariant(t.children),t.children.push(n)}static removeChild(t,e){var n,r;t.children=null!==(r=null===(n=t.children)||void 0===n?void 0:n.filter((t=>t!==e)))&&void 0!==r?r:null}static slice(t,n){e.isNullish(t.children)||(t.children.length=n)}}function i(t,n,r){if(e.isNullish(t.children))return;let s=!1;for(const u of t.children){if(s)return;if((e.isNullish(r)||e.optionalFunctionValue(r,u))&&n(u,o),s)return;i(u,((t,e)=>{n(t,(()=>{e(),o()}))}),r)}function o(){s=!0}}function s(t,e,n){let r=!1;return i(t,((t,n)=>{e(t)&&(n(),r=!0)}),n),r}function o(t,e){let n=t;for(;n.parent;){if(e(n))return n;n=n.parent}return null}function u(t,e){return!!o(t,e)}var l,c=Object.freeze({__proto__:null,closest:o,closestExists:u,every:function(t,e,n){let r=!0;return i(t,((t,n)=>{e(t)||(n(),r=!1)}),n),r},find:function(t,e,n){let r=null;return i(t,((t,n)=>{e(t)&&(n(),r=t)}),n),r},has:function(t,e){return s(t,(()=>!0),e)},pluck:function(t,e,n){i(t,(t=>{e(t)&&t.parent&&r.removeChild(t.parent,t)}),n)},some:s,walk:i});class a{static at(t,n){var r,i;return e.isNullish(t)?null:null!==(i=null===(r=t.children)||void 0===r?void 0:r[n])&&void 0!==i?i:null}static cursor(t){var n,r;return e.isNullish(t)?0:null!==(r=null===(n=t.children)||void 0===n?void 0:n.length)&&void 0!==r?r:0}static shouldAllowReorder(t){var n;return!e.isNullish(t)&&(null!==(n=u(t,(t=>t.allowReorder)))&&void 0!==n&&n)}static usesKey(t){return!e.isNullish(t)&&e.isNotNullish(t.key)}}!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.'}(l||(l={}));const d=n.createCascade(((t,n)=>{if(n)return null;e.invariant(t.historyRoot);const[r]=t.historyRoot(),i={};return e.assign(i,{historyNode:r,runtimeNode:null,runtimeRoot:null,stateRef:t}),i})),f=d.run,h={Run:f,addNodeToHistory:E,createRef:function(t){return Object.freeze({historyRoot:e.tinyState.createTinyState(null),Bus:e.bus.createBus(),appData:e.optionalFunctionValue(t)})},persist:v,reset:function(){const[,,t]=p();t()},useAvailableRoot:function(){const t=_();if(t)return t;const[e]=p();return e},useCurrentCursor:function(){const t=R();return t?a.cursor(t):0},useXAppData:function(){return y().stateRef.appData}};function v(t){const e=d.useX();return(...n)=>{var r;const i=null!==(r=d.use())&&void 0!==r?r:e;return d.run(i.stateRef,(()=>t(...n)))}}function y(){return d.useX()}function p(){return y().stateRef.historyRoot()}function N(){return y().historyNode}function E(t){const n=R();n?function(t){const n=R();e.invariant(n,l.NO_ACTIVE_ISOLATE),r.addChild(n,t)}(t):function(t){const[,e]=p();e(t)}(t),r.setParent(t,n)}function R(){var t;return null!==(t=y().runtimeNode)&&void 0!==t?t:null}function _(){return y().runtimeRoot}class m{static reconcile(t,n,r){const i=R(),s=N();let o=s;i&&(o=a.at(s,a.cursor(i)));const u=t(n,o);return e.invariant(u),Object.is(u,n)?[n,T(o,n,r)]:[u,u.output]}static removeAllNextNodesInIsolate(){const t=R(),e=N();e&&t&&r.slice(e,a.cursor(t))}static handleIsolateNodeWithKey(t){e.invariant(a.usesKey(t));const n=function(t){var n;if(e.isNullish(t))return null;const r=y().historyNode;return null!==(n=null==r?void 0:r.keys[t])&&void 0!==n?n:null}(t.key);let r=t;return e.isNullish(n)||(r=n),function(t,n){if(!t)return;const r=R();e.invariant(r,l.NO_ACTIVE_ISOLATE),e.isNullish(r.keys[t])?r.keys[t]=n:e.deferThrow(e.text(l.ENCOUNTERED_THE_SAME_KEY_TWICE,{key:t}))}(t.key,t),r}}function T(t,e,n){const r=_(),i=f(Object.assign({historyNode:t,runtimeNode:e},!r&&{runtimeRoot:e}),(()=>n(e)));return e.output=i,i}class I{constructor(t){this.children=[],this.keys={},this.parent=null,this.key=null,this.allowReorder=!1,this.type=Symbol("Isolate")}static create(t,e){const n=R(),i=r.setParent(new this(e),n),[s,o]=m.reconcile(this.reconciler,i,t);return r.saveOutput(s,o),E(s),s}}function k(){return y().stateRef.Bus}function O(t,n){const r=k().emit;return e.isNullish(t)||r(t,n),v(r)}I.reconciler=function(t,n){return e.isNullish(n),t};var C=Object.freeze({__proto__:null,useBus:k,useEmit:O,usePrepareEmitter:function(t){const e=O();return n=>e(t,n)}});t.Bus=C,t.Isolate=I,t.IsolateInspector=a,t.IsolateMutator=r,t.Reconciler=m,t.VestRuntime=h,t.Walker=c}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vestjs-runtime",
|
|
3
|
-
"version": "0.0.2-next-
|
|
3
|
+
"version": "0.0.2-next-2cf993",
|
|
4
4
|
"description": "Internal runtime module used by Vest",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ealush",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"url": "https://github.com/ealush/vest.git/issues"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"context": "3.0.9-next-
|
|
22
|
-
"vest-utils": "1.0.0-next-
|
|
21
|
+
"context": "3.0.9-next-2cf993",
|
|
22
|
+
"vest-utils": "1.0.0-next-2cf993"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
@@ -44,5 +44,6 @@
|
|
|
44
44
|
},
|
|
45
45
|
"./package.json": "./package.json",
|
|
46
46
|
"./*": "./*"
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
|
+
"vxAllowResolve": []
|
|
48
49
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { CB, TinyState, BusType } from "vest-utils";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
// I would rather not use `any` here, but instead use `Isolate`.
|
|
3
|
+
// The problem is that it breaks the actual implementation of `Isolate` in `IsolateTest`
|
|
4
|
+
// As it is not properly extending `Isolate`.
|
|
5
|
+
interface IRecociler<I = any> {
|
|
6
|
+
(currentNode: I, historicNode: Isolate | null): I;
|
|
4
7
|
}
|
|
5
8
|
declare class Reconciler {
|
|
6
|
-
static reconcile<Callback extends CB = CB>(reconciler: IRecociler
|
|
9
|
+
static reconcile<Callback extends CB = CB>(reconciler: IRecociler<Isolate>, node: Isolate, callback: Callback): [
|
|
7
10
|
Isolate,
|
|
8
11
|
ReturnType<Callback>
|
|
9
12
|
];
|
|
@@ -15,35 +18,25 @@ declare class Isolate<_D = any> {
|
|
|
15
18
|
children: Isolate[] | null;
|
|
16
19
|
keys: Record<string, Isolate>;
|
|
17
20
|
parent: Isolate | null;
|
|
18
|
-
output
|
|
21
|
+
output: any;
|
|
19
22
|
key: IsolateKey;
|
|
20
23
|
allowReorder: boolean;
|
|
21
|
-
|
|
24
|
+
type: symbol;
|
|
22
25
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
|
23
26
|
constructor(_data?: _D);
|
|
24
|
-
|
|
25
|
-
saveOutput(output: any): this;
|
|
26
|
-
setKey(key: string | null): this;
|
|
27
|
-
usesKey(): boolean;
|
|
28
|
-
addChild(child: Isolate): void;
|
|
29
|
-
removeChild(node: Isolate): void;
|
|
30
|
-
slice(at: number): void;
|
|
31
|
-
at(at: number): Isolate | null;
|
|
32
|
-
cursor(): number;
|
|
33
|
-
shouldAllowReorder(): boolean;
|
|
34
|
-
get rootNode(): Isolate;
|
|
27
|
+
static reconciler: IRecociler;
|
|
35
28
|
static create<Callback extends CB = CB>(callback: Callback, data?: any): Isolate;
|
|
36
|
-
private static createImplementation;
|
|
37
|
-
static setNode(node: Isolate): void;
|
|
38
|
-
static is(node: any): boolean;
|
|
39
29
|
}
|
|
40
30
|
declare namespace Walker {
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
// I would rather not use `any` here, but instead use `Isolate`.
|
|
32
|
+
// The problem is that it breaks the actual implementation of `Isolate` in `IsolateTest`
|
|
33
|
+
// As it is not properly extending `Isolate`.
|
|
34
|
+
interface IRecociler<I = any> {
|
|
35
|
+
(currentNode: I, historicNode: Isolate | null): I;
|
|
43
36
|
}
|
|
44
37
|
function BaseReconciler(currentNode: Isolate, historicNode: Isolate | null): Isolate;
|
|
45
38
|
class Reconciler {
|
|
46
|
-
static reconcile<Callback extends CB = CB>(reconciler: IRecociler
|
|
39
|
+
static reconcile<Callback extends CB = CB>(reconciler: IRecociler<Isolate>, node: Isolate, callback: Callback): [
|
|
47
40
|
Isolate,
|
|
48
41
|
ReturnType<Callback>
|
|
49
42
|
];
|
|
@@ -55,27 +48,14 @@ declare namespace Walker {
|
|
|
55
48
|
children: Isolate[] | null;
|
|
56
49
|
keys: Record<string, Isolate>;
|
|
57
50
|
parent: Isolate | null;
|
|
58
|
-
output
|
|
51
|
+
output: any;
|
|
59
52
|
key: IsolateKey;
|
|
60
53
|
allowReorder: boolean;
|
|
61
|
-
|
|
54
|
+
type: symbol;
|
|
62
55
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
|
63
56
|
constructor(_data?: _D);
|
|
64
|
-
|
|
65
|
-
saveOutput(output: any): this;
|
|
66
|
-
setKey(key: string | null): this;
|
|
67
|
-
usesKey(): boolean;
|
|
68
|
-
addChild(child: Isolate): void;
|
|
69
|
-
removeChild(node: Isolate): void;
|
|
70
|
-
slice(at: number): void;
|
|
71
|
-
at(at: number): Isolate | null;
|
|
72
|
-
cursor(): number;
|
|
73
|
-
shouldAllowReorder(): boolean;
|
|
74
|
-
get rootNode(): Isolate;
|
|
57
|
+
static reconciler: IRecociler;
|
|
75
58
|
static create<Callback extends CB = CB>(callback: Callback, data?: any): Isolate;
|
|
76
|
-
private static createImplementation;
|
|
77
|
-
static setNode(node: Isolate): void;
|
|
78
|
-
static is(node: any): boolean;
|
|
79
59
|
}
|
|
80
60
|
type VisitOnlyPredicate = (isolate: Isolate) => boolean;
|
|
81
61
|
// eslint-disable-next-line
|
|
@@ -116,28 +96,43 @@ type StateRefType = {
|
|
|
116
96
|
};
|
|
117
97
|
declare const RuntimeApi: {
|
|
118
98
|
Run: <R>(value: Partial<CTXType>, fn: () => R) => R;
|
|
99
|
+
addNodeToHistory: typeof addNodeToHistory;
|
|
119
100
|
createRef: typeof createRef;
|
|
120
101
|
persist: typeof persist;
|
|
121
102
|
reset: typeof reset;
|
|
122
103
|
useAvailableRoot: typeof useAvailableRoot;
|
|
123
|
-
useBus: typeof useBus;
|
|
124
104
|
useCurrentCursor: typeof useCurrentCursor;
|
|
125
|
-
useEmit: typeof useEmit;
|
|
126
|
-
usePrepareEmitter: typeof usePrepareEmitter;
|
|
127
105
|
useXAppData: typeof useXAppData;
|
|
128
106
|
};
|
|
129
|
-
declare function useBus(): BusType;
|
|
130
|
-
/*
|
|
131
|
-
Returns an emitter, but it also has a shortcut for emitting an event immediately
|
|
132
|
-
by passing an event name.
|
|
133
|
-
*/
|
|
134
|
-
declare function useEmit(): (event: string, ...args: any[]) => void;
|
|
135
|
-
declare function usePrepareEmitter<T = void>(event: string): (arg: T) => void;
|
|
136
107
|
declare function useXAppData<T = object>(): T;
|
|
137
108
|
declare function createRef(setter: Record<string, any> | (() => Record<string, any>)): StateRefType;
|
|
138
109
|
declare function persist<T extends CB>(cb: T): T;
|
|
110
|
+
declare function addNodeToHistory(node: Isolate): void;
|
|
139
111
|
declare function useCurrentCursor(): number;
|
|
140
112
|
declare function useAvailableRoot<I extends Isolate = Isolate>(): I;
|
|
141
113
|
declare function reset(): void;
|
|
142
|
-
|
|
114
|
+
declare class IsolateInspector {
|
|
115
|
+
static at(isolate: Isolate | null, at: number): Isolate | null;
|
|
116
|
+
static cursor(isolate: Isolate | null): number;
|
|
117
|
+
static shouldAllowReorder(isolate: Isolate | null): boolean;
|
|
118
|
+
static usesKey(isolate: Isolate | null): boolean;
|
|
119
|
+
}
|
|
120
|
+
declare class IsolateMutator {
|
|
121
|
+
static setParent(isolate: Isolate, parent: Isolate | null): Isolate;
|
|
122
|
+
static saveOutput(isolate: Isolate, output: any): Isolate;
|
|
123
|
+
static setKey(isolate: Isolate, key: string | null): Isolate;
|
|
124
|
+
static addChild(isolate: Isolate, child: Isolate): void;
|
|
125
|
+
static removeChild(isolate: Isolate, node: Isolate): void;
|
|
126
|
+
static slice(isolate: Isolate, at: number): void;
|
|
127
|
+
}
|
|
128
|
+
declare namespace Bus {
|
|
129
|
+
function useBus(): import("vest-utils").BusType;
|
|
130
|
+
/*
|
|
131
|
+
Returns an emitter, but it also has a shortcut for emitting an event immediately
|
|
132
|
+
by passing an event name.
|
|
133
|
+
*/
|
|
134
|
+
function useEmit(event?: string, data?: any): (event: string, data?: any) => void;
|
|
135
|
+
function usePrepareEmitter<T = void>(event: string): (arg: T) => void;
|
|
136
|
+
}
|
|
137
|
+
export { IsolateKey, Isolate, Reconciler, IRecociler, Walker, RuntimeApi as VestRuntime, IsolateInspector, IsolateMutator, Bus };
|
|
143
138
|
//# sourceMappingURL=vestjs-runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vestjs-runtime.d.ts","sourceRoot":"","sources":["../src/vestjs-runtime.ts","../src/IsolateWalker.ts","../src/errors/ErrorStrings.ts","../src/VestRuntime.ts","../src/Reconciler.ts","../src/Isolate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vestjs-runtime.d.ts","sourceRoot":"","sources":["../src/vestjs-runtime.ts","../src/Isolate/IsolateMutator.ts","../src/IsolateWalker.ts","../src/Isolate/IsolateInspector.ts","../src/errors/ErrorStrings.ts","../src/VestRuntime.ts","../src/Reconciler.ts","../src/Isolate/Isolate.ts","../src/Bus.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,yHAAuB,CAAgB"}
|