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.
@@ -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
- node.parent.removeChild(node);
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
- var _a, _b;
214
- return (_b = (_a = useIsolate()) === null || _a === void 0 ? void 0 : _a.cursor()) !== null && _b !== void 0 ? _b : 0;
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
- currentIsolate.addChild(child);
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
- historyNode.slice(useCurrentCursor());
335
+ IsolateMutator.slice(historyNode, IsolateInspector.cursor(testIsolate));
283
336
  }
284
337
  static handleIsolateNodeWithKey(node) {
285
- vestUtils.invariant(node.usesKey());
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).setParent(parent);
369
+ const newCreatedNode = IsolateMutator.setParent(new this(data), parent);
364
370
  const [nextIsolateChild, output] = Reconciler.reconcile(this.reconciler, newCreatedNode, callback);
365
- nextIsolateChild.saveOutput(output);
366
- this.setNode(nextIsolateChild);
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,5 +1,4 @@
1
1
  'use strict'
2
-
3
2
  if (process.env.NODE_ENV === 'production') {
4
3
  module.exports = require('./vestjs-runtime.production.js');
5
4
  } else {
@@ -1 +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;
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, invariant, assign, tinyState, bus, deferThrow, text, isNotNullish } from 'vest-utils';
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
- node.parent.removeChild(node);
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
- var _a, _b;
212
- return (_b = (_a = useIsolate()) === null || _a === void 0 ? void 0 : _a.cursor()) !== null && _b !== void 0 ? _b : 0;
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
- currentIsolate.addChild(child);
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
- historyNode.slice(useCurrentCursor());
333
+ IsolateMutator.slice(historyNode, IsolateInspector.cursor(testIsolate));
281
334
  }
282
335
  static handleIsolateNodeWithKey(node) {
283
- invariant(node.usesKey());
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).setParent(parent);
367
+ const newCreatedNode = IsolateMutator.setParent(new this(data), parent);
362
368
  const [nextIsolateChild, output] = Reconciler.reconcile(this.reconciler, newCreatedNode, callback);
