vestjs-runtime 0.0.2-next-2cf993 → 0.0.2-next-04eea9
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 +5 -5
- package/dist/cjs/vestjs-runtime.production.js +1 -1
- package/dist/es/vestjs-runtime.development.js +5 -5
- package/dist/es/vestjs-runtime.production.js +1 -1
- package/dist/umd/vestjs-runtime.development.js +5 -5
- package/dist/umd/vestjs-runtime.production.js +1 -1
- package/package.json +3 -3
- package/types/vestjs-runtime.d.ts +26 -26
|
@@ -19,6 +19,7 @@ class IsolateMutator {
|
|
|
19
19
|
static addChild(isolate, child) {
|
|
20
20
|
vestUtils.invariant(isolate.children);
|
|
21
21
|
isolate.children.push(child);
|
|
22
|
+
IsolateMutator.setParent(child, isolate);
|
|
22
23
|
}
|
|
23
24
|
static removeChild(isolate, node) {
|
|
24
25
|
var _a, _b;
|
|
@@ -122,12 +123,12 @@ function pluck(startNode, predicate, visitOnly) {
|
|
|
122
123
|
//startNode that satisfies the given predicate function.
|
|
123
124
|
function closest(startNode, predicate) {
|
|
124
125
|
let current = startNode;
|
|
125
|
-
|
|
126
|
+
do {
|
|
126
127
|
if (predicate(current)) {
|
|
127
128
|
return current;
|
|
128
129
|
}
|
|
129
130
|
current = current.parent;
|
|
130
|
-
}
|
|
131
|
+
} while (current);
|
|
131
132
|
return null;
|
|
132
133
|
}
|
|
133
134
|
// This function returns true if the closest ancestor Isolates of the
|
|
@@ -164,11 +165,10 @@ class IsolateInspector {
|
|
|
164
165
|
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
165
166
|
}
|
|
166
167
|
static shouldAllowReorder(isolate) {
|
|
167
|
-
var _a;
|
|
168
168
|
if (vestUtils.isNullish(isolate)) {
|
|
169
169
|
return false;
|
|
170
170
|
}
|
|
171
|
-
return
|
|
171
|
+
return closestExists(isolate, node => node.allowReorder);
|
|
172
172
|
}
|
|
173
173
|
static usesKey(isolate) {
|
|
174
174
|
if (vestUtils.isNullish(isolate)) {
|
|
@@ -362,7 +362,7 @@ class Isolate {
|
|
|
362
362
|
this.parent = null;
|
|
363
363
|
this.key = null;
|
|
364
364
|
this.allowReorder = false;
|
|
365
|
-
this.type =
|
|
365
|
+
this.type = 'Isolate';
|
|
366
366
|
}
|
|
367
367
|
static create(callback, data) {
|
|
368
368
|
const parent = useIsolate();
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,r){t.invariant(e.children),e.children.push(r),n.setParent(r,e)}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 o of e.children){if(s)return;if((t.isNullish(i)||t.optionalFunctionValue(i,o))&&n(o,u),s)return;r(o,((t,e)=>{n(t,(()=>{e(),u()}))}),i)}function u(){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;do{if(e(n))return n;n=n.parent}while(n);return null}function u(t,e){return!!s(t,e)}var o,l=Object.freeze({__proto__:null,closest:s,closestExists:u,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){return!t.isNullish(e)&&u(e,(t=>t.allowReorder))}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.'}(o||(o={}));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,o.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 u=s;i&&(u=c.at(s,c.cursor(i)));const o=e(n,u);return t.invariant(o),Object.is(o,n)?[n,m(u,n,r)]:[o,o.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,o.NO_ACTIVE_ISOLATE),t.isNullish(r.keys[e])?r.keys[e]=n:t.deferThrow(t.text(o.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="Isolate"}static create(t,e){const r=E(),i=n.setParent(new this(e),r),[s,u]=_.reconcile(this.reconciler,i,t);return n.saveOutput(s,u),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;
|
|
@@ -17,6 +17,7 @@ class IsolateMutator {
|
|
|
17
17
|
static addChild(isolate, child) {
|
|
18
18
|
invariant(isolate.children);
|
|
19
19
|
isolate.children.push(child);
|
|
20
|
+
IsolateMutator.setParent(child, isolate);
|
|
20
21
|
}
|
|
21
22
|
static removeChild(isolate, node) {
|
|
22
23
|
var _a, _b;
|
|
@@ -120,12 +121,12 @@ function pluck(startNode, predicate, visitOnly) {
|
|
|
120
121
|
//startNode that satisfies the given predicate function.
|
|
121
122
|
function closest(startNode, predicate) {
|
|
122
123
|
let current = startNode;
|
|
123
|
-
|
|
124
|
+
do {
|
|
124
125
|
if (predicate(current)) {
|
|
125
126
|
return current;
|
|
126
127
|
}
|
|
127
128
|
current = current.parent;
|
|
128
|
-
}
|
|
129
|
+
} while (current);
|
|
129
130
|
return null;
|
|
130
131
|
}
|
|
131
132
|
// This function returns true if the closest ancestor Isolates of the
|
|
@@ -162,11 +163,10 @@ class IsolateInspector {
|
|
|
162
163
|
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
163
164
|
}
|
|
164
165
|
static shouldAllowReorder(isolate) {
|
|
165
|
-
var _a;
|
|
166
166
|
if (isNullish(isolate)) {
|
|
167
167
|
return false;
|
|
168
168
|
}
|
|
169
|
-
return
|
|
169
|
+
return closestExists(isolate, node => node.allowReorder);
|
|
170
170
|
}
|
|
171
171
|
static usesKey(isolate) {
|
|
172
172
|
if (isNullish(isolate)) {
|
|
@@ -360,7 +360,7 @@ class Isolate {
|
|
|
360
360
|
this.parent = null;
|
|
361
361
|
this.key = null;
|
|
362
362
|
this.allowReorder = false;
|
|
363
|
-
this.type =
|
|
363
|
+
this.type = 'Isolate';
|
|
364
364
|
}
|
|
365
365
|
static create(callback, data) {
|
|
366
366
|
const parent = useIsolate();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{invariant as t,isNullish as e,optionalFunctionValue as n,isNotNullish as r,assign as o,tinyState as u,bus as
|
|
1
|
+
import{invariant as t,isNullish as e,optionalFunctionValue as n,isNotNullish as r,assign as o,tinyState as u,bus as s,deferThrow as i,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),a.setParent(n,e)}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 i of t.children){if(u)return;if((e(o)||n(o,i))&&r(i,s),u)return;d(i,((t,e)=>{r(t,(()=>{e(),s()}))}),o)}function s(){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;do{if(e(n))return n;n=n.parent}while(n);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){return!e(t)&&v(t,(t=>t.allowReorder))}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 _=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:m,addNodeToHistory:C,createRef:function(t){return Object.freeze({historyRoot:u.createTinyState(null),Bus:s.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=_.useX();return(...n)=>{var r;const o=null!==(r=_.use())&&void 0!==r?r:e;return _.run(o.stateRef,(()=>t(...n)))}}function k(){return _.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 w{static reconcile(e,n,r){const o=A(),u=T();let s=u;o&&(s=E.at(u,E.cursor(o)));const i=e(n,s);return t(i),Object.is(i,n)?[n,b(s,n,r)]:[i,i.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:i(c(y.ENCOUNTERED_THE_SAME_KEY_TWICE,{key:n}))}(n.key,n),o}}function b(t,e,n){const r=I(),o=m(Object.assign({historyNode:t,runtimeNode:e},!r&&{runtimeRoot:e}),(()=>n(e)));return e.output=o,o}class K{constructor(t){this.children=[],this.keys={},this.parent=null,this.key=null,this.allowReorder=!1,this.type="Isolate"}static create(t,e){const n=A(),r=a.setParent(new this(e),n),[o,u]=w.reconcile(this.reconciler,r,t);return a.saveOutput(o,u),C(o),o}}function S(){return k().stateRef.Bus}function g(t,n){const r=S().emit;return e(t)||r(t,n),N(r)}K.reconciler=function(t,n){return e(n),t};var j=Object.freeze({__proto__:null,useBus:S,useEmit:g,usePrepareEmitter:function(t){const e=g();return n=>e(t,n)}});export{j as Bus,K as Isolate,E as IsolateInspector,a as IsolateMutator,w as Reconciler,R as VestRuntime,p as Walker};
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
static addChild(isolate, child) {
|
|
21
21
|
vestUtils.invariant(isolate.children);
|
|
22
22
|
isolate.children.push(child);
|
|
23
|
+
IsolateMutator.setParent(child, isolate);
|
|
23
24
|
}
|
|
24
25
|
static removeChild(isolate, node) {
|
|
25
26
|
var _a, _b;
|
|
@@ -123,12 +124,12 @@
|
|
|
123
124
|
//startNode that satisfies the given predicate function.
|
|
124
125
|
function closest(startNode, predicate) {
|
|
125
126
|
let current = startNode;
|
|
126
|
-
|
|
127
|
+
do {
|
|
127
128
|
if (predicate(current)) {
|
|
128
129
|
return current;
|
|
129
130
|
}
|
|
130
131
|
current = current.parent;
|
|
131
|
-
}
|
|
132
|
+
} while (current);
|
|
132
133
|
return null;
|
|
133
134
|
}
|
|
134
135
|
// This function returns true if the closest ancestor Isolates of the
|
|
@@ -165,11 +166,10 @@
|
|
|
165
166
|
return (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
166
167
|
}
|
|
167
168
|
static shouldAllowReorder(isolate) {
|
|
168
|
-
var _a;
|
|
169
169
|
if (vestUtils.isNullish(isolate)) {
|
|
170
170
|
return false;
|
|
171
171
|
}
|
|
172
|
-
return
|
|
172
|
+
return closestExists(isolate, node => node.allowReorder);
|
|
173
173
|
}
|
|
174
174
|
static usesKey(isolate) {
|
|
175
175
|
if (vestUtils.isNullish(isolate)) {
|
|
@@ -363,7 +363,7 @@
|
|
|
363
363
|
this.parent = null;
|
|
364
364
|
this.key = null;
|
|
365
365
|
this.allowReorder = false;
|
|
366
|
-
this.type =
|
|
366
|
+
this.type = 'Isolate';
|
|
367
367
|
}
|
|
368
368
|
static create(callback, data) {
|
|
369
369
|
const parent = useIsolate();
|
|
@@ -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";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
|
|
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),r.setParent(n,t)}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 o of t.children){if(s)return;if((e.isNullish(r)||e.optionalFunctionValue(r,o))&&n(o,u),s)return;i(o,((t,e)=>{n(t,(()=>{e(),u()}))}),r)}function u(){s=!0}}function s(t,e,n){let r=!1;return i(t,((t,n)=>{e(t)&&(n(),r=!0)}),n),r}function u(t,e){let n=t;do{if(e(n))return n;n=n.parent}while(n);return null}function o(t,e){return!!u(t,e)}var l,c=Object.freeze({__proto__:null,closest:u,closestExists:o,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){return!e.isNullish(t)&&o(t,(t=>t.allowReorder))}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 u=s;i&&(u=a.at(s,a.cursor(i)));const o=t(n,u);return e.invariant(o),Object.is(o,n)?[n,T(u,n,r)]:[o,o.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="Isolate"}static create(t,e){const n=R(),i=r.setParent(new this(e),n),[s,u]=m.reconcile(this.reconciler,i,t);return r.saveOutput(s,u),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-04eea9",
|
|
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-04eea9",
|
|
22
|
+
"vest-utils": "1.0.0-next-04eea9"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CB, TinyState, BusType } from "vest-utils";
|
|
1
|
+
import { CB, Nullable, TinyState, BusType, DynamicValue } from "vest-utils";
|
|
2
2
|
// I would rather not use `any` here, but instead use `Isolate`.
|
|
3
3
|
// The problem is that it breaks the actual implementation of `Isolate` in `IsolateTest`
|
|
4
4
|
// As it is not properly extending `Isolate`.
|
|
5
5
|
interface IRecociler<I = any> {
|
|
6
|
-
(currentNode: I, historicNode: Isolate
|
|
6
|
+
(currentNode: I, historicNode: Nullable<Isolate>): I;
|
|
7
7
|
}
|
|
8
8
|
declare class Reconciler {
|
|
9
9
|
static reconcile<Callback extends CB = CB>(reconciler: IRecociler<Isolate>, node: Isolate, callback: Callback): [
|
|
@@ -13,15 +13,15 @@ declare class Reconciler {
|
|
|
13
13
|
static removeAllNextNodesInIsolate(): void;
|
|
14
14
|
static handleIsolateNodeWithKey(node: Isolate): Isolate;
|
|
15
15
|
}
|
|
16
|
-
type IsolateKey =
|
|
16
|
+
type IsolateKey = Nullable<string>;
|
|
17
17
|
declare class Isolate<_D = any> {
|
|
18
|
-
children: Isolate[]
|
|
18
|
+
children: Nullable<Isolate[]>;
|
|
19
19
|
keys: Record<string, Isolate>;
|
|
20
|
-
parent: Isolate
|
|
20
|
+
parent: Nullable<Isolate>;
|
|
21
21
|
output: any;
|
|
22
22
|
key: IsolateKey;
|
|
23
23
|
allowReorder: boolean;
|
|
24
|
-
type:
|
|
24
|
+
type: string;
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
|
26
26
|
constructor(_data?: _D);
|
|
27
27
|
static reconciler: IRecociler;
|
|
@@ -32,9 +32,9 @@ declare namespace Walker {
|
|
|
32
32
|
// The problem is that it breaks the actual implementation of `Isolate` in `IsolateTest`
|
|
33
33
|
// As it is not properly extending `Isolate`.
|
|
34
34
|
interface IRecociler<I = any> {
|
|
35
|
-
(currentNode: I, historicNode: Isolate
|
|
35
|
+
(currentNode: I, historicNode: Nullable<Isolate>): I;
|
|
36
36
|
}
|
|
37
|
-
function BaseReconciler(currentNode: Isolate, historicNode: Isolate
|
|
37
|
+
function BaseReconciler(currentNode: Isolate, historicNode: Nullable<Isolate>): Isolate;
|
|
38
38
|
class Reconciler {
|
|
39
39
|
static reconcile<Callback extends CB = CB>(reconciler: IRecociler<Isolate>, node: Isolate, callback: Callback): [
|
|
40
40
|
Isolate,
|
|
@@ -43,15 +43,15 @@ declare namespace Walker {
|
|
|
43
43
|
static removeAllNextNodesInIsolate(): void;
|
|
44
44
|
static handleIsolateNodeWithKey(node: Isolate): Isolate;
|
|
45
45
|
}
|
|
46
|
-
type IsolateKey =
|
|
46
|
+
type IsolateKey = Nullable<string>;
|
|
47
47
|
class Isolate<_D = any> {
|
|
48
|
-
children: Isolate[]
|
|
48
|
+
children: Nullable<Isolate[]>;
|
|
49
49
|
keys: Record<string, Isolate>;
|
|
50
|
-
parent: Isolate
|
|
50
|
+
parent: Nullable<Isolate>;
|
|
51
51
|
output: any;
|
|
52
52
|
key: IsolateKey;
|
|
53
53
|
allowReorder: boolean;
|
|
54
|
-
type:
|
|
54
|
+
type: string;
|
|
55
55
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
|
56
56
|
constructor(_data?: _D);
|
|
57
57
|
static reconciler: IRecociler;
|
|
@@ -68,7 +68,7 @@ declare namespace Walker {
|
|
|
68
68
|
function has(startNode: Isolate, match: VisitOnlyPredicate): boolean;
|
|
69
69
|
// This function returns the first Isolate object in the tree that satisfies the given predicate function.
|
|
70
70
|
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
71
|
-
function find(startNode: Isolate, predicate: (node: Isolate) => boolean, visitOnly?: VisitOnlyPredicate): Isolate
|
|
71
|
+
function find(startNode: Isolate, predicate: (node: Isolate) => boolean, visitOnly?: VisitOnlyPredicate): Nullable<Isolate>;
|
|
72
72
|
// This function returns true if the given predicate function returns true for every Isolate object in the tree.
|
|
73
73
|
// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
|
|
74
74
|
function every(startNode: Isolate, predicate: (node: Isolate) => boolean, visitOnly?: VisitOnlyPredicate): boolean;
|
|
@@ -78,19 +78,19 @@ declare namespace Walker {
|
|
|
78
78
|
function pluck(startNode: Isolate, predicate: (node: Isolate) => boolean, visitOnly?: VisitOnlyPredicate): void;
|
|
79
79
|
// Returns the closest ancestor Isolate object of the given
|
|
80
80
|
//startNode that satisfies the given predicate function.
|
|
81
|
-
function closest(startNode: Isolate, predicate: (node: Isolate) => boolean): Isolate
|
|
81
|
+
function closest(startNode: Isolate, predicate: (node: Isolate) => boolean): Nullable<Isolate>;
|
|
82
82
|
// This function returns true if the closest ancestor Isolates of the
|
|
83
83
|
// given startNode that satisfies the given predicate function exists.
|
|
84
84
|
function closestExists(startNode: Isolate, predicate: (node: Isolate) => boolean): boolean;
|
|
85
85
|
}
|
|
86
86
|
type CTXType = StateRefType & {
|
|
87
|
-
historyNode: Isolate
|
|
88
|
-
runtimeNode: Isolate
|
|
89
|
-
runtimeRoot: Isolate
|
|
87
|
+
historyNode: Nullable<Isolate>;
|
|
88
|
+
runtimeNode: Nullable<Isolate>;
|
|
89
|
+
runtimeRoot: Nullable<Isolate>;
|
|
90
90
|
stateRef: StateRefType;
|
|
91
91
|
};
|
|
92
92
|
type StateRefType = {
|
|
93
|
-
historyRoot: TinyState<Isolate
|
|
93
|
+
historyRoot: TinyState<Nullable<Isolate>>;
|
|
94
94
|
Bus: BusType;
|
|
95
95
|
appData: Record<string, any>;
|
|
96
96
|
};
|
|
@@ -105,22 +105,22 @@ declare const RuntimeApi: {
|
|
|
105
105
|
useXAppData: typeof useXAppData;
|
|
106
106
|
};
|
|
107
107
|
declare function useXAppData<T = object>(): T;
|
|
108
|
-
declare function createRef(setter:
|
|
109
|
-
declare function persist<T extends
|
|
108
|
+
declare function createRef(setter: DynamicValue<Record<string, any>>): StateRefType;
|
|
109
|
+
declare function persist<T extends (...args: any[]) => any>(cb: T): T;
|
|
110
110
|
declare function addNodeToHistory(node: Isolate): void;
|
|
111
111
|
declare function useCurrentCursor(): number;
|
|
112
112
|
declare function useAvailableRoot<I extends Isolate = Isolate>(): I;
|
|
113
113
|
declare function reset(): void;
|
|
114
114
|
declare class IsolateInspector {
|
|
115
|
-
static at(isolate: Isolate
|
|
116
|
-
static cursor(isolate: Isolate
|
|
117
|
-
static shouldAllowReorder(isolate: Isolate
|
|
118
|
-
static usesKey(isolate: Isolate
|
|
115
|
+
static at(isolate: Nullable<Isolate>, at: number): Nullable<Isolate>;
|
|
116
|
+
static cursor(isolate: Nullable<Isolate>): number;
|
|
117
|
+
static shouldAllowReorder(isolate: Nullable<Isolate>): boolean;
|
|
118
|
+
static usesKey(isolate: Nullable<Isolate>): boolean;
|
|
119
119
|
}
|
|
120
120
|
declare class IsolateMutator {
|
|
121
|
-
static setParent(isolate: Isolate, parent: Isolate
|
|
121
|
+
static setParent(isolate: Isolate, parent: Nullable<Isolate>): Isolate;
|
|
122
122
|
static saveOutput(isolate: Isolate, output: any): Isolate;
|
|
123
|
-
static setKey(isolate: Isolate, key: string
|
|
123
|
+
static setKey(isolate: Isolate, key: Nullable<string>): Isolate;
|
|
124
124
|
static addChild(isolate: Isolate, child: Isolate): void;
|
|
125
125
|
static removeChild(isolate: Isolate, node: Isolate): void;
|
|
126
126
|
static slice(isolate: Isolate, at: number): void;
|