reactronic 0.24.110 → 0.24.112
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.
|
@@ -12,46 +12,49 @@ export declare const enum Priority {
|
|
|
12
12
|
Normal = 1,
|
|
13
13
|
Background = 2
|
|
14
14
|
}
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
abstract readonly driver: RxNodeDriver<T>;
|
|
18
|
-
abstract readonly declaration: Readonly<RxNodeDecl<T>>;
|
|
19
|
-
abstract readonly level: number;
|
|
20
|
-
abstract readonly owner: RxNode;
|
|
21
|
-
abstract element: T;
|
|
22
|
-
abstract readonly host: RxNode;
|
|
23
|
-
abstract readonly children: MergeListReader<RxNode>;
|
|
24
|
-
abstract readonly slot: MergedItem<RxNode<T>> | undefined;
|
|
25
|
-
abstract readonly stamp: number;
|
|
26
|
-
abstract readonly outer: RxNode;
|
|
27
|
-
abstract readonly context: RxNodeContext | undefined;
|
|
28
|
-
abstract readonly isInitialUpdate: boolean;
|
|
29
|
-
abstract priority?: Priority;
|
|
30
|
-
abstract childrenShuffling: boolean;
|
|
31
|
-
abstract strictOrder: boolean;
|
|
32
|
-
abstract has(mode: Mode): boolean;
|
|
33
|
-
abstract configureReactronic(options: Partial<MemberOptions>): MemberOptions;
|
|
15
|
+
export interface RxElement {
|
|
16
|
+
node: RxNode<any>;
|
|
34
17
|
}
|
|
35
|
-
export interface
|
|
36
|
-
|
|
18
|
+
export interface RxNode<E extends RxElement = any> {
|
|
19
|
+
readonly key: string;
|
|
20
|
+
readonly driver: RxNodeDriver<E>;
|
|
21
|
+
readonly declaration: Readonly<RxNodeDecl<E>>;
|
|
22
|
+
readonly level: number;
|
|
23
|
+
readonly owner: RxNode;
|
|
24
|
+
element: E;
|
|
25
|
+
readonly host: RxNode;
|
|
26
|
+
readonly children: MergeListReader<RxNode>;
|
|
27
|
+
readonly seat: MergedItem<RxNode<E>> | undefined;
|
|
28
|
+
readonly stamp: number;
|
|
29
|
+
readonly outer: RxNode;
|
|
30
|
+
readonly context: RxNodeContext | undefined;
|
|
31
|
+
readonly isInitialUpdate: boolean;
|
|
32
|
+
priority?: Priority;
|
|
33
|
+
childrenShuffling: boolean;
|
|
34
|
+
strictOrder: boolean;
|
|
35
|
+
has(mode: Mode): boolean;
|
|
36
|
+
configureReactronic(options: Partial<MemberOptions>): MemberOptions;
|
|
37
|
+
}
|
|
38
|
+
export interface RxNodeDecl<E extends RxElement> {
|
|
39
|
+
preset?: RxNodeDecl<E>;
|
|
37
40
|
key?: string;
|
|
38
41
|
mode?: Mode;
|
|
39
42
|
triggers?: unknown;
|
|
40
|
-
specify?: Delegate<
|
|
41
|
-
create?: Delegate<
|
|
42
|
-
initialize?: Delegate<
|
|
43
|
-
update?: Delegate<
|
|
44
|
-
finalize?: Delegate<
|
|
43
|
+
specify?: Delegate<E>;
|
|
44
|
+
create?: Delegate<E>;
|
|
45
|
+
initialize?: Delegate<E>;
|
|
46
|
+
update?: Delegate<E>;
|
|
47
|
+
finalize?: Delegate<E>;
|
|
45
48
|
}
|
|
46
|
-
export interface RxNodeDriver<
|
|
49
|
+
export interface RxNodeDriver<E extends RxElement> {
|
|
47
50
|
readonly name: string;
|
|
48
51
|
readonly isPartitionSeparator: boolean;
|
|
49
|
-
readonly predefine?: SimpleDelegate<
|
|
50
|
-
allocate(node: RxNode<
|
|
51
|
-
initialize(element:
|
|
52
|
-
mount(element:
|
|
53
|
-
update(element:
|
|
54
|
-
finalize(element:
|
|
52
|
+
readonly predefine?: SimpleDelegate<E>;
|
|
53
|
+
allocate(node: RxNode<E>): E;
|
|
54
|
+
initialize(element: E): void;
|
|
55
|
+
mount(element: E): void;
|
|
56
|
+
update(element: E): void | Promise<void>;
|
|
57
|
+
finalize(element: E, isLeader: boolean): boolean;
|
|
55
58
|
}
|
|
56
59
|
export interface RxNodeContext<T extends Object = Object> {
|
|
57
60
|
value: T;
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import { LoggingOptions } from './Logging.js';
|
|
2
|
-
import { Priority, RxNodeDecl, RxNodeDriver, SimpleDelegate, RxNode } from './RxNode.js';
|
|
2
|
+
import { Priority, RxNodeDecl, RxNodeDriver, SimpleDelegate, RxNode, RxElement } from './RxNode.js';
|
|
3
3
|
export declare class RxTree {
|
|
4
4
|
static readonly shortFrameDuration = 16;
|
|
5
5
|
static readonly longFrameDuration = 300;
|
|
6
6
|
static currentUpdatePriority: Priority;
|
|
7
7
|
static frameDuration: number;
|
|
8
|
-
static declare<
|
|
9
|
-
static triggerUpdate(element:
|
|
10
|
-
node: RxNode;
|
|
11
|
-
}, triggers: unknown): void;
|
|
8
|
+
static declare<E extends RxElement>(driver: RxNodeDriver<E>, declaration?: RxNodeDecl<E>, preset?: RxNodeDecl<E>): E;
|
|
9
|
+
static triggerUpdate(element: RxElement, triggers: unknown): void;
|
|
12
10
|
static updateNestedTreesThenDo(action: (error: unknown) => void): void;
|
|
13
|
-
static findMatchingHost<
|
|
14
|
-
static findMatchingPrevSibling<
|
|
15
|
-
static forEachChildRecursively<
|
|
11
|
+
static findMatchingHost<E extends RxElement, R extends RxElement>(node: RxNode<E>, match: SimpleDelegate<RxNode<E>, boolean>): RxNode<R> | undefined;
|
|
12
|
+
static findMatchingPrevSibling<E extends RxElement, R extends RxElement>(node: RxNode<E>, match: SimpleDelegate<RxNode<E>, boolean>): RxNode<R> | undefined;
|
|
13
|
+
static forEachChildRecursively<E extends RxElement>(node: RxNode<E>, action: SimpleDelegate<RxNode<E>>): void;
|
|
16
14
|
static getDefaultLoggingOptions(): LoggingOptions | undefined;
|
|
17
15
|
static setDefaultLoggingOptions(logging?: LoggingOptions): void;
|
|
18
16
|
}
|
|
19
|
-
export declare abstract class BaseDriver<
|
|
20
|
-
node: RxNode;
|
|
21
|
-
}> implements RxNodeDriver<T> {
|
|
17
|
+
export declare abstract class BaseDriver<E extends RxElement> implements RxNodeDriver<E> {
|
|
22
18
|
readonly name: string;
|
|
23
19
|
readonly isPartitionSeparator: boolean;
|
|
24
|
-
readonly predefine?: SimpleDelegate<
|
|
25
|
-
constructor(name: string, isPartitionSeparator: boolean, predefine?: SimpleDelegate<
|
|
26
|
-
abstract allocate(node: RxNode<
|
|
27
|
-
initialize(element:
|
|
28
|
-
mount(element:
|
|
29
|
-
update(element:
|
|
30
|
-
finalize(element:
|
|
20
|
+
readonly predefine?: SimpleDelegate<E> | undefined;
|
|
21
|
+
constructor(name: string, isPartitionSeparator: boolean, predefine?: SimpleDelegate<E> | undefined);
|
|
22
|
+
abstract allocate(node: RxNode<E>): E;
|
|
23
|
+
initialize(element: E): void;
|
|
24
|
+
mount(element: E): void;
|
|
25
|
+
update(element: E): void | Promise<void>;
|
|
26
|
+
finalize(element: E, isLeader: boolean): boolean;
|
|
31
27
|
}
|
|
32
28
|
export declare class RxNodeVariable<T extends Object = Object> {
|
|
33
29
|
readonly defaultValue: T | undefined;
|
|
@@ -54,24 +54,24 @@ export class RxTree {
|
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
56
|
const node = new RxNodeImpl(key || generateKey(owner), driver, declaration, owner);
|
|
57
|
-
node.
|
|
57
|
+
node.seat = children.mergeAsAdded(node);
|
|
58
58
|
result = node.element;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
const node = new RxNodeImpl(key || '', driver, declaration, owner);
|
|
63
|
-
node.
|
|
63
|
+
node.seat = MergeList.createItem(node);
|
|
64
64
|
result = node.element;
|
|
65
|
-
|
|
65
|
+
triggerUpdateGivenSeat(node.seat);
|
|
66
66
|
}
|
|
67
67
|
return result;
|
|
68
68
|
}
|
|
69
69
|
static triggerUpdate(element, triggers) {
|
|
70
|
-
const
|
|
71
|
-
const declaration =
|
|
70
|
+
const node = element.node;
|
|
71
|
+
const declaration = node.declaration;
|
|
72
72
|
if (!triggersAreEqual(triggers, declaration.triggers)) {
|
|
73
73
|
declaration.triggers = triggers;
|
|
74
|
-
|
|
74
|
+
triggerUpdateGivenSeat(node.seat);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
static updateNestedTreesThenDo(action) {
|
|
@@ -84,7 +84,7 @@ export class RxTree {
|
|
|
84
84
|
return p;
|
|
85
85
|
}
|
|
86
86
|
static findMatchingPrevSibling(node, match) {
|
|
87
|
-
let p = node.
|
|
87
|
+
let p = node.seat.prev;
|
|
88
88
|
while (p && !match(p.instance))
|
|
89
89
|
p = p.prev;
|
|
90
90
|
return p === null || p === void 0 ? void 0 : p.instance;
|
|
@@ -213,7 +213,7 @@ class RxNodeImpl {
|
|
|
213
213
|
this.element = driver.allocate(this);
|
|
214
214
|
this.host = this;
|
|
215
215
|
this.children = new MergeList(getNodeKey, true);
|
|
216
|
-
this.
|
|
216
|
+
this.seat = undefined;
|
|
217
217
|
this.stamp = Number.MAX_SAFE_INTEGER;
|
|
218
218
|
this.context = undefined;
|
|
219
219
|
this.numerator = 0;
|
|
@@ -226,12 +226,12 @@ class RxNodeImpl {
|
|
|
226
226
|
get isInitialUpdate() { return this.stamp === 1; }
|
|
227
227
|
get strictOrder() { return this.children.isStrict; }
|
|
228
228
|
set strictOrder(value) { this.children.isStrict = value; }
|
|
229
|
-
get isMoved() { return this.owner.children.isMoved(this.
|
|
229
|
+
get isMoved() { return this.owner.children.isMoved(this.seat); }
|
|
230
230
|
has(mode) {
|
|
231
231
|
return (getModeViaPresetChain(this.declaration) & mode) === mode;
|
|
232
232
|
}
|
|
233
233
|
update(_triggers) {
|
|
234
|
-
updateNow(this.
|
|
234
|
+
updateNow(this.seat);
|
|
235
235
|
}
|
|
236
236
|
configureReactronic(options) {
|
|
237
237
|
if (this.stamp < Number.MAX_SAFE_INTEGER - 1 || !this.has(Mode.PinpointUpdate))
|
|
@@ -247,7 +247,7 @@ class RxNodeImpl {
|
|
|
247
247
|
var _a, _b;
|
|
248
248
|
let node = RxNodeImpl.current.instance;
|
|
249
249
|
while (((_a = node.context) === null || _a === void 0 ? void 0 : _a.variable) !== variable && node.owner !== node)
|
|
250
|
-
node = node.outer.
|
|
250
|
+
node = node.outer.seat.instance;
|
|
251
251
|
return (_b = node.context) === null || _b === void 0 ? void 0 : _b.value;
|
|
252
252
|
}
|
|
253
253
|
static useNodeVariableValue(variable) {
|
|
@@ -308,8 +308,8 @@ function runUpdateNestedTreesThenDo(error, action) {
|
|
|
308
308
|
let promised = undefined;
|
|
309
309
|
try {
|
|
310
310
|
children.endMerge(error);
|
|
311
|
-
for (const
|
|
312
|
-
triggerFinalization(
|
|
311
|
+
for (const child of children.removedItems(true))
|
|
312
|
+
triggerFinalization(child, true, true);
|
|
313
313
|
if (!error) {
|
|
314
314
|
const sequential = children.isStrict;
|
|
315
315
|
let p1 = undefined;
|
|
@@ -326,7 +326,7 @@ function runUpdateNestedTreesThenDo(error, action) {
|
|
|
326
326
|
const p = (_a = el.node.priority) !== null && _a !== void 0 ? _a : Priority.Realtime;
|
|
327
327
|
mounting = markToMountIfNecessary(mounting, host, child, children, sequential);
|
|
328
328
|
if (p === Priority.Realtime)
|
|
329
|
-
|
|
329
|
+
triggerUpdateGivenSeat(child);
|
|
330
330
|
else if (p === Priority.Normal)
|
|
331
331
|
p1 = push(child, p1);
|
|
332
332
|
else
|
|
@@ -344,27 +344,27 @@ function runUpdateNestedTreesThenDo(error, action) {
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
function markToMountIfNecessary(mounting, host,
|
|
348
|
-
const node =
|
|
347
|
+
function markToMountIfNecessary(mounting, host, seat, children, sequential) {
|
|
348
|
+
const node = seat.instance;
|
|
349
349
|
const el = node.element;
|
|
350
350
|
if (el.native && !node.has(Mode.ManualMount)) {
|
|
351
351
|
if (mounting || node.host !== host) {
|
|
352
|
-
children.markAsMoved(
|
|
352
|
+
children.markAsMoved(seat);
|
|
353
353
|
mounting = false;
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
|
-
else if (sequential && children.isMoved(
|
|
356
|
+
else if (sequential && children.isMoved(seat))
|
|
357
357
|
mounting = true;
|
|
358
358
|
node.host = host;
|
|
359
359
|
return mounting;
|
|
360
360
|
}
|
|
361
|
-
function startIncrementalUpdate(
|
|
361
|
+
function startIncrementalUpdate(ownerSeat, allChildren, priority1, priority2) {
|
|
362
362
|
return __awaiter(this, void 0, void 0, function* () {
|
|
363
|
-
const stamp =
|
|
363
|
+
const stamp = ownerSeat.instance.stamp;
|
|
364
364
|
if (priority1)
|
|
365
|
-
yield updateIncrementally(
|
|
365
|
+
yield updateIncrementally(ownerSeat, stamp, allChildren, priority1, Priority.Normal);
|
|
366
366
|
if (priority2)
|
|
367
|
-
yield updateIncrementally(
|
|
367
|
+
yield updateIncrementally(ownerSeat, stamp, allChildren, priority2, Priority.Background);
|
|
368
368
|
});
|
|
369
369
|
}
|
|
370
370
|
function updateIncrementally(owner, stamp, allChildren, items, priority) {
|
|
@@ -380,7 +380,7 @@ function updateIncrementally(owner, stamp, allChildren, items, priority) {
|
|
|
380
380
|
const frameDurationLimit = priority === Priority.Background ? RxTree.shortFrameDuration : Infinity;
|
|
381
381
|
let frameDuration = Math.min(frameDurationLimit, Math.max(RxTree.frameDuration / 4, RxTree.shortFrameDuration));
|
|
382
382
|
for (const child of items) {
|
|
383
|
-
|
|
383
|
+
triggerUpdateGivenSeat(child);
|
|
384
384
|
if (Transaction.isFrameOver(1, frameDuration)) {
|
|
385
385
|
RxTree.currentUpdatePriority = outerPriority;
|
|
386
386
|
yield Transaction.requestNextFrame(0);
|
|
@@ -398,8 +398,8 @@ function updateIncrementally(owner, stamp, allChildren, items, priority) {
|
|
|
398
398
|
}
|
|
399
399
|
});
|
|
400
400
|
}
|
|
401
|
-
function
|
|
402
|
-
const node =
|
|
401
|
+
function triggerUpdateGivenSeat(seat) {
|
|
402
|
+
const node = seat.instance;
|
|
403
403
|
if (node.stamp >= 0) {
|
|
404
404
|
if (node.has(Mode.PinpointUpdate)) {
|
|
405
405
|
if (node.stamp === Number.MAX_SAFE_INTEGER) {
|
|
@@ -414,7 +414,7 @@ function triggerUpdate(slot) {
|
|
|
414
414
|
unobs(node.update, node.declaration.triggers);
|
|
415
415
|
}
|
|
416
416
|
else
|
|
417
|
-
updateNow(
|
|
417
|
+
updateNow(seat);
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
420
|
function mountOrRemountIfNecessary(node) {
|
|
@@ -435,12 +435,12 @@ function mountOrRemountIfNecessary(node) {
|
|
|
435
435
|
else if (node.isMoved && !node.has(Mode.ManualMount) && element.node.host !== element.node)
|
|
436
436
|
unobs(() => driver.mount(element));
|
|
437
437
|
}
|
|
438
|
-
function updateNow(
|
|
439
|
-
const node =
|
|
438
|
+
function updateNow(seat) {
|
|
439
|
+
const node = seat.instance;
|
|
440
440
|
const el = node.element;
|
|
441
441
|
if (node.stamp >= 0) {
|
|
442
442
|
let result = undefined;
|
|
443
|
-
runInside(
|
|
443
|
+
runInside(seat, () => {
|
|
444
444
|
mountOrRemountIfNecessary(node);
|
|
445
445
|
if (node.stamp < Number.MAX_SAFE_INTEGER - 1) {
|
|
446
446
|
try {
|
|
@@ -463,8 +463,8 @@ function updateNow(slot) {
|
|
|
463
463
|
});
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
|
-
function triggerFinalization(
|
|
467
|
-
const node =
|
|
466
|
+
function triggerFinalization(seat, isLeader, individual) {
|
|
467
|
+
const node = seat.instance;
|
|
468
468
|
const el = node.element;
|
|
469
469
|
if (node.stamp >= 0) {
|
|
470
470
|
const driver = node.driver;
|
|
@@ -475,14 +475,14 @@ function triggerFinalization(slot, isLeader, individual) {
|
|
|
475
475
|
el.native = null;
|
|
476
476
|
el.controller = null;
|
|
477
477
|
if (node.has(Mode.PinpointUpdate)) {
|
|
478
|
-
|
|
478
|
+
seat.aux = undefined;
|
|
479
479
|
const last = gLastToDispose;
|
|
480
480
|
if (last)
|
|
481
|
-
gLastToDispose = last.aux =
|
|
481
|
+
gLastToDispose = last.aux = seat;
|
|
482
482
|
else
|
|
483
|
-
gFirstToDispose = gLastToDispose =
|
|
484
|
-
if (gFirstToDispose ===
|
|
485
|
-
Transaction.run({ separation: 'disposal', hint: `runDisposalLoop(initiator=${
|
|
483
|
+
gFirstToDispose = gLastToDispose = seat;
|
|
484
|
+
if (gFirstToDispose === seat)
|
|
485
|
+
Transaction.run({ separation: 'disposal', hint: `runDisposalLoop(initiator=${seat.instance.key})` }, () => {
|
|
486
486
|
void runDisposalLoop().then(NOP, error => console.log(error));
|
|
487
487
|
});
|
|
488
488
|
}
|
|
@@ -494,12 +494,12 @@ function triggerFinalization(slot, isLeader, individual) {
|
|
|
494
494
|
function runDisposalLoop() {
|
|
495
495
|
return __awaiter(this, void 0, void 0, function* () {
|
|
496
496
|
yield Transaction.requestNextFrame();
|
|
497
|
-
let
|
|
498
|
-
while (
|
|
497
|
+
let seat = gFirstToDispose;
|
|
498
|
+
while (seat !== undefined) {
|
|
499
499
|
if (Transaction.isFrameOver(500, 5))
|
|
500
500
|
yield Transaction.requestNextFrame();
|
|
501
|
-
RxSystem.dispose(
|
|
502
|
-
|
|
501
|
+
RxSystem.dispose(seat.instance);
|
|
502
|
+
seat = seat.aux;
|
|
503
503
|
RxNodeImpl.disposableNodeCount--;
|
|
504
504
|
}
|
|
505
505
|
gFirstToDispose = gLastToDispose = undefined;
|
|
@@ -516,10 +516,10 @@ function wrapToRunInside(func) {
|
|
|
516
516
|
wrappedToRunInside = func;
|
|
517
517
|
return wrappedToRunInside;
|
|
518
518
|
}
|
|
519
|
-
function runInside(
|
|
519
|
+
function runInside(seat, func, ...args) {
|
|
520
520
|
const outer = gCurrent;
|
|
521
521
|
try {
|
|
522
|
-
gCurrent =
|
|
522
|
+
gCurrent = seat;
|
|
523
523
|
return func(...args);
|
|
524
524
|
}
|
|
525
525
|
finally {
|
|
@@ -18,6 +18,6 @@ export { Monitor } from './impl/Monitor.js';
|
|
|
18
18
|
export { Journal } from './impl/Journal.js';
|
|
19
19
|
export { RxSystem, raw, obs, transactional, reactive, cached, transaction, unobs, sensitive, options } from './RxSystem.js';
|
|
20
20
|
export { Mode, Priority } from './RxNode.js';
|
|
21
|
-
export type { Delegate, SimpleDelegate, RxNode, RxNodeDecl, RxNodeDriver, RxNodeContext } from './RxNode.js';
|
|
21
|
+
export type { Delegate, SimpleDelegate, RxElement, RxNode, RxNodeDecl, RxNodeDriver, RxNodeContext } from './RxNode.js';
|
|
22
22
|
export { RxTree, BaseDriver, RxNodeVariable } from './RxTree.js';
|
|
23
23
|
export { Clock } from './Clock.js';
|