reactronic 0.94.25028 → 0.94.25029
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 +1 -2
- package/build/dist/source/api.js +1 -2
- package/build/dist/source/core/TreeNode.d.ts +18 -0
- package/build/dist/source/core/TreeNode.js +100 -1
- package/package.json +1 -1
- package/build/dist/source/core/Tree.d.ts +0 -19
- package/build/dist/source/core/Tree.js +0 -99
|
@@ -20,6 +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 { ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
|
|
24
|
-
export { ReactiveTree } from "./core/Tree.js";
|
|
23
|
+
export { ReactiveTree, ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
|
|
25
24
|
export type { Script, ScriptAsync, Handler, ReactiveTreeNodeDecl, ReactiveTreeNodeDriver, ReactiveTreeNodeContext } from "./core/TreeNode.js";
|
package/build/dist/source/api.js
CHANGED
|
@@ -16,5 +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 { ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
|
|
20
|
-
export { ReactiveTree } from "./core/Tree.js";
|
|
19
|
+
export { ReactiveTree, ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
|
|
@@ -6,6 +6,22 @@ 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
|
+
}
|
|
9
25
|
export declare abstract class ReactiveTreeNode<E = unknown> {
|
|
10
26
|
abstract readonly key: string;
|
|
11
27
|
abstract readonly driver: ReactiveTreeNodeDriver<E>;
|
|
@@ -31,6 +47,7 @@ export declare abstract class ReactiveTreeNode<E = unknown> {
|
|
|
31
47
|
static set priority(value: Priority);
|
|
32
48
|
static get childrenShuffling(): boolean;
|
|
33
49
|
static set childrenShuffling(value: boolean);
|
|
50
|
+
static get effectiveScriptPriority(): Priority;
|
|
34
51
|
}
|
|
35
52
|
export type ReactiveTreeNodeDecl<E = unknown> = {
|
|
36
53
|
script?: Script<E>;
|
|
@@ -79,6 +96,7 @@ export declare class ReactiveTreeVariable<T extends Object = Object> {
|
|
|
79
96
|
get valueOrUndefined(): T | undefined;
|
|
80
97
|
}
|
|
81
98
|
export declare function generateKey(owner: ReactiveTreeNodeImpl): string;
|
|
99
|
+
export declare function getModeUsingBasisChain(declaration?: ReactiveTreeNodeDecl<any>): Mode;
|
|
82
100
|
declare class ReactiveTreeNodeContextImpl<T extends Object = Object> extends ObservableObject implements ReactiveTreeNodeContext<T> {
|
|
83
101
|
next: ReactiveTreeNodeContextImpl<object> | undefined;
|
|
84
102
|
variable: ReactiveTreeVariable<T>;
|
|
@@ -23,6 +23,102 @@ 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 ReactiveTree {
|
|
27
|
+
static declare(driver, scriptOrDeclaration, scriptAsync, key, mode, preparation, preparationAsync, finalization, triggers, basis) {
|
|
28
|
+
let result;
|
|
29
|
+
let declaration;
|
|
30
|
+
if (scriptOrDeclaration instanceof Function) {
|
|
31
|
+
declaration = {
|
|
32
|
+
script: scriptOrDeclaration, scriptAsync, key, mode,
|
|
33
|
+
preparation, preparationAsync, finalization, triggers, basis,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
declaration = scriptOrDeclaration !== null && scriptOrDeclaration !== void 0 ? scriptOrDeclaration : {};
|
|
38
|
+
let effectiveKey = declaration.key;
|
|
39
|
+
const owner = (getModeUsingBasisChain(declaration) & Mode.rootNode) !== Mode.rootNode ? gNodeSlot === null || gNodeSlot === void 0 ? void 0 : gNodeSlot.instance : undefined;
|
|
40
|
+
if (owner) {
|
|
41
|
+
let existing = owner.driver.declareChild(owner, driver, declaration, declaration.basis);
|
|
42
|
+
const children = owner.children;
|
|
43
|
+
existing !== null && existing !== void 0 ? existing : (existing = children.tryMergeAsExisting(effectiveKey = effectiveKey || generateKey(owner), undefined, "nested elements can be declared inside 'script' only"));
|
|
44
|
+
if (existing) {
|
|
45
|
+
result = existing.instance;
|
|
46
|
+
if (result.driver !== driver && driver !== undefined)
|
|
47
|
+
throw new Error(`changing element driver is not yet supported: "${result.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
|
|
48
|
+
const exTriggers = result.declaration.triggers;
|
|
49
|
+
if (observablesAreEqual(declaration.triggers, exTriggers))
|
|
50
|
+
declaration.triggers = exTriggers;
|
|
51
|
+
result.declaration = declaration;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
result = new ReactiveTreeNodeImpl(effectiveKey || generateKey(owner), driver, declaration, owner);
|
|
55
|
+
result.slot = children.mergeAsAdded(result);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
result = new ReactiveTreeNodeImpl(effectiveKey || "", driver, declaration, owner);
|
|
60
|
+
result.slot = MergeList.createItem(result);
|
|
61
|
+
triggerScriptRunViaSlot(result.slot);
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
static withBasis(declaration, basis) {
|
|
66
|
+
if (declaration)
|
|
67
|
+
declaration.basis = basis;
|
|
68
|
+
else
|
|
69
|
+
declaration = basis !== null && basis !== void 0 ? basis : {};
|
|
70
|
+
return declaration;
|
|
71
|
+
}
|
|
72
|
+
static get isFirstScriptRun() {
|
|
73
|
+
return ReactiveTreeNodeImpl.nodeSlot.instance.stamp === 1;
|
|
74
|
+
}
|
|
75
|
+
static triggerScriptRun(node, triggers) {
|
|
76
|
+
const impl = node;
|
|
77
|
+
const declaration = impl.declaration;
|
|
78
|
+
if (!observablesAreEqual(triggers, declaration.triggers)) {
|
|
79
|
+
declaration.triggers = triggers;
|
|
80
|
+
triggerScriptRunViaSlot(impl.slot);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
static triggerFinalization(node) {
|
|
84
|
+
const impl = node;
|
|
85
|
+
triggerFinalization(impl.slot, true, true);
|
|
86
|
+
}
|
|
87
|
+
static runNestedNodeScriptsThenDo(action) {
|
|
88
|
+
runNestedNodeScriptsThenDoImpl(ReactiveTreeNodeImpl.nodeSlot, undefined, action);
|
|
89
|
+
}
|
|
90
|
+
static markAsMounted(node, yes) {
|
|
91
|
+
const n = node;
|
|
92
|
+
if (n.stamp < 0)
|
|
93
|
+
throw new Error("deactivated node cannot be mounted or unmounted");
|
|
94
|
+
if (n.stamp >= Number.MAX_SAFE_INTEGER)
|
|
95
|
+
throw new Error("node must be activated before mounting");
|
|
96
|
+
n.stamp = yes ? 0 : Number.MAX_SAFE_INTEGER - 1;
|
|
97
|
+
}
|
|
98
|
+
static findMatchingHost(node, match) {
|
|
99
|
+
let p = node.host;
|
|
100
|
+
while (p !== p.host && !match(p))
|
|
101
|
+
p = p.host;
|
|
102
|
+
return p;
|
|
103
|
+
}
|
|
104
|
+
static findMatchingPrevSibling(node, match) {
|
|
105
|
+
let p = node.slot.prev;
|
|
106
|
+
while (p && !match(p.instance))
|
|
107
|
+
p = p.prev;
|
|
108
|
+
return p === null || p === void 0 ? void 0 : p.instance;
|
|
109
|
+
}
|
|
110
|
+
static forEachChildRecursively(node, action) {
|
|
111
|
+
action(node);
|
|
112
|
+
for (const child of node.children.items())
|
|
113
|
+
ReactiveTree.forEachChildRecursively(child.instance, action);
|
|
114
|
+
}
|
|
115
|
+
static getDefaultLoggingOptions() {
|
|
116
|
+
return ReactiveTreeNodeImpl.logging;
|
|
117
|
+
}
|
|
118
|
+
static setDefaultLoggingOptions(logging) {
|
|
119
|
+
ReactiveTreeNodeImpl.logging = logging;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
26
122
|
export class ReactiveTreeNode {
|
|
27
123
|
static get key() {
|
|
28
124
|
return ReactiveTreeNodeImpl.nodeSlot.instance.key;
|
|
@@ -45,6 +141,9 @@ export class ReactiveTreeNode {
|
|
|
45
141
|
static set childrenShuffling(value) {
|
|
46
142
|
ReactiveTreeNodeImpl.nodeSlot.instance.childrenShuffling = value;
|
|
47
143
|
}
|
|
144
|
+
static get effectiveScriptPriority() {
|
|
145
|
+
return ReactiveTreeNodeImpl.currentScriptPriority;
|
|
146
|
+
}
|
|
48
147
|
}
|
|
49
148
|
export class BaseDriver {
|
|
50
149
|
constructor(name, isPartition, initialize) {
|
|
@@ -97,7 +196,7 @@ export function generateKey(owner) {
|
|
|
97
196
|
result = `·${lettered}`;
|
|
98
197
|
return result;
|
|
99
198
|
}
|
|
100
|
-
function getModeUsingBasisChain(declaration) {
|
|
199
|
+
export function getModeUsingBasisChain(declaration) {
|
|
101
200
|
var _a;
|
|
102
201
|
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
202
|
}
|
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
|
-
}
|