reactronic 0.94.25029 → 0.94.25030
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.
|
@@ -20,5 +20,5 @@ export { Journal } from "./core/Journal.js";
|
|
|
20
20
|
export { runAtomically, runNonReactively, runSensitively, runContextually, manageReactiveOperation, configureCurrentReactiveOperation, disposeObservableObject } from "./System.js";
|
|
21
21
|
export { ReactiveSystem, observable, atomic, reactive, cached, options } from "./System.js";
|
|
22
22
|
export { ReactiveOperationEx } from "./OperationEx.js";
|
|
23
|
-
export {
|
|
23
|
+
export { ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
|
|
24
24
|
export type { Script, ScriptAsync, Handler, ReactiveTreeNodeDecl, ReactiveTreeNodeDriver, ReactiveTreeNodeContext } from "./core/TreeNode.js";
|
package/build/dist/source/api.js
CHANGED
|
@@ -16,4 +16,4 @@ export { Journal } from "./core/Journal.js";
|
|
|
16
16
|
export { runAtomically, runNonReactively, runSensitively, runContextually, manageReactiveOperation, configureCurrentReactiveOperation, disposeObservableObject } from "./System.js";
|
|
17
17
|
export { ReactiveSystem, observable, atomic, reactive, cached, options } from "./System.js";
|
|
18
18
|
export { ReactiveOperationEx } from "./OperationEx.js";
|
|
19
|
-
export {
|
|
19
|
+
export { ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
|
|
@@ -6,23 +6,11 @@ import { ObservableObject } from "../core/Mvcc.js";
|
|
|
6
6
|
export type Script<E> = (el: E, basis: () => void) => void;
|
|
7
7
|
export type ScriptAsync<E> = (el: E, basis: () => Promise<void>) => Promise<void>;
|
|
8
8
|
export type Handler<E = unknown, R = void> = (el: E) => R;
|
|
9
|
-
export declare class ReactiveTree {
|
|
10
|
-
static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, script?: Script<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
11
|
-
static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, declaration?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
12
|
-
static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, scriptOrDeclaration?: Script<E> | ReactiveTreeNodeDecl<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
13
|
-
static withBasis<E = void>(declaration?: ReactiveTreeNodeDecl<E>, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNodeDecl<E>;
|
|
14
|
-
static get isFirstScriptRun(): boolean;
|
|
15
|
-
static triggerScriptRun(node: ReactiveTreeNode<any>, triggers: unknown): void;
|
|
16
|
-
static triggerFinalization(node: ReactiveTreeNode<any>): void;
|
|
17
|
-
static runNestedNodeScriptsThenDo(action: (error: unknown) => void): void;
|
|
18
|
-
static markAsMounted(node: ReactiveTreeNode<any>, yes: boolean): void;
|
|
19
|
-
static findMatchingHost<E = unknown, R = unknown>(node: ReactiveTreeNode<E>, match: Handler<ReactiveTreeNode<E>, boolean>): ReactiveTreeNode<R> | undefined;
|
|
20
|
-
static findMatchingPrevSibling<E = unknown, R = unknown>(node: ReactiveTreeNode<E>, match: Handler<ReactiveTreeNode<E>, boolean>): ReactiveTreeNode<R> | undefined;
|
|
21
|
-
static forEachChildRecursively<E = unknown>(node: ReactiveTreeNode<E>, action: Handler<ReactiveTreeNode<E>>): void;
|
|
22
|
-
static getDefaultLoggingOptions(): LoggingOptions | undefined;
|
|
23
|
-
static setDefaultLoggingOptions(logging?: LoggingOptions): void;
|
|
24
|
-
}
|
|
25
9
|
export declare abstract class ReactiveTreeNode<E = unknown> {
|
|
10
|
+
static readonly shortFrameDuration = 16;
|
|
11
|
+
static readonly longFrameDuration = 300;
|
|
12
|
+
static frameDuration: number;
|
|
13
|
+
static currentScriptPriority: Priority;
|
|
26
14
|
abstract readonly key: string;
|
|
27
15
|
abstract readonly driver: ReactiveTreeNodeDriver<E>;
|
|
28
16
|
abstract readonly declaration: Readonly<ReactiveTreeNodeDecl<E>>;
|
|
@@ -39,15 +27,22 @@ export declare abstract class ReactiveTreeNode<E = unknown> {
|
|
|
39
27
|
abstract childrenShuffling: boolean;
|
|
40
28
|
abstract strictOrder: boolean;
|
|
41
29
|
abstract has(mode: Mode): boolean;
|
|
42
|
-
abstract
|
|
43
|
-
static get
|
|
44
|
-
static get
|
|
45
|
-
static
|
|
46
|
-
static
|
|
47
|
-
static
|
|
48
|
-
static
|
|
49
|
-
static
|
|
50
|
-
static
|
|
30
|
+
abstract configureReactivity(options: Partial<ReactivityOptions>): ReactivityOptions;
|
|
31
|
+
static get current(): ReactiveTreeNode;
|
|
32
|
+
static get isFirstScriptRun(): boolean;
|
|
33
|
+
static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, script?: Script<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
34
|
+
static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, declaration?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
35
|
+
static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, scriptOrDeclaration?: Script<E> | ReactiveTreeNodeDecl<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
36
|
+
static withBasis<E = void>(declaration?: ReactiveTreeNodeDecl<E>, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNodeDecl<E>;
|
|
37
|
+
static triggerScriptRun(node: ReactiveTreeNode<any>, triggers: unknown): void;
|
|
38
|
+
static triggerFinalization(node: ReactiveTreeNode<any>): void;
|
|
39
|
+
static runNestedNodeScriptsThenDo(action: (error: unknown) => void): void;
|
|
40
|
+
static markAsMounted(node: ReactiveTreeNode<any>, yes: boolean): void;
|
|
41
|
+
static findMatchingHost<E = unknown, R = unknown>(node: ReactiveTreeNode<E>, match: Handler<ReactiveTreeNode<E>, boolean>): ReactiveTreeNode<R> | undefined;
|
|
42
|
+
static findMatchingPrevSibling<E = unknown, R = unknown>(node: ReactiveTreeNode<E>, match: Handler<ReactiveTreeNode<E>, boolean>): ReactiveTreeNode<R> | undefined;
|
|
43
|
+
static forEachChildRecursively<E = unknown>(node: ReactiveTreeNode<E>, action: Handler<ReactiveTreeNode<E>>): void;
|
|
44
|
+
static getDefaultLoggingOptions(): LoggingOptions | undefined;
|
|
45
|
+
static setDefaultLoggingOptions(logging?: LoggingOptions): void;
|
|
51
46
|
}
|
|
52
47
|
export type ReactiveTreeNodeDecl<E = unknown> = {
|
|
53
48
|
script?: Script<E>;
|
|
@@ -107,10 +102,6 @@ declare class ReactiveTreeNodeImpl<E = unknown> extends ReactiveTreeNode<E> {
|
|
|
107
102
|
static logging: LoggingOptions | undefined;
|
|
108
103
|
static grandNodeCount: number;
|
|
109
104
|
static disposableNodeCount: number;
|
|
110
|
-
static readonly shortFrameDuration = 16;
|
|
111
|
-
static readonly longFrameDuration = 300;
|
|
112
|
-
static currentScriptPriority: Priority;
|
|
113
|
-
static frameDuration: number;
|
|
114
105
|
readonly key: string;
|
|
115
106
|
readonly driver: ReactiveTreeNodeDriver<E>;
|
|
116
107
|
declaration: ReactiveTreeNodeDecl<E>;
|
|
@@ -132,11 +123,11 @@ declare class ReactiveTreeNodeImpl<E = unknown> extends ReactiveTreeNode<E> {
|
|
|
132
123
|
get isMoved(): boolean;
|
|
133
124
|
has(mode: Mode): boolean;
|
|
134
125
|
script(_triggers: unknown): void;
|
|
135
|
-
|
|
126
|
+
configureReactivity(options: Partial<ReactivityOptions>): ReactivityOptions;
|
|
136
127
|
static get nodeSlot(): MergedItem<ReactiveTreeNodeImpl>;
|
|
137
|
-
static
|
|
138
|
-
static
|
|
139
|
-
static
|
|
128
|
+
static tryUseTreeVariableValue<T extends Object>(variable: ReactiveTreeVariable<T>): T | undefined;
|
|
129
|
+
static useTreeVariableValue<T extends Object>(variable: ReactiveTreeVariable<T>): T;
|
|
130
|
+
static setTreeVariableValue<T extends Object>(variable: ReactiveTreeVariable<T>, value: T | undefined): void;
|
|
140
131
|
}
|
|
141
132
|
export declare function observablesAreEqual(a1: any, a2: any): boolean;
|
|
142
133
|
export {};
|
|
@@ -23,7 +23,13 @@ import { Priority, Mode, Isolation, Reentrance } from "../Enums.js";
|
|
|
23
23
|
import { ObservableObject } from "../core/Mvcc.js";
|
|
24
24
|
import { Transaction } from "../core/Transaction.js";
|
|
25
25
|
import { ReactiveSystem, options, observable, reactive, runAtomically, runNonReactively, manageReactiveOperation, disposeObservableObject } from "../System.js";
|
|
26
|
-
export class
|
|
26
|
+
export class ReactiveTreeNode {
|
|
27
|
+
static get current() {
|
|
28
|
+
return ReactiveTreeNodeImpl.nodeSlot.instance;
|
|
29
|
+
}
|
|
30
|
+
static get isFirstScriptRun() {
|
|
31
|
+
return ReactiveTreeNode.current.stamp === 1;
|
|
32
|
+
}
|
|
27
33
|
static declare(driver, scriptOrDeclaration, scriptAsync, key, mode, preparation, preparationAsync, finalization, triggers, basis) {
|
|
28
34
|
let result;
|
|
29
35
|
let declaration;
|
|
@@ -69,9 +75,6 @@ export class ReactiveTree {
|
|
|
69
75
|
declaration = basis !== null && basis !== void 0 ? basis : {};
|
|
70
76
|
return declaration;
|
|
71
77
|
}
|
|
72
|
-
static get isFirstScriptRun() {
|
|
73
|
-
return ReactiveTreeNodeImpl.nodeSlot.instance.stamp === 1;
|
|
74
|
-
}
|
|
75
78
|
static triggerScriptRun(node, triggers) {
|
|
76
79
|
const impl = node;
|
|
77
80
|
const declaration = impl.declaration;
|
|
@@ -110,7 +113,7 @@ export class ReactiveTree {
|
|
|
110
113
|
static forEachChildRecursively(node, action) {
|
|
111
114
|
action(node);
|
|
112
115
|
for (const child of node.children.items())
|
|
113
|
-
|
|
116
|
+
ReactiveTreeNode.forEachChildRecursively(child.instance, action);
|
|
114
117
|
}
|
|
115
118
|
static getDefaultLoggingOptions() {
|
|
116
119
|
return ReactiveTreeNodeImpl.logging;
|
|
@@ -119,32 +122,10 @@ export class ReactiveTree {
|
|
|
119
122
|
ReactiveTreeNodeImpl.logging = logging;
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
static get stamp() {
|
|
127
|
-
return ReactiveTreeNodeImpl.nodeSlot.instance.stamp;
|
|
128
|
-
}
|
|
129
|
-
static get triggers() {
|
|
130
|
-
return ReactiveTreeNodeImpl.nodeSlot.instance.declaration.triggers;
|
|
131
|
-
}
|
|
132
|
-
static get priority() {
|
|
133
|
-
return ReactiveTreeNodeImpl.nodeSlot.instance.priority;
|
|
134
|
-
}
|
|
135
|
-
static set priority(value) {
|
|
136
|
-
ReactiveTreeNodeImpl.nodeSlot.instance.priority = value;
|
|
137
|
-
}
|
|
138
|
-
static get childrenShuffling() {
|
|
139
|
-
return ReactiveTreeNodeImpl.nodeSlot.instance.childrenShuffling;
|
|
140
|
-
}
|
|
141
|
-
static set childrenShuffling(value) {
|
|
142
|
-
ReactiveTreeNodeImpl.nodeSlot.instance.childrenShuffling = value;
|
|
143
|
-
}
|
|
144
|
-
static get effectiveScriptPriority() {
|
|
145
|
-
return ReactiveTreeNodeImpl.currentScriptPriority;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
125
|
+
ReactiveTreeNode.shortFrameDuration = 16;
|
|
126
|
+
ReactiveTreeNode.longFrameDuration = 300;
|
|
127
|
+
ReactiveTreeNode.frameDuration = ReactiveTreeNode.longFrameDuration;
|
|
128
|
+
ReactiveTreeNode.currentScriptPriority = Priority.realtime;
|
|
148
129
|
export class BaseDriver {
|
|
149
130
|
constructor(name, isPartition, initialize) {
|
|
150
131
|
this.name = name;
|
|
@@ -177,13 +158,13 @@ export class ReactiveTreeVariable {
|
|
|
177
158
|
this.defaultValue = defaultValue;
|
|
178
159
|
}
|
|
179
160
|
set value(value) {
|
|
180
|
-
ReactiveTreeNodeImpl.
|
|
161
|
+
ReactiveTreeNodeImpl.setTreeVariableValue(this, value);
|
|
181
162
|
}
|
|
182
163
|
get value() {
|
|
183
|
-
return ReactiveTreeNodeImpl.
|
|
164
|
+
return ReactiveTreeNodeImpl.useTreeVariableValue(this);
|
|
184
165
|
}
|
|
185
166
|
get valueOrUndefined() {
|
|
186
|
-
return ReactiveTreeNodeImpl.
|
|
167
|
+
return ReactiveTreeNodeImpl.tryUseTreeVariableValue(this);
|
|
187
168
|
}
|
|
188
169
|
}
|
|
189
170
|
export function generateKey(owner) {
|
|
@@ -285,18 +266,24 @@ class ReactiveTreeNodeImpl extends ReactiveTreeNode {
|
|
|
285
266
|
if (this.has(Mode.autonomous))
|
|
286
267
|
ReactiveTreeNodeImpl.disposableNodeCount++;
|
|
287
268
|
}
|
|
288
|
-
get strictOrder() {
|
|
289
|
-
|
|
290
|
-
|
|
269
|
+
get strictOrder() {
|
|
270
|
+
return this.children.isStrict;
|
|
271
|
+
}
|
|
272
|
+
set strictOrder(value) {
|
|
273
|
+
this.children.isStrict = value;
|
|
274
|
+
}
|
|
275
|
+
get isMoved() {
|
|
276
|
+
return this.owner.children.isMoved(this.slot);
|
|
277
|
+
}
|
|
291
278
|
has(mode) {
|
|
292
279
|
return (getModeUsingBasisChain(this.declaration) & mode) === mode;
|
|
293
280
|
}
|
|
294
281
|
script(_triggers) {
|
|
295
282
|
runScriptNow(this.slot);
|
|
296
283
|
}
|
|
297
|
-
|
|
284
|
+
configureReactivity(options) {
|
|
298
285
|
if (this.stamp < Number.MAX_SAFE_INTEGER - 1 || !this.has(Mode.autonomous))
|
|
299
|
-
throw new Error("reactronic can be configured only for elements with autonomous mode and only during
|
|
286
|
+
throw new Error("reactronic can be configured only for elements with autonomous mode and only during preparation");
|
|
300
287
|
return manageReactiveOperation(this.script).configure(options);
|
|
301
288
|
}
|
|
302
289
|
static get nodeSlot() {
|
|
@@ -304,21 +291,21 @@ class ReactiveTreeNodeImpl extends ReactiveTreeNode {
|
|
|
304
291
|
throw new Error("current element is undefined");
|
|
305
292
|
return gNodeSlot;
|
|
306
293
|
}
|
|
307
|
-
static
|
|
294
|
+
static tryUseTreeVariableValue(variable) {
|
|
308
295
|
var _a, _b;
|
|
309
296
|
let node = ReactiveTreeNodeImpl.nodeSlot.instance;
|
|
310
297
|
while (((_a = node.context) === null || _a === void 0 ? void 0 : _a.variable) !== variable && node.owner !== node)
|
|
311
298
|
node = node.outer.slot.instance;
|
|
312
299
|
return (_b = node.context) === null || _b === void 0 ? void 0 : _b.value;
|
|
313
300
|
}
|
|
314
|
-
static
|
|
301
|
+
static useTreeVariableValue(variable) {
|
|
315
302
|
var _a;
|
|
316
|
-
const result = (_a = ReactiveTreeNodeImpl.
|
|
303
|
+
const result = (_a = ReactiveTreeNodeImpl.tryUseTreeVariableValue(variable)) !== null && _a !== void 0 ? _a : variable.defaultValue;
|
|
317
304
|
if (!result)
|
|
318
305
|
throw new Error("unknown node variable");
|
|
319
306
|
return result;
|
|
320
307
|
}
|
|
321
|
-
static
|
|
308
|
+
static setTreeVariableValue(variable, value) {
|
|
322
309
|
const node = ReactiveTreeNodeImpl.nodeSlot.instance;
|
|
323
310
|
const owner = node.owner;
|
|
324
311
|
const hostCtx = runNonReactively(() => { var _a; return (_a = owner.context) === null || _a === void 0 ? void 0 : _a.value; });
|
|
@@ -346,10 +333,6 @@ class ReactiveTreeNodeImpl extends ReactiveTreeNode {
|
|
|
346
333
|
ReactiveTreeNodeImpl.logging = undefined;
|
|
347
334
|
ReactiveTreeNodeImpl.grandNodeCount = 0;
|
|
348
335
|
ReactiveTreeNodeImpl.disposableNodeCount = 0;
|
|
349
|
-
ReactiveTreeNodeImpl.shortFrameDuration = 16;
|
|
350
|
-
ReactiveTreeNodeImpl.longFrameDuration = 300;
|
|
351
|
-
ReactiveTreeNodeImpl.currentScriptPriority = Priority.realtime;
|
|
352
|
-
ReactiveTreeNodeImpl.frameDuration = ReactiveTreeNodeImpl.longFrameDuration;
|
|
353
336
|
__decorate([
|
|
354
337
|
reactive,
|
|
355
338
|
options({
|
|
@@ -442,8 +425,8 @@ function runNestedScriptsIncrementally(owner, stamp, allChildren, items, priorit
|
|
|
442
425
|
try {
|
|
443
426
|
if (node.childrenShuffling)
|
|
444
427
|
shuffle(items);
|
|
445
|
-
const frameDurationLimit = priority === Priority.background ?
|
|
446
|
-
let frameDuration = Math.min(frameDurationLimit, Math.max(
|
|
428
|
+
const frameDurationLimit = priority === Priority.background ? ReactiveTreeNode.shortFrameDuration : Infinity;
|
|
429
|
+
let frameDuration = Math.min(frameDurationLimit, Math.max(ReactiveTreeNode.frameDuration / 4, ReactiveTreeNode.shortFrameDuration));
|
|
447
430
|
for (const child of items) {
|
|
448
431
|
triggerScriptRunViaSlot(child);
|
|
449
432
|
if (Transaction.isFrameOver(1, frameDuration)) {
|
|
@@ -451,9 +434,9 @@ function runNestedScriptsIncrementally(owner, stamp, allChildren, items, priorit
|
|
|
451
434
|
yield Transaction.requestNextFrame(0);
|
|
452
435
|
outerPriority = ReactiveTreeNodeImpl.currentScriptPriority;
|
|
453
436
|
ReactiveTreeNodeImpl.currentScriptPriority = priority;
|
|
454
|
-
frameDuration = Math.min(4 * frameDuration, Math.min(frameDurationLimit,
|
|
437
|
+
frameDuration = Math.min(4 * frameDuration, Math.min(frameDurationLimit, ReactiveTreeNode.frameDuration));
|
|
455
438
|
}
|
|
456
|
-
if (Transaction.isCanceled && Transaction.isFrameOver(1,
|
|
439
|
+
if (Transaction.isCanceled && Transaction.isFrameOver(1, ReactiveTreeNode.shortFrameDuration / 3))
|
|
457
440
|
break;
|
|
458
441
|
}
|
|
459
442
|
}
|