reactronic 0.24.273 → 0.24.275
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.
|
@@ -19,5 +19,5 @@ 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 { Reaction } from "./Reaction.js";
|
|
21
21
|
export { RxNode, Mode, Priority, BaseDriver, RxNodeVariable } from "./core/RxNode.js";
|
|
22
|
-
export type {
|
|
22
|
+
export type { Script, ScriptAsync, Handler, RxNodeDecl, RxNodeDriver, RxNodeContext } from "./core/RxNode.js";
|
|
23
23
|
export { Clock } from "./Clock.js";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { LoggingOptions } from "../Logging.js";
|
|
2
2
|
import { MergeListReader, MergedItem } from "../util/MergeList.js";
|
|
3
3
|
import { MemberOptions } from "../Options.js";
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
4
|
+
export type Script<T> = (el: T, basis: () => void) => void;
|
|
5
|
+
export type ScriptAsync<T> = (el: T, basis: () => Promise<void>) => Promise<void>;
|
|
6
|
+
export type Handler<T = unknown, R = void> = (el: T) => R;
|
|
6
7
|
export declare enum Mode {
|
|
7
8
|
default = 0,
|
|
8
9
|
independentUpdate = 1,
|
|
@@ -35,7 +36,7 @@ export declare abstract class RxNode<E = unknown> {
|
|
|
35
36
|
static readonly longFrameDuration = 300;
|
|
36
37
|
static currentUpdatePriority: Priority;
|
|
37
38
|
static frameDuration: number;
|
|
38
|
-
static declare<E = void>(driver: RxNodeDriver<E>, declaration?: RxNodeDecl<E>,
|
|
39
|
+
static declare<E = void>(driver: RxNodeDriver<E>, declaration?: RxNodeDecl<E>, basis?: RxNodeDecl<E>): RxNode<E>;
|
|
39
40
|
static get isFirstUpdate(): boolean;
|
|
40
41
|
static get key(): string;
|
|
41
42
|
static get stamp(): number;
|
|
@@ -48,31 +49,33 @@ export declare abstract class RxNode<E = unknown> {
|
|
|
48
49
|
static triggerDeactivation(node: RxNode<any>): void;
|
|
49
50
|
static updateNestedNodesThenDo(action: (error: unknown) => void): void;
|
|
50
51
|
static markAsMounted(node: RxNode<any>, yes: boolean): void;
|
|
51
|
-
static findMatchingHost<E = unknown, R = unknown>(node: RxNode<E>, match:
|
|
52
|
-
static findMatchingPrevSibling<E = unknown, R = unknown>(node: RxNode<E>, match:
|
|
53
|
-
static forEachChildRecursively<E = unknown>(node: RxNode<E>, action:
|
|
52
|
+
static findMatchingHost<E = unknown, R = unknown>(node: RxNode<E>, match: Handler<RxNode<E>, boolean>): RxNode<R> | undefined;
|
|
53
|
+
static findMatchingPrevSibling<E = unknown, R = unknown>(node: RxNode<E>, match: Handler<RxNode<E>, boolean>): RxNode<R> | undefined;
|
|
54
|
+
static forEachChildRecursively<E = unknown>(node: RxNode<E>, action: Handler<RxNode<E>>): void;
|
|
54
55
|
static getDefaultLoggingOptions(): LoggingOptions | undefined;
|
|
55
56
|
static setDefaultLoggingOptions(logging?: LoggingOptions): void;
|
|
56
57
|
}
|
|
57
58
|
export type RxNodeDecl<E = unknown> = {
|
|
58
|
-
script?:
|
|
59
|
+
script?: Script<E>;
|
|
60
|
+
scriptAsync?: ScriptAsync<E>;
|
|
59
61
|
key?: string;
|
|
60
62
|
mode?: Mode;
|
|
61
|
-
creation?:
|
|
62
|
-
destruction?:
|
|
63
|
+
creation?: Script<E>;
|
|
64
|
+
destruction?: Script<E>;
|
|
63
65
|
triggers?: unknown;
|
|
64
|
-
|
|
66
|
+
basis?: RxNodeDecl<E>;
|
|
65
67
|
};
|
|
66
68
|
export type RxNodeDriver<E = unknown> = {
|
|
67
69
|
readonly name: string;
|
|
68
70
|
readonly isPartition: boolean;
|
|
69
|
-
readonly
|
|
71
|
+
readonly initialize?: Handler<E>;
|
|
70
72
|
allocate(node: RxNode<E>): E;
|
|
71
73
|
create(node: RxNode<E>): void;
|
|
72
74
|
destroy(node: RxNode<E>, isLeader: boolean): boolean;
|
|
73
75
|
mount(node: RxNode<E>): void;
|
|
74
76
|
update(node: RxNode<E>): void | Promise<void>;
|
|
75
|
-
child(ownerNode: RxNode<E>, childDriver: RxNodeDriver<any>, childDeclaration?: RxNodeDecl<any>,
|
|
77
|
+
child(ownerNode: RxNode<E>, childDriver: RxNodeDriver<any>, childDeclaration?: RxNodeDecl<any>, childBasis?: RxNodeDecl<any>): MergedItem<RxNode> | undefined;
|
|
78
|
+
getHost(node: RxNode<E>): RxNode<E>;
|
|
76
79
|
};
|
|
77
80
|
export type RxNodeContext<T extends Object = Object> = {
|
|
78
81
|
value: T;
|
|
@@ -80,14 +83,15 @@ export type RxNodeContext<T extends Object = Object> = {
|
|
|
80
83
|
export declare abstract class BaseDriver<E = unknown> implements RxNodeDriver<E> {
|
|
81
84
|
readonly name: string;
|
|
82
85
|
readonly isPartition: boolean;
|
|
83
|
-
readonly
|
|
84
|
-
constructor(name: string, isPartition: boolean,
|
|
86
|
+
readonly initialize?: Handler<E, void> | undefined;
|
|
87
|
+
constructor(name: string, isPartition: boolean, initialize?: Handler<E, void> | undefined);
|
|
85
88
|
abstract allocate(node: RxNode<E>): E;
|
|
86
89
|
create(node: RxNode<E>): void;
|
|
87
90
|
destroy(node: RxNode<E>, isLeader: boolean): boolean;
|
|
88
91
|
mount(node: RxNode<E>): void;
|
|
89
92
|
update(node: RxNode<E>): void | Promise<void>;
|
|
90
|
-
child(ownerNode: RxNode<E>, childDriver: RxNodeDriver<any>, childDeclaration?: RxNodeDecl<any>,
|
|
93
|
+
child(ownerNode: RxNode<E>, childDriver: RxNodeDriver<any>, childDeclaration?: RxNodeDecl<any>, childBasis?: RxNodeDecl<any>): MergedItem<RxNode> | undefined;
|
|
94
|
+
getHost(node: RxNode<E>): RxNode<E>;
|
|
91
95
|
}
|
|
92
96
|
export declare class RxNodeVariable<T extends Object = Object> {
|
|
93
97
|
readonly defaultValue: T | undefined;
|
|
@@ -35,16 +35,16 @@ export var Priority;
|
|
|
35
35
|
Priority[Priority["background"] = 2] = "background";
|
|
36
36
|
})(Priority || (Priority = {}));
|
|
37
37
|
export class RxNode {
|
|
38
|
-
static declare(driver, declaration,
|
|
38
|
+
static declare(driver, declaration, basis) {
|
|
39
39
|
let result;
|
|
40
40
|
if (declaration)
|
|
41
|
-
declaration.
|
|
41
|
+
declaration.basis = basis;
|
|
42
42
|
else
|
|
43
|
-
declaration =
|
|
43
|
+
declaration = basis !== null && basis !== void 0 ? basis : {};
|
|
44
44
|
let key = declaration.key;
|
|
45
45
|
const owner = gOwnSeat === null || gOwnSeat === void 0 ? void 0 : gOwnSeat.instance;
|
|
46
46
|
if (owner) {
|
|
47
|
-
let existing = owner.driver.child(owner, driver, declaration,
|
|
47
|
+
let existing = owner.driver.child(owner, driver, declaration, basis);
|
|
48
48
|
const children = owner.children;
|
|
49
49
|
existing !== null && existing !== void 0 ? existing : (existing = children.tryMergeAsExisting(key = key || generateKey(owner), undefined, "nested elements can be declared inside update function only"));
|
|
50
50
|
if (existing) {
|
|
@@ -144,28 +144,31 @@ RxNode.longFrameDuration = 300;
|
|
|
144
144
|
RxNode.currentUpdatePriority = Priority.realtime;
|
|
145
145
|
RxNode.frameDuration = RxNode.longFrameDuration;
|
|
146
146
|
export class BaseDriver {
|
|
147
|
-
constructor(name, isPartition,
|
|
147
|
+
constructor(name, isPartition, initialize) {
|
|
148
148
|
this.name = name;
|
|
149
149
|
this.isPartition = isPartition;
|
|
150
|
-
this.
|
|
150
|
+
this.initialize = initialize;
|
|
151
151
|
}
|
|
152
152
|
create(node) {
|
|
153
153
|
var _a;
|
|
154
|
-
(_a = this.
|
|
155
|
-
|
|
154
|
+
(_a = this.initialize) === null || _a === void 0 ? void 0 : _a.call(this, node.element);
|
|
155
|
+
invokeCreationUsingBasisChain(node.element, node.declaration);
|
|
156
156
|
}
|
|
157
157
|
destroy(node, isLeader) {
|
|
158
|
-
|
|
158
|
+
invokeDestructionUsingBasisChain(node.element, node.declaration);
|
|
159
159
|
return isLeader;
|
|
160
160
|
}
|
|
161
161
|
mount(node) {
|
|
162
162
|
}
|
|
163
163
|
update(node) {
|
|
164
|
-
|
|
164
|
+
invokeScriptUsingBasisChain(node.element, node.declaration);
|
|
165
165
|
}
|
|
166
|
-
child(ownerNode, childDriver, childDeclaration,
|
|
166
|
+
child(ownerNode, childDriver, childDeclaration, childBasis) {
|
|
167
167
|
return undefined;
|
|
168
168
|
}
|
|
169
|
+
getHost(node) {
|
|
170
|
+
return node;
|
|
171
|
+
}
|
|
169
172
|
}
|
|
170
173
|
export class RxNodeVariable {
|
|
171
174
|
constructor(defaultValue) {
|
|
@@ -191,33 +194,33 @@ function generateKey(owner) {
|
|
|
191
194
|
result = `·${lettered}`;
|
|
192
195
|
return result;
|
|
193
196
|
}
|
|
194
|
-
function
|
|
197
|
+
function getModeUsingBasisChain(declaration) {
|
|
195
198
|
var _a;
|
|
196
|
-
return (_a = declaration === null || declaration === void 0 ? void 0 : declaration.mode) !== null && _a !== void 0 ? _a : ((declaration === null || declaration === void 0 ? void 0 : declaration.
|
|
197
|
-
}
|
|
198
|
-
function invokeOnCreateViaPresetChain(element, declaration) {
|
|
199
|
-
const preset = declaration.preset;
|
|
200
|
-
const creation = declaration.creation;
|
|
201
|
-
if (creation)
|
|
202
|
-
creation(element, preset ? () => invokeOnCreateViaPresetChain(element, preset) : NOP);
|
|
203
|
-
else if (preset)
|
|
204
|
-
invokeOnCreateViaPresetChain(element, preset);
|
|
199
|
+
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);
|
|
205
200
|
}
|
|
206
|
-
function
|
|
207
|
-
const
|
|
201
|
+
function invokeScriptUsingBasisChain(element, declaration) {
|
|
202
|
+
const basis = declaration.basis;
|
|
208
203
|
const script = declaration.script;
|
|
209
204
|
if (script)
|
|
210
|
-
script(element,
|
|
211
|
-
else if (
|
|
212
|
-
|
|
205
|
+
script(element, basis ? () => invokeScriptUsingBasisChain(element, basis) : NOP);
|
|
206
|
+
else if (basis)
|
|
207
|
+
invokeScriptUsingBasisChain(element, basis);
|
|
208
|
+
}
|
|
209
|
+
function invokeCreationUsingBasisChain(element, declaration) {
|
|
210
|
+
const basis = declaration.basis;
|
|
211
|
+
const creation = declaration.creation;
|
|
212
|
+
if (creation)
|
|
213
|
+
creation(element, basis ? () => invokeCreationUsingBasisChain(element, basis) : NOP);
|
|
214
|
+
else if (basis)
|
|
215
|
+
invokeCreationUsingBasisChain(element, basis);
|
|
213
216
|
}
|
|
214
|
-
function
|
|
215
|
-
const
|
|
217
|
+
function invokeDestructionUsingBasisChain(element, declaration) {
|
|
218
|
+
const basis = declaration.basis;
|
|
216
219
|
const destruction = declaration.destruction;
|
|
217
220
|
if (destruction)
|
|
218
|
-
destruction(element,
|
|
219
|
-
else if (
|
|
220
|
-
|
|
221
|
+
destruction(element, basis ? () => invokeDestructionUsingBasisChain(element, basis) : NOP);
|
|
222
|
+
else if (basis)
|
|
223
|
+
invokeDestructionUsingBasisChain(element, basis);
|
|
221
224
|
}
|
|
222
225
|
class RxNodeContextImpl extends ObservableObject {
|
|
223
226
|
constructor(variable, value) {
|
|
@@ -270,7 +273,7 @@ class RxNodeImpl extends RxNode {
|
|
|
270
273
|
set strictOrder(value) { this.children.isStrict = value; }
|
|
271
274
|
get isMoved() { return this.owner.children.isMoved(this.seat); }
|
|
272
275
|
has(mode) {
|
|
273
|
-
return (
|
|
276
|
+
return (getModeUsingBasisChain(this.declaration) & mode) === mode;
|
|
274
277
|
}
|
|
275
278
|
update(_triggers) {
|
|
276
279
|
updateNow(this.seat);
|