vestjs-runtime 0.1.0-dev-ae6b14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,391 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vest-utils'), require('context')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vest-utils', 'context'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["vestjs-runtime"] = {}, global["vest-utils"], global.context));
5
+ })(this, (function (exports, vestUtils, context) { 'use strict';
6
+
7
+ // eslint-disable-next-line
8
+ function walk(startNode, callback, visitOnly) {
9
+ // If the startNode has no children, there is nothing to walk.
10
+ if (vestUtils.isNullish(startNode.children)) {
11
+ return;
12
+ }
13
+ let broke = false;
14
+ // For each child Isolate object, call the callback function.
15
+ for (const isolate of startNode.children) {
16
+ if (broke) {
17
+ return;
18
+ }
19
+ // If visitOnly is not provided or the predicate is satisfied, call the callback function.
20
+ if (vestUtils.isNullish(visitOnly) || vestUtils.optionalFunctionValue(visitOnly, isolate)) {
21
+ callback(isolate, breakout);
22
+ }
23
+ // If the breakout function has been called, stop the walk.
24
+ if (broke) {
25
+ return;
26
+ }
27
+ // Recursively walk through the child Isolate object.
28
+ walk(isolate, (child, innerBreakout) => {
29
+ callback(child, () => {
30
+ innerBreakout();
31
+ breakout();
32
+ });
33
+ }, visitOnly);
34
+ }
35
+ function breakout() {
36
+ broke = true;
37
+ }
38
+ }
39
+ // This function returns true if the given predicate function returns true for any Isolate object in the tree.
40
+ // If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
41
+ function some(startNode, predicate, visitOnly) {
42
+ let hasMatch = false;
43
+ // Call the walk function with a callback function that sets hasMatch to true if the predicate is satisfied.
44
+ walk(startNode, (node, breakout) => {
45
+ if (predicate(node)) {
46
+ breakout();
47
+ hasMatch = true;
48
+ }
49
+ }, visitOnly);
50
+ return hasMatch;
51
+ }
52
+ // This function returns true if the given predicate function returns true for any Isolate object in the tree.
53
+ // If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
54
+ function has(startNode, match) {
55
+ return some(startNode, () => true, match);
56
+ }
57
+ // This function returns the first Isolate object in the tree that satisfies the given predicate function.
58
+ // If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
59
+ function find(startNode, predicate, visitOnly) {
60
+ let found = null;
61
+ // Call the walk function with a callback function that sets found to the current node if the predicate is satisfied.
62
+ walk(startNode, (node, breakout) => {
63
+ if (predicate(node)) {
64
+ breakout();
65
+ found = node;
66
+ }
67
+ }, visitOnly);
68
+ return found;
69
+ }
70
+ // This function returns true if the given predicate function returns true for every Isolate object in the tree.
71
+ // If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
72
+ function every(startNode, predicate, visitOnly) {
73
+ let hasMatch = true;
74
+ walk(startNode, (node, breakout) => {
75
+ if (!predicate(node)) {
76
+ breakout();
77
+ hasMatch = false;
78
+ }
79
+ }, visitOnly);
80
+ return hasMatch;
81
+ }
82
+ // This function removes all Isolate objects in the tree that
83
+ // satisfy the given predicate function and have a parent.
84
+ // If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
85
+ function pluck(startNode, predicate, visitOnly) {
86
+ walk(startNode, node => {
87
+ if (predicate(node) && node.parent) {
88
+ node.parent.removeChild(node);
89
+ }
90
+ }, visitOnly);
91
+ }
92
+ // Returns the closest ancestor Isolate object of the given
93
+ //startNode that satisfies the given predicate function.
94
+ function closest(startNode, predicate) {
95
+ let current = startNode;
96
+ while (current.parent) {
97
+ if (predicate(current)) {
98
+ return current;
99
+ }
100
+ current = current.parent;
101
+ }
102
+ return null;
103
+ }
104
+ // This function returns true if the closest ancestor Isolates of the
105
+ // given startNode that satisfies the given predicate function exists.
106
+ function closestExists(startNode, predicate) {
107
+ return !!closest(startNode, predicate);
108
+ }
109
+
110
+ var IsolateWalker = /*#__PURE__*/Object.freeze({
111
+ __proto__: null,
112
+ closest: closest,
113
+ closestExists: closestExists,
114
+ every: every,
115
+ find: find,
116
+ has: has,
117
+ pluck: pluck,
118
+ some: some,
119
+ walk: walk
120
+ });
121
+
122
+ var ErrorStrings;
123
+ (function (ErrorStrings) {
124
+ ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
125
+ ErrorStrings["ENCOUNTERED_THE_SAME_KEY_TWICE"] = "Encountered the same test key \"{key}\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.";
126
+ })(ErrorStrings || (ErrorStrings = {}));
127
+
128
+ const PersistedContext = context.createCascade((stateRef, parentContext) => {
129
+ if (parentContext) {
130
+ return null;
131
+ }
132
+ vestUtils.invariant(stateRef.historyRoot);
133
+ const [historyRootNode] = stateRef.historyRoot();
134
+ const ctxRef = {};
135
+ vestUtils.assign(ctxRef, {
136
+ historyNode: historyRootNode,
137
+ runtimeNode: null,
138
+ runtimeRoot: null,
139
+ stateRef,
140
+ });
141
+ return ctxRef;
142
+ });
143
+ const Run = PersistedContext.run;
144
+ const RuntimeApi = {
145
+ Run,
146
+ createRef,
147
+ persist,
148
+ reset,
149
+ useAvailableRoot,
150
+ useBus,
151
+ useCurrentCursor,
152
+ useEmit,
153
+ usePrepareEmitter,
154
+ useXAppData,
155
+ };
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
+ function useXAppData() {
171
+ return useX().stateRef.appData;
172
+ }
173
+ function createRef(setter) {
174
+ return Object.freeze({
175
+ historyRoot: vestUtils.tinyState.createTinyState(null),
176
+ Bus: vestUtils.bus.createBus(),
177
+ appData: vestUtils.optionalFunctionValue(setter),
178
+ });
179
+ }
180
+ function persist(cb) {
181
+ const prev = PersistedContext.useX();
182
+ return ((...args) => {
183
+ var _a;
184
+ const ctxToUse = (_a = PersistedContext.use()) !== null && _a !== void 0 ? _a : prev;
185
+ return PersistedContext.run(ctxToUse.stateRef, () => cb(...args));
186
+ });
187
+ }
188
+ function useX() {
189
+ return PersistedContext.useX();
190
+ }
191
+ function useHistoryRoot() {
192
+ return useX().stateRef.historyRoot();
193
+ }
194
+ function useHistoryNode() {
195
+ return useX().historyNode;
196
+ }
197
+ function useSetHistory(history) {
198
+ const [, setHistoryRoot] = useHistoryRoot();
199
+ setHistoryRoot(history);
200
+ }
201
+ function useHistoryKey(key) {
202
+ var _a;
203
+ if (vestUtils.isNullish(key)) {
204
+ return null;
205
+ }
206
+ const historyNode = useX().historyNode;
207
+ return (_a = historyNode === null || historyNode === void 0 ? void 0 : historyNode.keys[key]) !== null && _a !== void 0 ? _a : null;
208
+ }
209
+ function useIsolate() {
210
+ var _a;
211
+ return (_a = useX().runtimeNode) !== null && _a !== void 0 ? _a : null;
212
+ }
213
+ 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;
216
+ }
217
+ function useRuntimeRoot() {
218
+ return useX().runtimeRoot;
219
+ }
220
+ function useSetNextIsolateChild(child) {
221
+ const currentIsolate = useIsolate();
222
+ vestUtils.invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
223
+ currentIsolate.addChild(child);
224
+ }
225
+ function useSetIsolateKey(key, value) {
226
+ if (!key) {
227
+ return;
228
+ }
229
+ const currentIsolate = useIsolate();
230
+ vestUtils.invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);
231
+ if (vestUtils.isNullish(currentIsolate.keys[key])) {
232
+ currentIsolate.keys[key] = value;
233
+ return;
234
+ }
235
+ vestUtils.deferThrow(vestUtils.text(ErrorStrings.ENCOUNTERED_THE_SAME_KEY_TWICE, { key }));
236
+ }
237
+ function useAvailableRoot() {
238
+ const root = useRuntimeRoot();
239
+ if (root) {
240
+ return root;
241
+ }
242
+ const [historyRoot] = useHistoryRoot();
243
+ return historyRoot;
244
+ }
245
+ function reset() {
246
+ const [, , resetHistoryRoot] = useHistoryRoot();
247
+ resetHistoryRoot();
248
+ }
249
+
250
+ function BaseReconciler(currentNode, historicNode) {
251
+ if (vestUtils.isNullish(historicNode)) {
252
+ return currentNode;
253
+ }
254
+ return currentNode;
255
+ }
256
+ class Reconciler {
257
+ static reconcile(reconciler, node, callback) {
258
+ var _a;
259
+ const parent = useIsolate();
260
+ const historyNode = useHistoryNode();
261
+ let localHistoryNode = historyNode;
262
+ if (parent) {
263
+ // If we have a parent, we need to get the history node from the parent's children
264
+ // 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;
267
+ }
268
+ const nextNode = reconciler(node, localHistoryNode);
269
+ vestUtils.invariant(nextNode);
270
+ if (Object.is(nextNode, node)) {
271
+ return [node, useRunAsNew(localHistoryNode, node, callback)];
272
+ }
273
+ return [nextNode, nextNode.output];
274
+ }
275
+ static removeAllNextNodesInIsolate() {
276
+ const testIsolate = useIsolate();
277
+ const historyNode = useHistoryNode();
278
+ if (!historyNode || !testIsolate) {
279
+ // This is probably unreachable, but TS is not convinced.
280
+ // Let's play it safe.
281
+ return;
282
+ }
283
+ historyNode.slice(useCurrentCursor());
284
+ }
285
+ static handleIsolateNodeWithKey(node) {
286
+ vestUtils.invariant(node.usesKey());
287
+ const prevNodeByKey = useHistoryKey(node.key);
288
+ let nextNode = node;
289
+ if (!vestUtils.isNullish(prevNodeByKey)) {
290
+ nextNode = prevNodeByKey;
291
+ }
292
+ useSetIsolateKey(node.key, node);
293
+ return nextNode;
294
+ }
295
+ }
296
+ function useRunAsNew(localHistoryNode, current, callback) {
297
+ const runtimeRoot = useRuntimeRoot();
298
+ // We're creating a new child isolate context where the local history node
299
+ // is the current history node, thus advancing the history cursor.
300
+ const output = Run(Object.assign({ historyNode: localHistoryNode, runtimeNode: current }, (!runtimeRoot && { runtimeRoot: current })), () => callback(current));
301
+ current.output = output;
302
+ return output;
303
+ }
304
+
305
+ class Isolate {
306
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
307
+ constructor(_data) {
308
+ this.children = [];
309
+ this.keys = {};
310
+ this.parent = null;
311
+ this.key = null;
312
+ 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;
358
+ }
359
+ static create(callback, data) {
360
+ return this.createImplementation(callback, data);
361
+ }
362
+ static createImplementation(callback, data) {
363
+ const parent = useIsolate();
364
+ const newCreatedNode = new this(data).setParent(parent);
365
+ const [nextIsolateChild, output] = Reconciler.reconcile(this.reconciler, newCreatedNode, callback);
366
+ nextIsolateChild.saveOutput(output);
367
+ this.setNode(nextIsolateChild);
368
+ return nextIsolateChild;
369
+ }
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
+ }
384
+ Isolate.reconciler = BaseReconciler;
385
+
386
+ exports.Isolate = Isolate;
387
+ exports.Reconciler = Reconciler;
388
+ exports.VestRuntime = RuntimeApi;
389
+ exports.Walker = IsolateWalker;
390
+
391
+ }));
@@ -0,0 +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}));
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "vestjs-runtime",
3
+ "version": "0.1.0-dev-ae6b14",
4
+ "description": "Internal runtime module used by Vest",
5
+ "license": "MIT",
6
+ "author": "ealush",
7
+ "main": "./dist/cjs/vestjs-runtime.js",
8
+ "module": "./dist/es/vestjs-runtime.production.js",
9
+ "unpkg": "./dist/umd/vestjs-runtime.production.js",
10
+ "jsdelivr": "./dist/umd/vestjs-runtime.production.js",
11
+ "types": "./types/vestjs-runtime.d.ts",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/ealush/vest.git",
15
+ "directory": "packages/vestjs-runtime"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/ealush/vest.git/issues"
19
+ },
20
+ "dependencies": {
21
+ "context": "3.0.9-dev-ae6b14",
22
+ "vest-utils": "1.0.0-dev-ae6b14"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "development": {
27
+ "types": "./types/vestjs-runtime.d.ts",
28
+ "browser": "./dist/es/vestjs-runtime.development.js",
29
+ "umd": "./dist/umd/vestjs-runtime.development.js",
30
+ "import": "./dist/es/vestjs-runtime.development.js",
31
+ "require": "./dist/cjs/vestjs-runtime.development.js",
32
+ "node": "./dist/cjs/vestjs-runtime.development.js",
33
+ "module": "./dist/es/vestjs-runtime.development.js",
34
+ "default": "./dist/cjs/vestjs-runtime.development.js"
35
+ },
36
+ "types": "./types/vestjs-runtime.d.ts",
37
+ "browser": "./dist/es/vestjs-runtime.production.js",
38
+ "umd": "./dist/umd/vestjs-runtime.production.js",
39
+ "import": "./dist/es/vestjs-runtime.production.js",
40
+ "require": "./dist/cjs/vestjs-runtime.production.js",
41
+ "node": "./dist/cjs/vestjs-runtime.production.js",
42
+ "module": "./dist/es/vestjs-runtime.production.js",
43
+ "default": "./dist/cjs/vestjs-runtime.production.js"
44
+ },
45
+ "./package.json": "./package.json",
46
+ "./*": "./*"
47
+ }
48
+ }
@@ -0,0 +1,143 @@
1
+ import { CB, TinyState, BusType } from "vest-utils";
2
+ interface IRecociler {
3
+ (currentNode: Isolate, historicNode: Isolate | null): Isolate;
4
+ }
5
+ declare class Reconciler {
6
+ static reconcile<Callback extends CB = CB>(reconciler: IRecociler, node: Isolate, callback: Callback): [
7
+ Isolate,
8
+ ReturnType<Callback>
9
+ ];
10
+ static removeAllNextNodesInIsolate(): void;
11
+ static handleIsolateNodeWithKey(node: Isolate): Isolate;
12
+ }
13
+ type IsolateKey = null | string;
14
+ declare class Isolate<_D = any> {
15
+ children: Isolate[] | null;
16
+ keys: Record<string, Isolate>;
17
+ parent: Isolate | null;
18
+ output?: any;
19
+ key: IsolateKey;
20
+ allowReorder: boolean;
21
+ static reconciler: IRecociler;
22
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
23
+ 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;
35
+ 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
+ }
40
+ declare namespace Walker {
41
+ interface IRecociler {
42
+ (currentNode: Isolate, historicNode: Isolate | null): Isolate;
43
+ }
44
+ function BaseReconciler(currentNode: Isolate, historicNode: Isolate | null): Isolate;
45
+ class Reconciler {
46
+ static reconcile<Callback extends CB = CB>(reconciler: IRecociler, node: Isolate, callback: Callback): [
47
+ Isolate,
48
+ ReturnType<Callback>
49
+ ];
50
+ static removeAllNextNodesInIsolate(): void;
51
+ static handleIsolateNodeWithKey(node: Isolate): Isolate;
52
+ }
53
+ type IsolateKey = null | string;
54
+ class Isolate<_D = any> {
55
+ children: Isolate[] | null;
56
+ keys: Record<string, Isolate>;
57
+ parent: Isolate | null;
58
+ output?: any;
59
+ key: IsolateKey;
60
+ allowReorder: boolean;
61
+ static reconciler: IRecociler;
62
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
63
+ 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;
75
+ 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
+ }
80
+ type VisitOnlyPredicate = (isolate: Isolate) => boolean;
81
+ // eslint-disable-next-line
82
+ function walk(startNode: Isolate, callback: (isolate: Isolate, breakout: () => void) => void, visitOnly?: VisitOnlyPredicate): void;
83
+ // This function returns true if the given predicate function returns true for any Isolate object in the tree.
84
+ // If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
85
+ function some(startNode: Isolate, predicate: (node: Isolate) => boolean, visitOnly?: VisitOnlyPredicate): boolean;
86
+ // This function returns true if the given predicate function returns true for any Isolate object in the tree.
87
+ // If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
88
+ function has(startNode: Isolate, match: VisitOnlyPredicate): boolean;
89
+ // This function returns the first Isolate object in the tree that satisfies the given predicate function.
90
+ // If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
91
+ function find(startNode: Isolate, predicate: (node: Isolate) => boolean, visitOnly?: VisitOnlyPredicate): Isolate | null;
92
+ // This function returns true if the given predicate function returns true for every Isolate object in the tree.
93
+ // If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
94
+ function every(startNode: Isolate, predicate: (node: Isolate) => boolean, visitOnly?: VisitOnlyPredicate): boolean;
95
+ // This function removes all Isolate objects in the tree that
96
+ // satisfy the given predicate function and have a parent.
97
+ // If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.
98
+ function pluck(startNode: Isolate, predicate: (node: Isolate) => boolean, visitOnly?: VisitOnlyPredicate): void;
99
+ // Returns the closest ancestor Isolate object of the given
100
+ //startNode that satisfies the given predicate function.
101
+ function closest(startNode: Isolate, predicate: (node: Isolate) => boolean): Isolate | null;
102
+ // This function returns true if the closest ancestor Isolates of the
103
+ // given startNode that satisfies the given predicate function exists.
104
+ function closestExists(startNode: Isolate, predicate: (node: Isolate) => boolean): boolean;
105
+ }
106
+ type CTXType = StateRefType & {
107
+ historyNode: Isolate | null;
108
+ runtimeNode: Isolate | null;
109
+ runtimeRoot: Isolate | null;
110
+ stateRef: StateRefType;
111
+ };
112
+ type StateRefType = {
113
+ historyRoot: TinyState<Isolate | null>;
114
+ Bus: BusType;
115
+ appData: Record<string, any>;
116
+ };
117
+ declare const RuntimeApi: {
118
+ Run: <R>(value: Partial<CTXType>, fn: () => R) => R;
119
+ createRef: typeof createRef;
120
+ persist: typeof persist;
121
+ reset: typeof reset;
122
+ useAvailableRoot: typeof useAvailableRoot;
123
+ useBus: typeof useBus;
124
+ useCurrentCursor: typeof useCurrentCursor;
125
+ useEmit: typeof useEmit;
126
+ usePrepareEmitter: typeof usePrepareEmitter;
127
+ useXAppData: typeof useXAppData;
128
+ };
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
+ declare function useXAppData<T = object>(): T;
137
+ declare function createRef(setter: Record<string, any> | (() => Record<string, any>)): StateRefType;
138
+ declare function persist<T extends CB>(cb: T): T;
139
+ declare function useCurrentCursor(): number;
140
+ declare function useAvailableRoot<I extends Isolate = Isolate>(): I;
141
+ declare function reset(): void;
142
+ export { Isolate, IsolateKey, Reconciler, IRecociler, Walker, RuntimeApi as VestRuntime };
143
+ //# sourceMappingURL=vestjs-runtime.d.ts.map
@@ -0,0 +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"}