363
- nextIsolateChild.saveOutput(output);
364
- this.setNode(nextIsolateChild);
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
- export { Isolate, Reconciler, RuntimeApi as VestRuntime, IsolateWalker as Walker };
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{isNullish as t,optionalFunctionValue as e,invariant as n,assign as r,tinyState as o,bus as i,deferThrow as u,text as s,isNotNullish as l}from"vest-utils";import{createCascade as c}from"context";function a(n,r,o){if(t(n.children))return;let i=!1;for(const s of n.children){if(i)return;if((t(o)||e(o,s))&&r(s,u),i)return;a(s,((t,e)=>{r(t,(()=>{e(),u()}))}),o)}function u(){i=!0}}function d(t,e,n){let r=!1;return a(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 f(t,e){return!!h(t,e)}var v,p=Object.freeze({__proto__:null,closest:h,closestExists:f,every:function(t,e,n){let r=!0;return a(t,((t,n)=>{e(t)||(n(),r=!1)}),n),r},find:function(t,e,n){let r=null;return a(t,((t,n)=>{e(t)&&(n(),r=t)}),n),r},has:function(t,e){return d(t,(()=>!0),e)},pluck:function(t,e,n){a(t,(t=>{e(t)&&t.parent&&t.parent.removeChild(t)}),n)},some:d,walk:a});!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.'}(v||(v={}));const y=c(((t,e)=>{if(e)return null;n(t.historyRoot);const[o]=t.historyRoot(),i={};return r(i,{historyNode:o,runtimeNode:null,runtimeRoot:null,stateRef:t}),i})),m=y.run,E={Run:m,createRef:function(t){return Object.freeze({historyRoot:o.createTinyState(null),Bus:i.createBus(),appData:e(t)})},persist:_,reset:function(){const[,,t]=O();t()},useAvailableRoot:function(){const t=A();if(t)return t;const[e]=O();return e},useBus:N,useCurrentCursor:I,useEmit:R,usePrepareEmitter:function(t){const e=R();return n=>e(t,n)},useXAppData:function(){return k().stateRef.appData}};function N(){return k().stateRef.Bus}function R(){return _(N().emit)}function _(t){const e=y.useX();return(...n)=>{var r;const o=null!==(r=y.use())&&void 0!==r?r:e;return y.run(o.stateRef,(()=>t(...n)))}}function k(){return y.useX()}function O(){return k().stateRef.historyRoot()}function T(){return k().historyNode}function C(){var t;return null!==(t=k().runtimeNode)&&void 0!==t?t:null}function I(){var t,e;return null!==(e=null===(t=C())||void 0===t?void 0:t.cursor())&&void 0!==e?e:0}function A(){return k().runtimeRoot}class w{static reconcile(t,e,r){var o;const i=C(),u=T();let s=u;i&&(s=null!==(o=null==u?void 0:u.at(I()))&&void 0!==o?o:null);const l=t(e,s);return n(l),Object.is(l,e)?[e,b(s,e,r)]:[l,l.output]}static removeAllNextNodesInIsolate(){const t=C(),e=T();e&&t&&e.slice(I())}static handleIsolateNodeWithKey(e){n(e.usesKey());const r=function(e){var n;if(t(e))return null;const r=k().historyNode;return null!==(n=null==r?void 0:r.keys[e])&&void 0!==n?n:null}(e.key);let o=e;return t(r)||(o=r),function(e,r){if(!e)return;const o=C();n(o,v.NO_ACTIVE_ISOLATE),t(o.keys[e])?o.keys[e]=r:u(s(v.ENCOUNTERED_THE_SAME_KEY_TWICE,{key:e}))}(e.key,e),o}}function b(t,e,n){const r=A(),o=m(Object.assign({historyNode:t,runtimeNode:e},!r&&{runtimeRoot:e}),(()=>n(e)));return e.output=o,o}class g{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 l(this.key)}addChild(t){n(this.children),this.children.push(t)}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(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=f(this,(t=>t.allowReorder)))&&void 0!==t&&t}get rootNode(){var e;return null!==(e=h(this,(e=>t(e.parent))))&&void 0!==e?e:this}static create(t,e){return this.createImplementation(t,e)}static createImplementation(t,e){const n=C(),r=new this(e).setParent(n),[o,i]=w.reconcile(this.reconciler,r,t);return o.saveOutput(i),this.setNode(o),o}static setNode(t){const e=C();e?function(t){const e=C();n(e,v.NO_ACTIVE_ISOLATE),e.addChild(t)}(t):function(t){const[,e]=O();e(t)}(t),t.setParent(e)}static is(t){return t instanceof g}}g.reconciler=function(e,n){return t(n),e};export{g as Isolate,w as Reconciler,E as VestRuntime,p as Walker};
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
- node.parent.removeChild(node);
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
- var _a, _b;
215
- return (_b = (_a = useIsolate()) === null || _a === void 0 ? void 0 : _a.cursor()) !== null && _b !== void 0 ? _b : 0;
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
- currentIsolate.addChild(child);
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
- historyNode.slice(useCurrentCursor());
336
+ IsolateMutator.slice(historyNode, IsolateInspector.cursor(testIsolate));
284
337
  }
285
338
  static handleIsolateNodeWithKey(node) {
286
- vestUtils.invariant(node.usesKey());
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).setParent(parent);
370
+ const newCreatedNode = IsolateMutator.setParent(new this(data), parent);
365
371
  const [nextIsolateChild, output] = Reconciler.reconcile(this.reconciler, newCreatedNode, callback);
366
- nextIsolateChild.saveOutput(output);
367
- this.setNode(nextIsolateChild);
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 o=!1;for(const u of t.children){if(o)return;if((e.isNullish(r)||e.optionalFunctionValue(r,u))&&n(u,s),o)return;i(u,((t,e)=>{n(t,(()=>{e(),s()}))}),r)}function s(){o=!0}}function r(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 s(t,e){return!!o(t,e)}var u,l=Object.freeze({__proto__:null,closest:o,closestExists:s,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 r(t,(()=>!0),e)},pluck:function(t,e,n){i(t,(t=>{e(t)&&t.parent&&t.parent.removeChild(t)}),n)},some:r,walk:i});!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 c=n.createCascade(((t,n)=>{if(n)return null;e.invariant(t.historyRoot);const[i]=t.historyRoot(),r={};return e.assign(r,{historyNode:i,runtimeNode:null,runtimeRoot:null,stateRef:t}),r})),a=c.run,h={Run:a,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]=y();t()},useAvailableRoot:function(){const t=R();if(t)return t;const[e]=y();return e},useBus:d,useCurrentCursor:E,useEmit:f,usePrepareEmitter:function(t){const e=f();return n=>e(t,n)},useXAppData:function(){return p().stateRef.appData}};function d(){return p().stateRef.Bus}function f(){return v(d().emit)}function v(t){const e=c.useX();return(...n)=>{var i;const r=null!==(i=c.use())&&void 0!==i?i:e;return c.run(r.stateRef,(()=>t(...n)))}}function p(){return c.useX()}function y(){return p().stateRef.historyRoot()}function N(){return p().historyNode}function m(){var t;return null!==(t=p().runtimeNode)&&void 0!==t?t:null}function E(){var t,e;return null!==(e=null===(t=m())||void 0===t?void 0:t.cursor())&&void 0!==e?e:0}function R(){return p().runtimeRoot}class _{static reconcile(t,n,i){var r;const o=m(),s=N();let u=s;o&&(u=null!==(r=null==s?void 0:s.at(E()))&&void 0!==r?r:null);const l=t(n,u);return e.invariant(l),Object.is(l,n)?[n,T(u,n,i)]:[l,l.output]}static removeAllNextNodesInIsolate(){const t=m(),e=N();e&&t&&e.slice(E())}static handleIsolateNodeWithKey(t){e.invariant(t.usesKey());const n=function(t){var n;if(e.isNullish(t))return null;const i=p().historyNode;return null!==(n=null==i?void 0:i.keys[t])&&void 0!==n?n:null}(t.key);let i=t;return e.isNullish(n)||(i=n),function(t,n){if(!t)return;const i=m();e.invariant(i,u.NO_ACTIVE_ISOLATE),e.isNullish(i.keys[t])?i.keys[t]=n:e.deferThrow(e.text(u.ENCOUNTERED_THE_SAME_KEY_TWICE,{key:t}))}(t.key,t),i}}function T(t,e,n){const i=R(),r=a(Object.assign({historyNode:t,runtimeNode:e},!i&&{runtimeRoot:e}),(()=>n(e)));return e.output=r,r}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 e.isNotNullish(this.key)}addChild(t){e.invariant(this.children),this.children.push(t)}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(t){e.isNullish(this.children)||(this.children.length=t)}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 t;return null!==(t=o(this,(t=>e.isNullish(t.parent))))&&void 0!==t?t:this}static create(t,e){return this.createImplementation(t,e)}static createImplementation(t,e){const n=m(),i=new this(e).setParent(n),[r,o]=_.reconcile(this.reconciler,i,t);return r.saveOutput(o),this.setNode(r),r}static setNode(t){const n=m();n?function(t){const n=m();e.invariant(n,u.NO_ACTIVE_ISOLATE),n.addChild(t)}(t):function(t){const[,e]=y();e(t)}(t),t.setParent(n)}static is(t){return t instanceof k}}k.reconciler=function(t,n){return e.isNullish(n),t},t.Isolate=k,t.Reconciler=_,t.VestRuntime=h,t.Walker=l}));
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-1b0637",
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-1b0637",
22
- "vest-utils": "1.0.0-next-1b0637"
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
- interface IRecociler {
3
- (currentNode: Isolate, historicNode: Isolate | null): Isolate;
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, node: Isolate, callback: Callback): [
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?: any;
21
+ output: any;
19
22
  key: IsolateKey;
20
23
  allowReorder: boolean;
21
- static reconciler: IRecociler;
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
- setParent(parent: Isolate | null): this;
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
- interface IRecociler {
42
- (currentNode: Isolate, historicNode: Isolate | null): Isolate;
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, node: Isolate, callback: Callback): [
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?: any;
51
+ output: any;
59
52
  key: IsolateKey;
60
53
  allowReorder: boolean;
61
- static reconciler: IRecociler;
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
- setParent(parent: Isolate | null): this;
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
- export { Isolate, IsolateKey, Reconciler, IRecociler, Walker, RuntimeApi as VestRuntime };
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,kFAAuB,CAAgB"}
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"}