verstak 0.23.107 → 0.23.109

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.
@@ -1,745 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
11
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
12
- return new (P || (P = Promise))(function (resolve, reject) {
13
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
14
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
15
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16
- step((generator = generator.apply(thisArg, _arguments || [])).next());
17
- });
18
- };
19
- import { reactive, nonreactive, Transaction, options, Reentrance, Rx, Collection, ObservableObject, raw } from "reactronic";
20
- import { getCallerInfo } from "./Utils";
21
- import { emitLetters, equalCellRanges } from "./CellRange";
22
- import { Cursor, Align, TableCursor } from "./Cursor";
23
- export var Priority;
24
- (function (Priority) {
25
- Priority[Priority["Realtime"] = 0] = "Realtime";
26
- Priority[Priority["Normal"] = 1] = "Normal";
27
- Priority[Priority["Background"] = 2] = "Background";
28
- })(Priority || (Priority = {}));
29
- export function Fragment(builder, base) {
30
- return VBlock.claim(Driver.fragment, builder, base);
31
- }
32
- export class VBlock {
33
- get isInitialRendering() {
34
- return this.stamp === 2;
35
- }
36
- static root(render) {
37
- gSysRoot.instance.builder.render = render;
38
- triggerRendering(gSysRoot);
39
- }
40
- static get current() {
41
- return gCurrent.instance;
42
- }
43
- static renderNestedTreesThenDo(action) {
44
- runRenderNestedTreesThenDo(undefined, action);
45
- }
46
- static runForAllBlocks(action) {
47
- forEachChildRecursively(gSysRoot, action);
48
- }
49
- static claim(driver, builder, base) {
50
- var _a;
51
- let result;
52
- const owner = gCurrent.instance;
53
- const children = owner.children;
54
- let ex = undefined;
55
- if (builder)
56
- builder.base = base;
57
- else
58
- builder = base !== null && base !== void 0 ? base : {};
59
- let key = builder.key;
60
- if (driver.isRow) {
61
- const last = children.lastClaimedItem();
62
- if (((_a = last === null || last === void 0 ? void 0 : last.instance) === null || _a === void 0 ? void 0 : _a.driver) === driver)
63
- ex = last;
64
- }
65
- ex !== null && ex !== void 0 ? ex : (ex = children.claim(key = key || VBlock.generateKey(owner), undefined, "nested blocks can be declared inside render function only"));
66
- if (ex) {
67
- result = ex.instance;
68
- if (result.driver !== driver && driver !== undefined)
69
- throw new Error(`changing block driver is not yet supported: "${result.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
70
- const exTriggers = result.builder.triggers;
71
- if (triggersAreEqual(builder.triggers, exTriggers))
72
- builder.triggers = exTriggers;
73
- result.builder = builder;
74
- }
75
- else {
76
- result = new VBlockImpl(key || VBlock.generateKey(owner), driver, owner, builder);
77
- result.item = children.add(result);
78
- VBlockImpl.grandCount++;
79
- if (isReaction(builder))
80
- VBlockImpl.disposableCount++;
81
- }
82
- return result;
83
- }
84
- static generateKey(owner) {
85
- const n = owner.numerator++;
86
- const lettered = emitLetters(n);
87
- let result;
88
- if (Rx.isLogging)
89
- result = `·${getCallerInfo(lettered)}`;
90
- else
91
- result = `·${lettered}`;
92
- return result;
93
- }
94
- static getDefaultLoggingOptions() {
95
- return VBlockImpl.logging;
96
- }
97
- static setDefaultLoggingOptions(logging) {
98
- VBlockImpl.logging = logging;
99
- }
100
- }
101
- VBlock.shortFrameDuration = 16;
102
- VBlock.longFrameDuration = 300;
103
- VBlock.currentRenderingPriority = Priority.Realtime;
104
- VBlock.frameDuration = VBlock.longFrameDuration;
105
- export var Layout;
106
- (function (Layout) {
107
- Layout[Layout["Section"] = 0] = "Section";
108
- Layout[Layout["Table"] = 1] = "Table";
109
- Layout[Layout["Row"] = 2] = "Row";
110
- Layout[Layout["Group"] = 3] = "Group";
111
- Layout[Layout["Note"] = 4] = "Note";
112
- })(Layout || (Layout = {}));
113
- export class Driver {
114
- constructor(name, isRow, preset) {
115
- this.name = name;
116
- this.isRow = isRow;
117
- this.preset = preset;
118
- }
119
- create(block, b) {
120
- }
121
- claim(block) {
122
- const b = block;
123
- invokeClaim(b, b.builder);
124
- }
125
- initialize(block) {
126
- var _a;
127
- const b = block;
128
- (_a = this.preset) === null || _a === void 0 ? void 0 : _a.call(this, b);
129
- invokeInitialize(b, b.builder);
130
- }
131
- deploy(block) {
132
- }
133
- render(block) {
134
- invokeRender(block, block.builder);
135
- }
136
- finalize(block, isLeader) {
137
- const b = block;
138
- invokeFinalize(b, b.builder);
139
- return isLeader;
140
- }
141
- applyChildrenLayout(block, value) {
142
- const b = block;
143
- if (value === Layout.Table)
144
- b.cursor = new TableCursor();
145
- else
146
- b.cursor = new Cursor();
147
- }
148
- applyCellRange(block, value) {
149
- }
150
- applyWidthGrowth(block, value) {
151
- }
152
- applyMinWidth(block, value) {
153
- }
154
- applyMaxWidth(block, value) {
155
- }
156
- applyHeightGrowth(block, value) {
157
- }
158
- applyMinHeight(block, value) {
159
- }
160
- applyMaxHeight(block, value) {
161
- }
162
- applyContentAlignment(block, value) {
163
- }
164
- applyBlockAlignment(block, value) {
165
- }
166
- applyContentWrapping(block, value) {
167
- }
168
- applyOverlayVisible(block, value) {
169
- }
170
- applyStyle(block, secondary, styleName, enabled) {
171
- }
172
- }
173
- Driver.fragment = new Driver("fragment", false, b => b.childrenLayout = Layout.Group);
174
- function isReaction(builder) {
175
- var _a;
176
- return (_a = builder === null || builder === void 0 ? void 0 : builder.reaction) !== null && _a !== void 0 ? _a : ((builder === null || builder === void 0 ? void 0 : builder.base) ? isReaction(builder === null || builder === void 0 ? void 0 : builder.base) : false);
177
- }
178
- function invokeClaim(block, builder) {
179
- const claim = builder.claim;
180
- const base = builder.base;
181
- if (claim)
182
- claim(block, base ? () => invokeClaim(block, base) : NOP);
183
- else if (base)
184
- invokeClaim(block, base);
185
- }
186
- function invokeInitialize(block, builder) {
187
- const initialize = builder.initialize;
188
- const base = builder.base;
189
- if (initialize)
190
- initialize(block, base ? () => invokeInitialize(block, base) : NOP);
191
- else if (base)
192
- invokeInitialize(block, base);
193
- }
194
- function invokeRender(block, builder) {
195
- const render = builder.render;
196
- const base = builder.base;
197
- if (render)
198
- render(block, base ? () => invokeRender(block, base) : NOP);
199
- else if (base)
200
- invokeRender(block, base);
201
- }
202
- function invokeFinalize(block, builder) {
203
- const finalize = builder.finalize;
204
- const base = builder.base;
205
- if (finalize)
206
- finalize(block, base ? () => invokeFinalize(block, base) : NOP);
207
- else if (base)
208
- invokeFinalize(block, base);
209
- }
210
- export class StaticDriver extends Driver {
211
- constructor(element, name, isRow, preset) {
212
- super(name, isRow, preset);
213
- this.element = element;
214
- }
215
- create(block, b) {
216
- b.native = this.element;
217
- }
218
- }
219
- export class ContextVariable {
220
- constructor(defaultValue) {
221
- this.defaultValue = defaultValue;
222
- }
223
- set value(value) {
224
- VBlockImpl.setContextVariableValue(this, value);
225
- }
226
- get value() {
227
- return VBlockImpl.useContextVariableValue(this);
228
- }
229
- get valueOrUndefined() {
230
- return VBlockImpl.tryUseContextVariable(this);
231
- }
232
- }
233
- function getBlockKey(block) {
234
- return block.stamp >= 0 ? block.key : undefined;
235
- }
236
- class VBlockContext extends ObservableObject {
237
- constructor(variable, value) {
238
- super();
239
- this.next = undefined;
240
- this.variable = variable;
241
- this.value = value;
242
- }
243
- }
244
- __decorate([
245
- raw,
246
- __metadata("design:type", Object)
247
- ], VBlockContext.prototype, "next", void 0);
248
- __decorate([
249
- raw,
250
- __metadata("design:type", ContextVariable)
251
- ], VBlockContext.prototype, "variable", void 0);
252
- class VBlockImpl extends VBlock {
253
- constructor(key, driver, owner, builder) {
254
- super();
255
- this.key = key;
256
- this.driver = driver;
257
- this.builder = builder;
258
- this.model = undefined;
259
- this.appliedChildrenLayout = Layout.Row;
260
- this.appliedPlacement = undefined;
261
- this.appliedCellRange = Cursor.UndefinedCellRange;
262
- this.appliedWidthGrowth = 0;
263
- this.appliedMinWidth = "";
264
- this.appliedMaxWidth = "";
265
- this.appliedHeightGrowth = 0;
266
- this.appliedMinHeight = "";
267
- this.appliedMaxHeight = "";
268
- this.appliedContentAlignment = Align.Default;
269
- this.appliedBlockAlignment = Align.Default;
270
- this.appliedContentWrapping = false;
271
- this.appliedOverlayVisible = undefined;
272
- this.wasStyleApplied = false;
273
- this.childrenShuffling = false;
274
- this.renderingPriority = Priority.Realtime;
275
- this.level = owner.level + 1;
276
- this.host = owner;
277
- this.children = new Collection(getBlockKey, this.isSequential);
278
- this.numerator = 0;
279
- this.item = undefined;
280
- this.stamp = 0;
281
- this.native = undefined;
282
- this.controller = undefined;
283
- this.cursor = new Cursor();
284
- this.outer = owner.context ? owner : owner.outer;
285
- this.context = undefined;
286
- }
287
- render(_triggers) {
288
- renderNow(this.item);
289
- }
290
- get isSequential() { return (this.childrenLayout & 1) === 0; }
291
- get isAuxiliary() { return (this.childrenLayout & 2) === 2; }
292
- get isSection() { return this.childrenLayout === Layout.Section; }
293
- get isTable() { return this.childrenLayout === Layout.Table; }
294
- get isMoved() {
295
- let owner = this.host;
296
- if (owner.driver.isRow)
297
- owner = owner.host;
298
- return owner.children.isMoved(this.item);
299
- }
300
- get childrenLayout() { return this.appliedChildrenLayout; }
301
- set childrenLayout(value) {
302
- if (value !== this.appliedChildrenLayout || this.stamp < 2) {
303
- this.driver.applyChildrenLayout(this, value);
304
- this.appliedChildrenLayout = value;
305
- }
306
- }
307
- get placement() { return this.appliedPlacement; }
308
- set placement(value) {
309
- if (this.appliedPlacement !== undefined)
310
- throw new Error("cells can be assigned only once during rendering");
311
- const cellRange = this.host.cursor.onwards(value);
312
- if (!equalCellRanges(cellRange, this.appliedCellRange)) {
313
- this.driver.applyCellRange(this, cellRange);
314
- this.appliedCellRange = cellRange;
315
- }
316
- this.appliedPlacement = value !== null && value !== void 0 ? value : {};
317
- }
318
- get widthGrowth() { return this.appliedWidthGrowth; }
319
- set widthGrowth(value) {
320
- if (value !== this.appliedWidthGrowth) {
321
- this.driver.applyWidthGrowth(this, value);
322
- this.appliedWidthGrowth = value;
323
- }
324
- }
325
- get minWidth() { return this.appliedMinWidth; }
326
- set minWidth(value) {
327
- if (value !== this.appliedMinWidth) {
328
- this.driver.applyMinWidth(this, value);
329
- this.appliedMinWidth = value;
330
- }
331
- }
332
- get maxWidth() { return this.appliedMaxWidth; }
333
- set maxWidth(value) {
334
- if (value !== this.appliedMaxWidth) {
335
- this.driver.applyMaxWidth(this, value);
336
- this.appliedMaxWidth = value;
337
- }
338
- }
339
- get heightGrowth() { return this.appliedHeightGrowth; }
340
- set heightGrowth(value) {
341
- if (value !== this.appliedHeightGrowth) {
342
- this.driver.applyHeightGrowth(this, value);
343
- this.appliedHeightGrowth = value;
344
- }
345
- }
346
- get minHeight() { return this.appliedMinHeight; }
347
- set minHeight(value) {
348
- if (value !== this.appliedMinHeight) {
349
- this.driver.applyMinHeight(this, value);
350
- this.appliedMinHeight = value;
351
- }
352
- }
353
- get maxHeight() { return this.appliedMaxHeight; }
354
- set maxHeight(value) {
355
- if (value !== this.appliedMaxHeight) {
356
- this.driver.applyMaxHeight(this, value);
357
- this.appliedMaxHeight = value;
358
- }
359
- }
360
- get contentAlignment() { return this.appliedContentAlignment; }
361
- set contentAlignment(value) {
362
- if (value !== this.appliedContentAlignment) {
363
- this.driver.applyContentAlignment(this, value);
364
- this.appliedContentAlignment = value;
365
- }
366
- }
367
- get blockAlignment() { return this.appliedBlockAlignment; }
368
- set blockAlignment(value) {
369
- if (value !== this.appliedBlockAlignment) {
370
- this.driver.applyBlockAlignment(this, value);
371
- this.appliedBlockAlignment = value;
372
- }
373
- }
374
- get contentWrapping() { return this.appliedContentWrapping; }
375
- set contentWrapping(value) {
376
- if (value !== this.appliedContentWrapping) {
377
- this.driver.applyContentWrapping(this, value);
378
- this.appliedContentWrapping = value;
379
- }
380
- }
381
- get overlayVisible() { return this.appliedOverlayVisible; }
382
- set overlayVisible(value) {
383
- if (value !== this.appliedOverlayVisible) {
384
- this.driver.applyOverlayVisible(this, value);
385
- this.appliedOverlayVisible = value;
386
- }
387
- }
388
- style(styleName, enabled) {
389
- this.driver.applyStyle(this, this.wasStyleApplied, styleName, enabled);
390
- this.wasStyleApplied = true;
391
- }
392
- configureReactronic(options) {
393
- if (this.stamp !== 1 || !isReaction(this.builder))
394
- throw new Error("reactronic can be configured only for reacting blocks and only inside initialize");
395
- return Rx.getController(this.render).configure(options);
396
- }
397
- static tryUseContextVariable(variable) {
398
- var _a, _b;
399
- let b = gCurrent.instance;
400
- while (((_a = b.context) === null || _a === void 0 ? void 0 : _a.variable) !== variable && b.host !== b)
401
- b = b.outer;
402
- return (_b = b.context) === null || _b === void 0 ? void 0 : _b.value;
403
- }
404
- static useContextVariableValue(variable) {
405
- var _a;
406
- const result = (_a = VBlockImpl.tryUseContextVariable(variable)) !== null && _a !== void 0 ? _a : variable.defaultValue;
407
- if (!result)
408
- throw new Error("context doesn't exist");
409
- return result;
410
- }
411
- static setContextVariableValue(variable, value) {
412
- const block = gCurrent.instance;
413
- const host = block.host;
414
- const hostCtx = nonreactive(() => { var _a; return (_a = host.context) === null || _a === void 0 ? void 0 : _a.value; });
415
- if (value && value !== hostCtx) {
416
- if (hostCtx)
417
- block.outer = host;
418
- else
419
- block.outer = host.outer;
420
- Transaction.run({ separation: true }, () => {
421
- const ctx = block.context;
422
- if (ctx) {
423
- ctx.variable = variable;
424
- ctx.value = value;
425
- }
426
- else
427
- block.context = new VBlockContext(variable, value);
428
- });
429
- }
430
- else if (hostCtx)
431
- block.outer = host;
432
- else
433
- block.outer = host.outer;
434
- }
435
- }
436
- VBlockImpl.grandCount = 0;
437
- VBlockImpl.disposableCount = 0;
438
- VBlockImpl.logging = undefined;
439
- __decorate([
440
- reactive,
441
- options({
442
- reentrance: Reentrance.CancelPrevious,
443
- triggeringArgs: true,
444
- noSideEffects: false,
445
- }),
446
- __metadata("design:type", Function),
447
- __metadata("design:paramtypes", [Object]),
448
- __metadata("design:returntype", void 0)
449
- ], VBlockImpl.prototype, "render", null);
450
- function runRenderNestedTreesThenDo(error, action) {
451
- var _a;
452
- const current = gCurrent;
453
- const owner = current.instance;
454
- const children = owner.children;
455
- if (children.isMergeInProgress) {
456
- let promised = undefined;
457
- try {
458
- children.endMerge(error);
459
- for (const item of children.removedItems(true))
460
- triggerFinalization(item, true, true);
461
- if (!error) {
462
- const ownerIsSection = owner.isSection;
463
- const sequential = children.isStrict;
464
- const cursor = owner.cursor;
465
- let p1 = undefined;
466
- let p2 = undefined;
467
- let redeploy = false;
468
- let hostingRow = owner;
469
- cursor.reset();
470
- for (const item of children.items()) {
471
- if (Transaction.isCanceled)
472
- break;
473
- const block = item.instance;
474
- const isRow = block.driver.isRow;
475
- const host = isRow ? owner : hostingRow;
476
- const p = (_a = block.renderingPriority) !== null && _a !== void 0 ? _a : Priority.Realtime;
477
- redeploy = markToRedeployIfNecessary(redeploy, host, item, children, sequential);
478
- if (p === Priority.Realtime)
479
- triggerRendering(item);
480
- else if (p === Priority.Normal)
481
- p1 = push(item, p1);
482
- else
483
- p2 = push(item, p2);
484
- if (ownerIsSection && isRow)
485
- hostingRow = block;
486
- }
487
- if (!Transaction.isCanceled && (p1 !== undefined || p2 !== undefined))
488
- promised = startIncrementalRendering(current, children, p1, p2).then(() => action(error), e => action(e));
489
- }
490
- }
491
- finally {
492
- if (!promised)
493
- action(error);
494
- }
495
- }
496
- }
497
- function markToRedeployIfNecessary(redeploy, host, item, children, sequential) {
498
- const block = item.instance;
499
- if (block.native) {
500
- if (redeploy || block.host !== host) {
501
- children.markAsMoved(item);
502
- redeploy = false;
503
- }
504
- }
505
- else if (sequential && children.isMoved(item))
506
- redeploy = true;
507
- block.host = host;
508
- return redeploy;
509
- }
510
- function startIncrementalRendering(owner, allChildren, priority1, priority2) {
511
- return __awaiter(this, void 0, void 0, function* () {
512
- const stamp = owner.instance.stamp;
513
- if (priority1)
514
- yield renderIncrementally(owner, stamp, allChildren, priority1, Priority.Normal);
515
- if (priority2)
516
- yield renderIncrementally(owner, stamp, allChildren, priority2, Priority.Background);
517
- });
518
- }
519
- function renderIncrementally(owner, stamp, allChildren, items, priority) {
520
- return __awaiter(this, void 0, void 0, function* () {
521
- yield Transaction.requestNextFrame();
522
- const block = owner.instance;
523
- if (!Transaction.isCanceled || !Transaction.isFrameOver(1, VBlock.shortFrameDuration / 3)) {
524
- let outerPriority = VBlock.currentRenderingPriority;
525
- VBlock.currentRenderingPriority = priority;
526
- try {
527
- if (block.childrenShuffling)
528
- shuffle(items);
529
- const frameDurationLimit = priority === Priority.Background ? VBlock.shortFrameDuration : Infinity;
530
- let frameDuration = Math.min(frameDurationLimit, Math.max(VBlock.frameDuration / 4, VBlock.shortFrameDuration));
531
- for (const child of items) {
532
- triggerRendering(child);
533
- if (Transaction.isFrameOver(1, frameDuration)) {
534
- VBlock.currentRenderingPriority = outerPriority;
535
- yield Transaction.requestNextFrame(0);
536
- outerPriority = VBlock.currentRenderingPriority;
537
- VBlock.currentRenderingPriority = priority;
538
- frameDuration = Math.min(4 * frameDuration, Math.min(frameDurationLimit, VBlock.frameDuration));
539
- }
540
- if (Transaction.isCanceled && Transaction.isFrameOver(1, VBlock.shortFrameDuration / 3))
541
- break;
542
- }
543
- }
544
- finally {
545
- VBlock.currentRenderingPriority = outerPriority;
546
- }
547
- }
548
- });
549
- }
550
- function triggerRendering(item) {
551
- const block = item.instance;
552
- if (block.stamp >= 0) {
553
- if (isReaction(block.builder)) {
554
- if (block.stamp === 0) {
555
- Transaction.outside(() => {
556
- if (Rx.isLogging)
557
- Rx.setLoggingHint(block, block.key);
558
- Rx.getController(block.render).configure({
559
- order: block.level,
560
- });
561
- });
562
- }
563
- nonreactive(block.render, block.builder.triggers);
564
- }
565
- else
566
- renderNow(item);
567
- }
568
- }
569
- function redeployIfNecessary(block) {
570
- const driver = block.driver;
571
- if (block.stamp === 0) {
572
- block.stamp = 1;
573
- nonreactive(() => {
574
- driver.create(block, block);
575
- driver.initialize(block);
576
- driver.deploy(block);
577
- });
578
- }
579
- else if (block.isMoved)
580
- nonreactive(() => driver.deploy(block));
581
- }
582
- function renderNow(item) {
583
- const block = item.instance;
584
- if (block.stamp >= 0) {
585
- let result = undefined;
586
- runUnder(item, () => {
587
- try {
588
- redeployIfNecessary(block);
589
- block.stamp++;
590
- block.numerator = 0;
591
- block.appliedPlacement = undefined;
592
- block.wasStyleApplied = false;
593
- block.children.beginMerge();
594
- const driver = block.driver;
595
- result = driver.render(block);
596
- if (driver.isRow)
597
- block.host.cursor.rowBreak();
598
- else if (block.appliedPlacement === undefined)
599
- block.placement = undefined;
600
- if (result instanceof Promise)
601
- result.then(v => { runRenderNestedTreesThenDo(undefined, NOP); return v; }, e => { console.log(e); runRenderNestedTreesThenDo(e !== null && e !== void 0 ? e : new Error("unknown error"), NOP); });
602
- else
603
- runRenderNestedTreesThenDo(undefined, NOP);
604
- }
605
- catch (e) {
606
- runRenderNestedTreesThenDo(e, NOP);
607
- console.log(`Rendering failed: ${block.key}`);
608
- console.log(`${e}`);
609
- }
610
- });
611
- }
612
- }
613
- function triggerFinalization(item, isLeader, individual) {
614
- const block = item.instance;
615
- if (block.stamp >= 0) {
616
- const driver = block.driver;
617
- if (individual && block.key !== block.builder.key && !driver.isRow)
618
- console.log(`WARNING: it is recommended to assign explicit key for conditionally rendered block in order to avoid unexpected side effects: ${block.key}`);
619
- block.stamp = ~block.stamp;
620
- const childrenAreLeaders = nonreactive(() => driver.finalize(block, isLeader));
621
- block.native = null;
622
- block.controller = null;
623
- if (isReaction(block.builder)) {
624
- item.aux = undefined;
625
- const last = gLastToDispose;
626
- if (last)
627
- gLastToDispose = last.aux = item;
628
- else
629
- gFirstToDispose = gLastToDispose = item;
630
- if (gFirstToDispose === item)
631
- Transaction.run({ separation: "disposal", hint: `runDisposalLoop(initiator=${item.instance.key})` }, () => {
632
- void runDisposalLoop().then(NOP, error => console.log(error));
633
- });
634
- }
635
- for (const item of block.children.items())
636
- triggerFinalization(item, childrenAreLeaders, false);
637
- VBlockImpl.grandCount--;
638
- }
639
- }
640
- function runDisposalLoop() {
641
- return __awaiter(this, void 0, void 0, function* () {
642
- yield Transaction.requestNextFrame();
643
- let item = gFirstToDispose;
644
- while (item !== undefined) {
645
- if (Transaction.isFrameOver(500, 5))
646
- yield Transaction.requestNextFrame();
647
- Rx.dispose(item.instance);
648
- item = item.aux;
649
- VBlockImpl.disposableCount--;
650
- }
651
- gFirstToDispose = gLastToDispose = undefined;
652
- });
653
- }
654
- function forEachChildRecursively(item, action) {
655
- const block = item.instance;
656
- const e = block.native;
657
- e && action(e);
658
- for (const item of block.children.items())
659
- forEachChildRecursively(item, action);
660
- }
661
- function wrap(func) {
662
- const current = gCurrent;
663
- const wrappedRunUnder = (...args) => {
664
- return runUnder(current, func, ...args);
665
- };
666
- return wrappedRunUnder;
667
- }
668
- function runUnder(item, func, ...args) {
669
- const outer = gCurrent;
670
- try {
671
- gCurrent = item;
672
- return func(...args);
673
- }
674
- finally {
675
- gCurrent = outer;
676
- }
677
- }
678
- function triggersAreEqual(a1, a2) {
679
- let result = a1 === a2;
680
- if (!result) {
681
- if (Array.isArray(a1)) {
682
- result = Array.isArray(a2) &&
683
- a1.length === a2.length &&
684
- a1.every((t, i) => t === a2[i]);
685
- }
686
- else if (a1 === Object(a1) && a2 === Object(a2)) {
687
- for (const p in a1) {
688
- result = a1[p] === a2[p];
689
- if (!result)
690
- break;
691
- }
692
- }
693
- }
694
- return result;
695
- }
696
- function push(item, array) {
697
- if (array == undefined)
698
- array = new Array();
699
- array.push(item);
700
- return array;
701
- }
702
- function shuffle(array) {
703
- const n = array.length - 1;
704
- let i = n;
705
- while (i >= 0) {
706
- const j = Math.floor(Math.random() * n);
707
- const t = array[i];
708
- array[i] = array[j];
709
- array[j] = t;
710
- i--;
711
- }
712
- return array;
713
- }
714
- const ORIGINAL_PROMISE_THEN = Promise.prototype.then;
715
- function reactronicDomHookedThen(resolve, reject) {
716
- resolve = resolve ? wrap(resolve) : defaultResolve;
717
- reject = reject ? wrap(reject) : defaultReject;
718
- return ORIGINAL_PROMISE_THEN.call(this, resolve, reject);
719
- }
720
- function defaultResolve(value) {
721
- return value;
722
- }
723
- function defaultReject(error) {
724
- throw error;
725
- }
726
- Promise.prototype.then = reactronicDomHookedThen;
727
- const NOP = (...args) => { };
728
- const gSysDriver = new StaticDriver(null, "SYSTEM", false, b => b.childrenLayout = Layout.Group);
729
- const gSysRoot = Collection.createItem(new VBlockImpl(gSysDriver.name, gSysDriver, { level: 0 }, { reaction: true, render: NOP }));
730
- gSysRoot.instance.item = gSysRoot;
731
- Object.defineProperty(gSysRoot.instance, "host", {
732
- value: gSysRoot.instance,
733
- writable: false,
734
- configurable: false,
735
- enumerable: true,
736
- });
737
- Object.defineProperty(gSysRoot.instance, "senior", {
738
- value: gSysRoot.instance,
739
- writable: false,
740
- configurable: false,
741
- enumerable: true,
742
- });
743
- let gCurrent = gSysRoot;
744
- let gFirstToDispose = undefined;
745
- let gLastToDispose = undefined;