reactronic 0.24.114 → 0.24.116
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.
|
@@ -18,6 +18,6 @@ export { Monitor } from './core/Monitor.js';
|
|
|
18
18
|
export { Journal } from './core/Journal.js';
|
|
19
19
|
export { RxSystem, raw, obs, transactional, reactive, cached, transaction, unobs, sensitive, options } from './RxSystem.js';
|
|
20
20
|
export { Mode, Priority } from './tree/RxNode.js';
|
|
21
|
-
export type { Delegate, SimpleDelegate,
|
|
21
|
+
export type { Delegate, SimpleDelegate, RxNode, RxNodeDecl, RxNodeDriver, RxNodeContext } from './tree/RxNode.js';
|
|
22
22
|
export { RxTree, BaseDriver, RxNodeVariable } from './tree/RxTree.js';
|
|
23
23
|
export { Clock } from './Clock.js';
|
|
@@ -12,10 +12,7 @@ export declare const enum Priority {
|
|
|
12
12
|
Normal = 1,
|
|
13
13
|
Background = 2
|
|
14
14
|
}
|
|
15
|
-
export interface
|
|
16
|
-
node: RxNode<any>;
|
|
17
|
-
}
|
|
18
|
-
export interface RxNode<E extends RxElement = any> {
|
|
15
|
+
export interface RxNode<E = unknown> {
|
|
19
16
|
readonly key: string;
|
|
20
17
|
readonly driver: RxNodeDriver<E>;
|
|
21
18
|
readonly declaration: Readonly<RxNodeDecl<E>>;
|
|
@@ -28,14 +25,13 @@ export interface RxNode<E extends RxElement = any> {
|
|
|
28
25
|
readonly stamp: number;
|
|
29
26
|
readonly outer: RxNode;
|
|
30
27
|
readonly context: RxNodeContext | undefined;
|
|
31
|
-
readonly isInitialUpdate: boolean;
|
|
32
28
|
priority?: Priority;
|
|
33
29
|
childrenShuffling: boolean;
|
|
34
30
|
strictOrder: boolean;
|
|
35
31
|
has(mode: Mode): boolean;
|
|
36
32
|
configureReactronic(options: Partial<MemberOptions>): MemberOptions;
|
|
37
33
|
}
|
|
38
|
-
export interface RxNodeDecl<E
|
|
34
|
+
export interface RxNodeDecl<E = unknown> {
|
|
39
35
|
preset?: RxNodeDecl<E>;
|
|
40
36
|
key?: string;
|
|
41
37
|
mode?: Mode;
|
|
@@ -44,15 +40,15 @@ export interface RxNodeDecl<E extends RxElement> {
|
|
|
44
40
|
update?: Delegate<E>;
|
|
45
41
|
finalize?: Delegate<E>;
|
|
46
42
|
}
|
|
47
|
-
export interface RxNodeDriver<E
|
|
43
|
+
export interface RxNodeDriver<E = unknown> {
|
|
48
44
|
readonly name: string;
|
|
49
45
|
readonly isPartitionSeparator: boolean;
|
|
50
46
|
readonly predefine?: SimpleDelegate<E>;
|
|
51
47
|
allocate(node: RxNode<E>): E;
|
|
52
|
-
initialize(
|
|
53
|
-
mount(
|
|
54
|
-
update(
|
|
55
|
-
finalize(
|
|
48
|
+
initialize(node: RxNode<E>): void;
|
|
49
|
+
mount(node: RxNode<E>): void;
|
|
50
|
+
update(node: RxNode<E>): void | Promise<void>;
|
|
51
|
+
finalize(node: RxNode<E>, isLeader: boolean): boolean;
|
|
56
52
|
}
|
|
57
53
|
export interface RxNodeContext<T extends Object = Object> {
|
|
58
54
|
value: T;
|
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
import { LoggingOptions } from '../Logging.js';
|
|
2
|
-
import { Priority, RxNodeDecl, RxNodeDriver, SimpleDelegate, RxNode
|
|
2
|
+
import { Priority, RxNodeDecl, RxNodeDriver, SimpleDelegate, RxNode } 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<E
|
|
9
|
-
static
|
|
8
|
+
static declare<E = void>(driver: RxNodeDriver<E>, declaration?: RxNodeDecl<E>, preset?: RxNodeDecl<E>): RxNode<E>;
|
|
9
|
+
static get isFirstUpdate(): boolean;
|
|
10
|
+
static get nodeStamp(): number;
|
|
11
|
+
static triggerUpdate(node: RxNode<any>, triggers: unknown): void;
|
|
10
12
|
static updateNestedTreesThenDo(action: (error: unknown) => void): void;
|
|
11
|
-
static findMatchingHost<E
|
|
12
|
-
static findMatchingPrevSibling<E
|
|
13
|
-
static forEachChildRecursively<E
|
|
13
|
+
static findMatchingHost<E = unknown, R = unknown>(node: RxNode<E>, match: SimpleDelegate<RxNode<E>, boolean>): RxNode<R> | undefined;
|
|
14
|
+
static findMatchingPrevSibling<E = unknown, R = unknown>(node: RxNode<E>, match: SimpleDelegate<RxNode<E>, boolean>): RxNode<R> | undefined;
|
|
15
|
+
static forEachChildRecursively<E = unknown>(node: RxNode<E>, action: SimpleDelegate<RxNode<E>>): void;
|
|
14
16
|
static getDefaultLoggingOptions(): LoggingOptions | undefined;
|
|
15
17
|
static setDefaultLoggingOptions(logging?: LoggingOptions): void;
|
|
16
18
|
}
|
|
17
|
-
export declare abstract class BaseDriver<E
|
|
19
|
+
export declare abstract class BaseDriver<E = unknown> implements RxNodeDriver<E> {
|
|
18
20
|
readonly name: string;
|
|
19
21
|
readonly isPartitionSeparator: boolean;
|
|
20
22
|
readonly predefine?: SimpleDelegate<E> | undefined;
|
|
21
23
|
constructor(name: string, isPartitionSeparator: boolean, predefine?: SimpleDelegate<E> | undefined);
|
|
22
24
|
abstract allocate(node: RxNode<E>): E;
|
|
23
|
-
initialize(
|
|
24
|
-
mount(
|
|
25
|
-
update(
|
|
26
|
-
finalize(
|
|
25
|
+
initialize(node: RxNode<E>): void;
|
|
26
|
+
mount(node: RxNode<E>): void;
|
|
27
|
+
update(node: RxNode<E>): void | Promise<void>;
|
|
28
|
+
finalize(node: RxNode<E>, isLeader: boolean): boolean;
|
|
27
29
|
}
|
|
28
30
|
export declare class RxNodeVariable<T extends Object = Object> {
|
|
29
31
|
readonly defaultValue: T | undefined;
|
|
@@ -43,35 +43,39 @@ export class RxTree {
|
|
|
43
43
|
}
|
|
44
44
|
existing !== null && existing !== void 0 ? existing : (existing = children.tryMergeAsExisting(key = key || generateKey(owner), undefined, 'nested elements can be declared inside update function only'));
|
|
45
45
|
if (existing) {
|
|
46
|
-
|
|
47
|
-
result
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const exTriggers = node.declaration.triggers;
|
|
46
|
+
result = existing.instance;
|
|
47
|
+
if (result.driver !== driver && driver !== undefined)
|
|
48
|
+
throw new Error(`changing element driver is not yet supported: "${result.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
|
|
49
|
+
const exTriggers = result.declaration.triggers;
|
|
51
50
|
if (triggersAreEqual(declaration.triggers, exTriggers))
|
|
52
51
|
declaration.triggers = exTriggers;
|
|
53
|
-
|
|
52
|
+
result.declaration = declaration;
|
|
54
53
|
}
|
|
55
54
|
else {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
result = node.element;
|
|
55
|
+
result = new RxNodeImpl(key || generateKey(owner), driver, declaration, owner);
|
|
56
|
+
result.seat = children.mergeAsAdded(result);
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
59
|
else {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
result
|
|
65
|
-
triggerSeatUpdate(node.seat);
|
|
60
|
+
result = new RxNodeImpl(key || '', driver, declaration, owner);
|
|
61
|
+
result.seat = MergeList.createItem(result);
|
|
62
|
+
triggerUpdateViaSeat(result.seat);
|
|
66
63
|
}
|
|
67
64
|
return result;
|
|
68
65
|
}
|
|
69
|
-
static
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
static get isFirstUpdate() {
|
|
67
|
+
return (gCurrent === null || gCurrent === void 0 ? void 0 : gCurrent.instance.stamp) === 1;
|
|
68
|
+
}
|
|
69
|
+
static get nodeStamp() {
|
|
70
|
+
var _a;
|
|
71
|
+
return (_a = gCurrent === null || gCurrent === void 0 ? void 0 : gCurrent.instance.stamp) !== null && _a !== void 0 ? _a : -1;
|
|
72
|
+
}
|
|
73
|
+
static triggerUpdate(node, triggers) {
|
|
74
|
+
const impl = node;
|
|
75
|
+
const declaration = impl.declaration;
|
|
72
76
|
if (!triggersAreEqual(triggers, declaration.triggers)) {
|
|
73
77
|
declaration.triggers = triggers;
|
|
74
|
-
|
|
78
|
+
triggerUpdateViaSeat(impl.seat);
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
81
|
static updateNestedTreesThenDo(action) {
|
|
@@ -111,18 +115,18 @@ export class BaseDriver {
|
|
|
111
115
|
this.isPartitionSeparator = isPartitionSeparator;
|
|
112
116
|
this.predefine = predefine;
|
|
113
117
|
}
|
|
114
|
-
initialize(
|
|
118
|
+
initialize(node) {
|
|
115
119
|
var _a;
|
|
116
|
-
(_a = this.predefine) === null || _a === void 0 ? void 0 : _a.call(this, element);
|
|
117
|
-
initializeViaPresetChain(element,
|
|
120
|
+
(_a = this.predefine) === null || _a === void 0 ? void 0 : _a.call(this, node.element);
|
|
121
|
+
initializeViaPresetChain(node.element, node.declaration);
|
|
118
122
|
}
|
|
119
|
-
mount(
|
|
123
|
+
mount(node) {
|
|
120
124
|
}
|
|
121
|
-
update(
|
|
122
|
-
updateViaPresetChain(element,
|
|
125
|
+
update(node) {
|
|
126
|
+
updateViaPresetChain(node.element, node.declaration);
|
|
123
127
|
}
|
|
124
|
-
finalize(
|
|
125
|
-
finalizeViaPresetChain(element,
|
|
128
|
+
finalize(node, isLeader) {
|
|
129
|
+
finalizeViaPresetChain(node.element, node.declaration);
|
|
126
130
|
return isLeader;
|
|
127
131
|
}
|
|
128
132
|
}
|
|
@@ -196,6 +200,7 @@ __decorate([
|
|
|
196
200
|
], RxNodeContextImpl.prototype, "variable", void 0);
|
|
197
201
|
class RxNodeImpl {
|
|
198
202
|
constructor(key, driver, declaration, owner) {
|
|
203
|
+
const thisAsUnknown = this;
|
|
199
204
|
this.key = key;
|
|
200
205
|
this.driver = driver;
|
|
201
206
|
this.declaration = declaration;
|
|
@@ -207,11 +212,11 @@ class RxNodeImpl {
|
|
|
207
212
|
}
|
|
208
213
|
else {
|
|
209
214
|
this.level = 1;
|
|
210
|
-
this.owner = owner =
|
|
211
|
-
this.outer =
|
|
215
|
+
this.owner = owner = thisAsUnknown;
|
|
216
|
+
this.outer = thisAsUnknown;
|
|
212
217
|
}
|
|
213
218
|
this.element = driver.allocate(this);
|
|
214
|
-
this.host =
|
|
219
|
+
this.host = thisAsUnknown;
|
|
215
220
|
this.children = new MergeList(getNodeKey, true);
|
|
216
221
|
this.seat = undefined;
|
|
217
222
|
this.stamp = Number.MAX_SAFE_INTEGER;
|
|
@@ -223,7 +228,6 @@ class RxNodeImpl {
|
|
|
223
228
|
if (this.has(Mode.IndependentUpdate))
|
|
224
229
|
RxNodeImpl.disposableNodeCount++;
|
|
225
230
|
}
|
|
226
|
-
get isInitialUpdate() { return this.stamp === 1; }
|
|
227
231
|
get strictOrder() { return this.children.isStrict; }
|
|
228
232
|
set strictOrder(value) { this.children.isStrict = value; }
|
|
229
233
|
get isMoved() { return this.owner.children.isMoved(this.seat); }
|
|
@@ -325,7 +329,7 @@ function runUpdateNestedTreesThenDo(error, action) {
|
|
|
325
329
|
const p = (_a = childNode.priority) !== null && _a !== void 0 ? _a : Priority.Realtime;
|
|
326
330
|
mounting = markToMountIfNecessary(mounting, host, child, children, sequential);
|
|
327
331
|
if (p === Priority.Realtime)
|
|
328
|
-
|
|
332
|
+
triggerUpdateViaSeat(child);
|
|
329
333
|
else if (p === Priority.Normal)
|
|
330
334
|
p1 = push(child, p1);
|
|
331
335
|
else
|
|
@@ -378,7 +382,7 @@ function updateIncrementally(owner, stamp, allChildren, items, priority) {
|
|
|
378
382
|
const frameDurationLimit = priority === Priority.Background ? RxTree.shortFrameDuration : Infinity;
|
|
379
383
|
let frameDuration = Math.min(frameDurationLimit, Math.max(RxTree.frameDuration / 4, RxTree.shortFrameDuration));
|
|
380
384
|
for (const child of items) {
|
|
381
|
-
|
|
385
|
+
triggerUpdateViaSeat(child);
|
|
382
386
|
if (Transaction.isFrameOver(1, frameDuration)) {
|
|
383
387
|
RxTree.currentUpdatePriority = outerPriority;
|
|
384
388
|
yield Transaction.requestNextFrame(0);
|
|
@@ -396,7 +400,7 @@ function updateIncrementally(owner, stamp, allChildren, items, priority) {
|
|
|
396
400
|
}
|
|
397
401
|
});
|
|
398
402
|
}
|
|
399
|
-
function
|
|
403
|
+
function triggerUpdateViaSeat(seat) {
|
|
400
404
|
const node = seat.instance;
|
|
401
405
|
if (node.stamp >= 0) {
|
|
402
406
|
if (node.has(Mode.IndependentUpdate)) {
|
|
@@ -416,26 +420,24 @@ function triggerSeatUpdate(seat) {
|
|
|
416
420
|
}
|
|
417
421
|
}
|
|
418
422
|
function mountOrRemountIfNecessary(node) {
|
|
419
|
-
const element = node.element;
|
|
420
423
|
const driver = node.driver;
|
|
421
424
|
if (node.stamp === Number.MAX_SAFE_INTEGER) {
|
|
422
425
|
node.stamp = Number.MAX_SAFE_INTEGER - 1;
|
|
423
426
|
unobs(() => {
|
|
424
|
-
driver.initialize(
|
|
427
|
+
driver.initialize(node);
|
|
425
428
|
if (!node.has(Mode.ManualMount)) {
|
|
426
429
|
node.stamp = 0;
|
|
427
|
-
if (
|
|
428
|
-
driver.mount(
|
|
430
|
+
if (node.host !== node)
|
|
431
|
+
driver.mount(node);
|
|
429
432
|
}
|
|
430
433
|
node.stamp = 0;
|
|
431
434
|
});
|
|
432
435
|
}
|
|
433
|
-
else if (node.isMoved && !node.has(Mode.ManualMount) &&
|
|
434
|
-
unobs(() => driver.mount(
|
|
436
|
+
else if (node.isMoved && !node.has(Mode.ManualMount) && node.host !== node)
|
|
437
|
+
unobs(() => driver.mount(node));
|
|
435
438
|
}
|
|
436
439
|
function updateNow(seat) {
|
|
437
440
|
const node = seat.instance;
|
|
438
|
-
const el = node.element;
|
|
439
441
|
if (node.stamp >= 0) {
|
|
440
442
|
let result = undefined;
|
|
441
443
|
runInside(seat, () => {
|
|
@@ -446,7 +448,7 @@ function updateNow(seat) {
|
|
|
446
448
|
node.numerator = 0;
|
|
447
449
|
node.children.beginMerge();
|
|
448
450
|
const driver = node.driver;
|
|
449
|
-
result = driver.update(
|
|
451
|
+
result = driver.update(node);
|
|
450
452
|
if (result instanceof Promise)
|
|
451
453
|
result.then(v => { runUpdateNestedTreesThenDo(undefined, NOP); return v; }, e => { console.log(e); runUpdateNestedTreesThenDo(e !== null && e !== void 0 ? e : new Error('unknown error'), NOP); });
|
|
452
454
|
else
|
|
@@ -463,13 +465,12 @@ function updateNow(seat) {
|
|
|
463
465
|
}
|
|
464
466
|
function triggerFinalization(seat, isLeader, individual) {
|
|
465
467
|
const node = seat.instance;
|
|
466
|
-
const el = node.element;
|
|
467
468
|
if (node.stamp >= 0) {
|
|
468
469
|
const driver = node.driver;
|
|
469
470
|
if (individual && node.key !== node.declaration.key && !driver.isPartitionSeparator)
|
|
470
471
|
console.log(`WARNING: it is recommended to assign explicit key for conditional element in order to avoid unexpected side effects: ${node.key}`);
|
|
471
472
|
node.stamp = ~node.stamp;
|
|
472
|
-
const childrenAreLeaders = unobs(() => driver.finalize(
|
|
473
|
+
const childrenAreLeaders = unobs(() => driver.finalize(node, isLeader));
|
|
473
474
|
if (node.has(Mode.IndependentUpdate)) {
|
|
474
475
|
seat.aux = undefined;
|
|
475
476
|
const last = gLastToDispose;
|