reactronic 0.94.25028 → 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.
- package/build/dist/source/api.d.ts +0 -1
- package/build/dist/source/api.js +0 -1
- package/build/dist/source/core/TreeNode.d.ts +25 -16
- package/build/dist/source/core/TreeNode.js +119 -37
- package/package.json +1 -1
- package/build/dist/source/core/Tree.d.ts +0 -19
- package/build/dist/source/core/Tree.js +0 -99
|
@@ -21,5 +21,4 @@ export { runAtomically, runNonReactively, runSensitively, runContextually, manag
|
|
|
21
21
|
export { ReactiveSystem, observable, atomic, reactive, cached, options } from "./System.js";
|
|
22
22
|
export { ReactiveOperationEx } from "./OperationEx.js";
|
|
23
23
|
export { ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
|
|
24
|
-
export { ReactiveTree } from "./core/Tree.js";
|
|
25
24
|
export type { Script, ScriptAsync, Handler, ReactiveTreeNodeDecl, ReactiveTreeNodeDriver, ReactiveTreeNodeContext } from "./core/TreeNode.js";
|
package/build/dist/source/api.js
CHANGED
|
@@ -17,4 +17,3 @@ export { runAtomically, runNonReactively, runSensitively, runContextually, manag
|
|
|
17
17
|
export { ReactiveSystem, observable, atomic, reactive, cached, options } from "./System.js";
|
|
18
18
|
export { ReactiveOperationEx } from "./OperationEx.js";
|
|
19
19
|
export { ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
|
|
20
|
-
export { ReactiveTree } from "./core/Tree.js";
|
|
@@ -7,6 +7,10 @@ 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
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;
|
|
10
14
|
abstract readonly key: string;
|
|
11
15
|
abstract readonly driver: ReactiveTreeNodeDriver<E>;
|
|
12
16
|
abstract readonly declaration: Readonly<ReactiveTreeNodeDecl<E>>;
|
|
@@ -23,14 +27,22 @@ export declare abstract class ReactiveTreeNode<E = unknown> {
|
|
|
23
27
|
abstract childrenShuffling: boolean;
|
|
24
28
|
abstract strictOrder: boolean;
|
|
25
29
|
abstract has(mode: Mode): boolean;
|
|
26
|
-
abstract
|
|
27
|
-
static get
|
|
28
|
-
static get
|
|
29
|
-
static
|
|
30
|
-
static
|
|
31
|
-
static
|
|
32
|
-
static
|
|
33
|
-
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;
|
|
34
46
|
}
|
|
35
47
|
export type ReactiveTreeNodeDecl<E = unknown> = {
|
|
36
48
|
script?: Script<E>;
|
|
@@ -79,6 +91,7 @@ export declare class ReactiveTreeVariable<T extends Object = Object> {
|
|
|
79
91
|
get valueOrUndefined(): T | undefined;
|
|
80
92
|
}
|
|
81
93
|
export declare function generateKey(owner: ReactiveTreeNodeImpl): string;
|
|
94
|
+
export declare function getModeUsingBasisChain(declaration?: ReactiveTreeNodeDecl<any>): Mode;
|
|
82
95
|
declare class ReactiveTreeNodeContextImpl<T extends Object = Object> extends ObservableObject implements ReactiveTreeNodeContext<T> {
|
|
83
96
|
next: ReactiveTreeNodeContextImpl<object> | undefined;
|
|
84
97
|
variable: ReactiveTreeVariable<T>;
|
|
@@ -89,10 +102,6 @@ declare class ReactiveTreeNodeImpl<E = unknown> extends ReactiveTreeNode<E> {
|
|
|
89
102
|
static logging: LoggingOptions | undefined;
|
|
90
103
|
static grandNodeCount: number;
|
|
91
104
|
static disposableNodeCount: number;
|
|
92
|
-
static readonly shortFrameDuration = 16;
|
|
93
|
-
static readonly longFrameDuration = 300;
|
|
94
|
-
static currentScriptPriority: Priority;
|
|
95
|
-
static frameDuration: number;
|
|
96
105
|
readonly key: string;
|
|
97
106
|
readonly driver: ReactiveTreeNodeDriver<E>;
|
|
98
107
|
declaration: ReactiveTreeNodeDecl<E>;
|
|
@@ -114,11 +123,11 @@ declare class ReactiveTreeNodeImpl<E = unknown> extends ReactiveTreeNode<E> {
|
|
|
114
123
|
get isMoved(): boolean;
|
|
115
124
|
has(mode: Mode): boolean;
|
|
116
125
|
script(_triggers: unknown): void;
|
|
117
|
-
|
|
126
|
+
configureReactivity(options: Partial<ReactivityOptions>): ReactivityOptions;
|
|
118
127
|
static get nodeSlot(): MergedItem<ReactiveTreeNodeImpl>;
|
|
119
|
-
static
|
|
120
|
-
static
|
|
121
|
-
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;
|
|
122
131
|
}
|
|
123
132
|
export declare function observablesAreEqual(a1: any, a2: any): boolean;
|
|
124
133
|
export {};
|
|
@@ -24,28 +24,108 @@ 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
26
|
export class ReactiveTreeNode {
|
|
27
|
-
static get
|
|
28
|
-
return ReactiveTreeNodeImpl.nodeSlot.instance
|
|
29
|
-
}
|
|
30
|
-
static get
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
static
|
|
34
|
-
|
|
27
|
+
static get current() {
|
|
28
|
+
return ReactiveTreeNodeImpl.nodeSlot.instance;
|
|
29
|
+
}
|
|
30
|
+
static get isFirstScriptRun() {
|
|
31
|
+
return ReactiveTreeNode.current.stamp === 1;
|
|
32
|
+
}
|
|
33
|
+
static declare(driver, scriptOrDeclaration, scriptAsync, key, mode, preparation, preparationAsync, finalization, triggers, basis) {
|
|
34
|
+
let result;
|
|
35
|
+
let declaration;
|
|
36
|
+
if (scriptOrDeclaration instanceof Function) {
|
|
37
|
+
declaration = {
|
|
38
|
+
script: scriptOrDeclaration, scriptAsync, key, mode,
|
|
39
|
+
preparation, preparationAsync, finalization, triggers, basis,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
declaration = scriptOrDeclaration !== null && scriptOrDeclaration !== void 0 ? scriptOrDeclaration : {};
|
|
44
|
+
let effectiveKey = declaration.key;
|
|
45
|
+
const owner = (getModeUsingBasisChain(declaration) & Mode.rootNode) !== Mode.rootNode ? gNodeSlot === null || gNodeSlot === void 0 ? void 0 : gNodeSlot.instance : undefined;
|
|
46
|
+
if (owner) {
|
|
47
|
+
let existing = owner.driver.declareChild(owner, driver, declaration, declaration.basis);
|
|
48
|
+
const children = owner.children;
|
|
49
|
+
existing !== null && existing !== void 0 ? existing : (existing = children.tryMergeAsExisting(effectiveKey = effectiveKey || generateKey(owner), undefined, "nested elements can be declared inside 'script' only"));
|
|
50
|
+
if (existing) {
|
|
51
|
+
result = existing.instance;
|
|
52
|
+
if (result.driver !== driver && driver !== undefined)
|
|
53
|
+
throw new Error(`changing element driver is not yet supported: "${result.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
|
|
54
|
+
const exTriggers = result.declaration.triggers;
|
|
55
|
+
if (observablesAreEqual(declaration.triggers, exTriggers))
|
|
56
|
+
declaration.triggers = exTriggers;
|
|
57
|
+
result.declaration = declaration;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
result = new ReactiveTreeNodeImpl(effectiveKey || generateKey(owner), driver, declaration, owner);
|
|
61
|
+
result.slot = children.mergeAsAdded(result);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
result = new ReactiveTreeNodeImpl(effectiveKey || "", driver, declaration, owner);
|
|
66
|
+
result.slot = MergeList.createItem(result);
|
|
67
|
+
triggerScriptRunViaSlot(result.slot);
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
35
70
|
}
|
|
36
|
-
static
|
|
37
|
-
|
|
71
|
+
static withBasis(declaration, basis) {
|
|
72
|
+
if (declaration)
|
|
73
|
+
declaration.basis = basis;
|
|
74
|
+
else
|
|
75
|
+
declaration = basis !== null && basis !== void 0 ? basis : {};
|
|
76
|
+
return declaration;
|
|
77
|
+
}
|
|
78
|
+
static triggerScriptRun(node, triggers) {
|
|
79
|
+
const impl = node;
|
|
80
|
+
const declaration = impl.declaration;
|
|
81
|
+
if (!observablesAreEqual(triggers, declaration.triggers)) {
|
|
82
|
+
declaration.triggers = triggers;
|
|
83
|
+
triggerScriptRunViaSlot(impl.slot);
|
|
84
|
+
}
|
|
38
85
|
}
|
|
39
|
-
static
|
|
40
|
-
|
|
86
|
+
static triggerFinalization(node) {
|
|
87
|
+
const impl = node;
|
|
88
|
+
triggerFinalization(impl.slot, true, true);
|
|
89
|
+
}
|
|
90
|
+
static runNestedNodeScriptsThenDo(action) {
|
|
91
|
+
runNestedNodeScriptsThenDoImpl(ReactiveTreeNodeImpl.nodeSlot, undefined, action);
|
|
92
|
+
}
|
|
93
|
+
static markAsMounted(node, yes) {
|
|
94
|
+
const n = node;
|
|
95
|
+
if (n.stamp < 0)
|
|
96
|
+
throw new Error("deactivated node cannot be mounted or unmounted");
|
|
97
|
+
if (n.stamp >= Number.MAX_SAFE_INTEGER)
|
|
98
|
+
throw new Error("node must be activated before mounting");
|
|
99
|
+
n.stamp = yes ? 0 : Number.MAX_SAFE_INTEGER - 1;
|
|
100
|
+
}
|
|
101
|
+
static findMatchingHost(node, match) {
|
|
102
|
+
let p = node.host;
|
|
103
|
+
while (p !== p.host && !match(p))
|
|
104
|
+
p = p.host;
|
|
105
|
+
return p;
|
|
106
|
+
}
|
|
107
|
+
static findMatchingPrevSibling(node, match) {
|
|
108
|
+
let p = node.slot.prev;
|
|
109
|
+
while (p && !match(p.instance))
|
|
110
|
+
p = p.prev;
|
|
111
|
+
return p === null || p === void 0 ? void 0 : p.instance;
|
|
112
|
+
}
|
|
113
|
+
static forEachChildRecursively(node, action) {
|
|
114
|
+
action(node);
|
|
115
|
+
for (const child of node.children.items())
|
|
116
|
+
ReactiveTreeNode.forEachChildRecursively(child.instance, action);
|
|
41
117
|
}
|
|
42
|
-
static
|
|
43
|
-
return ReactiveTreeNodeImpl.
|
|
118
|
+
static getDefaultLoggingOptions() {
|
|
119
|
+
return ReactiveTreeNodeImpl.logging;
|
|
44
120
|
}
|
|
45
|
-
static
|
|
46
|
-
ReactiveTreeNodeImpl.
|
|
121
|
+
static setDefaultLoggingOptions(logging) {
|
|
122
|
+
ReactiveTreeNodeImpl.logging = logging;
|
|
47
123
|
}
|
|
48
124
|
}
|
|
125
|
+
ReactiveTreeNode.shortFrameDuration = 16;
|
|
126
|
+
ReactiveTreeNode.longFrameDuration = 300;
|
|
127
|
+
ReactiveTreeNode.frameDuration = ReactiveTreeNode.longFrameDuration;
|
|
128
|
+
ReactiveTreeNode.currentScriptPriority = Priority.realtime;
|
|
49
129
|
export class BaseDriver {
|
|
50
130
|
constructor(name, isPartition, initialize) {
|
|
51
131
|
this.name = name;
|
|
@@ -78,13 +158,13 @@ export class ReactiveTreeVariable {
|
|
|
78
158
|
this.defaultValue = defaultValue;
|
|
79
159
|
}
|
|
80
160
|
set value(value) {
|
|
81
|
-
ReactiveTreeNodeImpl.
|
|
161
|
+
ReactiveTreeNodeImpl.setTreeVariableValue(this, value);
|
|
82
162
|
}
|
|
83
163
|
get value() {
|
|
84
|
-
return ReactiveTreeNodeImpl.
|
|
164
|
+
return ReactiveTreeNodeImpl.useTreeVariableValue(this);
|
|
85
165
|
}
|
|
86
166
|
get valueOrUndefined() {
|
|
87
|
-
return ReactiveTreeNodeImpl.
|
|
167
|
+
return ReactiveTreeNodeImpl.tryUseTreeVariableValue(this);
|
|
88
168
|
}
|
|
89
169
|
}
|
|
90
170
|
export function generateKey(owner) {
|
|
@@ -97,7 +177,7 @@ export function generateKey(owner) {
|
|
|
97
177
|
result = `·${lettered}`;
|
|
98
178
|
return result;
|
|
99
179
|
}
|
|
100
|
-
function getModeUsingBasisChain(declaration) {
|
|
180
|
+
export function getModeUsingBasisChain(declaration) {
|
|
101
181
|
var _a;
|
|
102
182
|
return (_a = declaration === null || declaration === void 0 ? void 0 : declaration.mode) !== null && _a !== void 0 ? _a : ((declaration === null || declaration === void 0 ? void 0 : declaration.basis) ? getModeUsingBasisChain(declaration === null || declaration === void 0 ? void 0 : declaration.basis) : Mode.default);
|
|
103
183
|
}
|
|
@@ -186,18 +266,24 @@ class ReactiveTreeNodeImpl extends ReactiveTreeNode {
|
|
|
186
266
|
if (this.has(Mode.autonomous))
|
|
187
267
|
ReactiveTreeNodeImpl.disposableNodeCount++;
|
|
188
268
|
}
|
|
189
|
-
get strictOrder() {
|
|
190
|
-
|
|
191
|
-
|
|
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
|
+
}
|
|
192
278
|
has(mode) {
|
|
193
279
|
return (getModeUsingBasisChain(this.declaration) & mode) === mode;
|
|
194
280
|
}
|
|
195
281
|
script(_triggers) {
|
|
196
282
|
runScriptNow(this.slot);
|
|
197
283
|
}
|
|
198
|
-
|
|
284
|
+
configureReactivity(options) {
|
|
199
285
|
if (this.stamp < Number.MAX_SAFE_INTEGER - 1 || !this.has(Mode.autonomous))
|
|
200
|
-
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");
|
|
201
287
|
return manageReactiveOperation(this.script).configure(options);
|
|
202
288
|
}
|
|
203
289
|
static get nodeSlot() {
|
|
@@ -205,21 +291,21 @@ class ReactiveTreeNodeImpl extends ReactiveTreeNode {
|
|
|
205
291
|
throw new Error("current element is undefined");
|
|
206
292
|
return gNodeSlot;
|
|
207
293
|
}
|
|
208
|
-
static
|
|
294
|
+
static tryUseTreeVariableValue(variable) {
|
|
209
295
|
var _a, _b;
|
|
210
296
|
let node = ReactiveTreeNodeImpl.nodeSlot.instance;
|
|
211
297
|
while (((_a = node.context) === null || _a === void 0 ? void 0 : _a.variable) !== variable && node.owner !== node)
|
|
212
298
|
node = node.outer.slot.instance;
|
|
213
299
|
return (_b = node.context) === null || _b === void 0 ? void 0 : _b.value;
|
|
214
300
|
}
|
|
215
|
-
static
|
|
301
|
+
static useTreeVariableValue(variable) {
|
|
216
302
|
var _a;
|
|
217
|
-
const result = (_a = ReactiveTreeNodeImpl.
|
|
303
|
+
const result = (_a = ReactiveTreeNodeImpl.tryUseTreeVariableValue(variable)) !== null && _a !== void 0 ? _a : variable.defaultValue;
|
|
218
304
|
if (!result)
|
|
219
305
|
throw new Error("unknown node variable");
|
|
220
306
|
return result;
|
|
221
307
|
}
|
|
222
|
-
static
|
|
308
|
+
static setTreeVariableValue(variable, value) {
|
|
223
309
|
const node = ReactiveTreeNodeImpl.nodeSlot.instance;
|
|
224
310
|
const owner = node.owner;
|
|
225
311
|
const hostCtx = runNonReactively(() => { var _a; return (_a = owner.context) === null || _a === void 0 ? void 0 : _a.value; });
|
|
@@ -247,10 +333,6 @@ class ReactiveTreeNodeImpl extends ReactiveTreeNode {
|
|
|
247
333
|
ReactiveTreeNodeImpl.logging = undefined;
|
|
248
334
|
ReactiveTreeNodeImpl.grandNodeCount = 0;
|
|
249
335
|
ReactiveTreeNodeImpl.disposableNodeCount = 0;
|
|
250
|
-
ReactiveTreeNodeImpl.shortFrameDuration = 16;
|
|
251
|
-
ReactiveTreeNodeImpl.longFrameDuration = 300;
|
|
252
|
-
ReactiveTreeNodeImpl.currentScriptPriority = Priority.realtime;
|
|
253
|
-
ReactiveTreeNodeImpl.frameDuration = ReactiveTreeNodeImpl.longFrameDuration;
|
|
254
336
|
__decorate([
|
|
255
337
|
reactive,
|
|
256
338
|
options({
|
|
@@ -343,8 +425,8 @@ function runNestedScriptsIncrementally(owner, stamp, allChildren, items, priorit
|
|
|
343
425
|
try {
|
|
344
426
|
if (node.childrenShuffling)
|
|
345
427
|
shuffle(items);
|
|
346
|
-
const frameDurationLimit = priority === Priority.background ?
|
|
347
|
-
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));
|
|
348
430
|
for (const child of items) {
|
|
349
431
|
triggerScriptRunViaSlot(child);
|
|
350
432
|
if (Transaction.isFrameOver(1, frameDuration)) {
|
|
@@ -352,9 +434,9 @@ function runNestedScriptsIncrementally(owner, stamp, allChildren, items, priorit
|
|
|
352
434
|
yield Transaction.requestNextFrame(0);
|
|
353
435
|
outerPriority = ReactiveTreeNodeImpl.currentScriptPriority;
|
|
354
436
|
ReactiveTreeNodeImpl.currentScriptPriority = priority;
|
|
355
|
-
frameDuration = Math.min(4 * frameDuration, Math.min(frameDurationLimit,
|
|
437
|
+
frameDuration = Math.min(4 * frameDuration, Math.min(frameDurationLimit, ReactiveTreeNode.frameDuration));
|
|
356
438
|
}
|
|
357
|
-
if (Transaction.isCanceled && Transaction.isFrameOver(1,
|
|
439
|
+
if (Transaction.isCanceled && Transaction.isFrameOver(1, ReactiveTreeNode.shortFrameDuration / 3))
|
|
358
440
|
break;
|
|
359
441
|
}
|
|
360
442
|
}
|
package/package.json
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Mode } from "../Enums.js";
|
|
2
|
-
import { ReactiveTreeNodeDriver, ReactiveTreeNodeDecl, Script, ScriptAsync, Handler, ReactiveTreeNode } from "./TreeNode.js";
|
|
3
|
-
import { LoggingOptions } from "../Logging.js";
|
|
4
|
-
export declare class ReactiveTree {
|
|
5
|
-
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>;
|
|
6
|
-
static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, declaration?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
7
|
-
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>;
|
|
8
|
-
static withBasis<E = void>(declaration?: ReactiveTreeNodeDecl<E>, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNodeDecl<E>;
|
|
9
|
-
static get isFirstScriptRun(): boolean;
|
|
10
|
-
static triggerScriptRun(node: ReactiveTreeNode<any>, triggers: unknown): void;
|
|
11
|
-
static triggerFinalization(node: ReactiveTreeNode<any>): void;
|
|
12
|
-
static runNestedNodeScriptsThenDo(action: (error: unknown) => void): void;
|
|
13
|
-
static markAsMounted(node: ReactiveTreeNode<any>, yes: boolean): void;
|
|
14
|
-
static findMatchingHost<E = unknown, R = unknown>(node: ReactiveTreeNode<E>, match: Handler<ReactiveTreeNode<E>, boolean>): ReactiveTreeNode<R> | undefined;
|
|
15
|
-
static findMatchingPrevSibling<E = unknown, R = unknown>(node: ReactiveTreeNode<E>, match: Handler<ReactiveTreeNode<E>, boolean>): ReactiveTreeNode<R> | undefined;
|
|
16
|
-
static forEachChildRecursively<E = unknown>(node: ReactiveTreeNode<E>, action: Handler<ReactiveTreeNode<E>>): void;
|
|
17
|
-
static getDefaultLoggingOptions(): LoggingOptions | undefined;
|
|
18
|
-
static setDefaultLoggingOptions(logging?: LoggingOptions): void;
|
|
19
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Mode } from "../Enums.js";
|
|
2
|
-
import { generateKey, observablesAreEqual } from "./TreeNode.js";
|
|
3
|
-
import { MergeList } from "../util/MergeList.js";
|
|
4
|
-
export class ReactiveTree {
|
|
5
|
-
static declare(driver, scriptOrDeclaration, scriptAsync, key, mode, preparation, preparationAsync, finalization, triggers, basis) {
|
|
6
|
-
let result;
|
|
7
|
-
let declaration;
|
|
8
|
-
if (scriptOrDeclaration instanceof Function) {
|
|
9
|
-
declaration = {
|
|
10
|
-
script: scriptOrDeclaration, scriptAsync, key, mode,
|
|
11
|
-
preparation, preparationAsync, finalization, triggers, basis,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
else
|
|
15
|
-
declaration = scriptOrDeclaration !== null && scriptOrDeclaration !== void 0 ? scriptOrDeclaration : {};
|
|
16
|
-
let effectiveKey = declaration.key;
|
|
17
|
-
const owner = (getModeUsingBasisChain(declaration) & Mode.rootNode) !== Mode.rootNode ? gNodeSlot === null || gNodeSlot === void 0 ? void 0 : gNodeSlot.instance : undefined;
|
|
18
|
-
if (owner) {
|
|
19
|
-
let existing = owner.driver.declareChild(owner, driver, declaration, declaration.basis);
|
|
20
|
-
const children = owner.children;
|
|
21
|
-
existing !== null && existing !== void 0 ? existing : (existing = children.tryMergeAsExisting(effectiveKey = effectiveKey || generateKey(owner), undefined, "nested elements can be declared inside 'script' only"));
|
|
22
|
-
if (existing) {
|
|
23
|
-
result = existing.instance;
|
|
24
|
-
if (result.driver !== driver && driver !== undefined)
|
|
25
|
-
throw new Error(`changing element driver is not yet supported: "${result.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
|
|
26
|
-
const exTriggers = result.declaration.triggers;
|
|
27
|
-
if (observablesAreEqual(declaration.triggers, exTriggers))
|
|
28
|
-
declaration.triggers = exTriggers;
|
|
29
|
-
result.declaration = declaration;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
result = new ReactiveTreeNodeImpl(effectiveKey || generateKey(owner), driver, declaration, owner);
|
|
33
|
-
result.slot = children.mergeAsAdded(result);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
result = new ReactiveTreeNodeImpl(effectiveKey || "", driver, declaration, owner);
|
|
38
|
-
result.slot = MergeList.createItem(result);
|
|
39
|
-
triggerScriptRunViaSlot(result.slot);
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
static withBasis(declaration, basis) {
|
|
44
|
-
if (declaration)
|
|
45
|
-
declaration.basis = basis;
|
|
46
|
-
else
|
|
47
|
-
declaration = basis !== null && basis !== void 0 ? basis : {};
|
|
48
|
-
return declaration;
|
|
49
|
-
}
|
|
50
|
-
static get isFirstScriptRun() {
|
|
51
|
-
return ReactiveTreeNodeImpl.nodeSlot.instance.stamp === 1;
|
|
52
|
-
}
|
|
53
|
-
static triggerScriptRun(node, triggers) {
|
|
54
|
-
const impl = node;
|
|
55
|
-
const declaration = impl.declaration;
|
|
56
|
-
if (!observablesAreEqual(triggers, declaration.triggers)) {
|
|
57
|
-
declaration.triggers = triggers;
|
|
58
|
-
triggerScriptRunViaSlot(impl.slot);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
static triggerFinalization(node) {
|
|
62
|
-
const impl = node;
|
|
63
|
-
triggerFinalization(impl.slot, true, true);
|
|
64
|
-
}
|
|
65
|
-
static runNestedNodeScriptsThenDo(action) {
|
|
66
|
-
runNestedNodeScriptsThenDoImpl(ReactiveTreeNodeImpl.nodeSlot, undefined, action);
|
|
67
|
-
}
|
|
68
|
-
static markAsMounted(node, yes) {
|
|
69
|
-
const n = node;
|
|
70
|
-
if (n.stamp < 0)
|
|
71
|
-
throw new Error("deactivated node cannot be mounted or unmounted");
|
|
72
|
-
if (n.stamp >= Number.MAX_SAFE_INTEGER)
|
|
73
|
-
throw new Error("node must be activated before mounting");
|
|
74
|
-
n.stamp = yes ? 0 : Number.MAX_SAFE_INTEGER - 1;
|
|
75
|
-
}
|
|
76
|
-
static findMatchingHost(node, match) {
|
|
77
|
-
let p = node.host;
|
|
78
|
-
while (p !== p.host && !match(p))
|
|
79
|
-
p = p.host;
|
|
80
|
-
return p;
|
|
81
|
-
}
|
|
82
|
-
static findMatchingPrevSibling(node, match) {
|
|
83
|
-
let p = node.slot.prev;
|
|
84
|
-
while (p && !match(p.instance))
|
|
85
|
-
p = p.prev;
|
|
86
|
-
return p === null || p === void 0 ? void 0 : p.instance;
|
|
87
|
-
}
|
|
88
|
-
static forEachChildRecursively(node, action) {
|
|
89
|
-
action(node);
|
|
90
|
-
for (const child of node.children.items())
|
|
91
|
-
ReactiveTree.forEachChildRecursively(child.instance, action);
|
|
92
|
-
}
|
|
93
|
-
static getDefaultLoggingOptions() {
|
|
94
|
-
return ReactiveTreeNodeImpl.logging;
|
|
95
|
-
}
|
|
96
|
-
static setDefaultLoggingOptions(logging) {
|
|
97
|
-
ReactiveTreeNodeImpl.logging = logging;
|
|
98
|
-
}
|
|
99
|
-
}
|