reactronic 0.24.127 → 0.24.200
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.
|
@@ -1,14 +1,14 @@
|
|
|
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 Delegate<T> = (
|
|
5
|
-
export type SimpleDelegate<T = unknown, R = void> = (
|
|
4
|
+
export type Delegate<T> = (el: T, basis: () => void) => void;
|
|
5
|
+
export type SimpleDelegate<T = unknown, R = void> = (el: T) => R;
|
|
6
6
|
export declare enum Mode {
|
|
7
7
|
default = 0,
|
|
8
8
|
independentUpdate = 1,
|
|
9
9
|
manualMount = 2
|
|
10
10
|
}
|
|
11
|
-
export declare
|
|
11
|
+
export declare enum Priority {
|
|
12
12
|
realtime = 0,
|
|
13
13
|
normal = 1,
|
|
14
14
|
background = 2
|
|
@@ -45,7 +45,7 @@ export declare abstract class RxNode<E = unknown> {
|
|
|
45
45
|
static get childrenShuffling(): boolean;
|
|
46
46
|
static set childrenShuffling(value: boolean);
|
|
47
47
|
static triggerUpdate(node: RxNode<any>, triggers: unknown): void;
|
|
48
|
-
static
|
|
48
|
+
static triggerDeactivation(node: RxNode<any>): void;
|
|
49
49
|
static updateNestedNodesThenDo(action: (error: unknown) => void): void;
|
|
50
50
|
static markAsMounted(node: RxNode<any>, yes: boolean): void;
|
|
51
51
|
static findMatchingHost<E = unknown, R = unknown>(node: RxNode<E>, match: SimpleDelegate<RxNode<E>, boolean>): RxNode<R> | undefined;
|
|
@@ -55,23 +55,23 @@ export declare abstract class RxNode<E = unknown> {
|
|
|
55
55
|
static setDefaultLoggingOptions(logging?: LoggingOptions): void;
|
|
56
56
|
}
|
|
57
57
|
export type RxNodeDecl<E = unknown> = {
|
|
58
|
-
|
|
58
|
+
content?: Delegate<E>;
|
|
59
59
|
key?: string;
|
|
60
60
|
mode?: Mode;
|
|
61
|
+
activation?: Delegate<E>;
|
|
62
|
+
deactivation?: Delegate<E>;
|
|
61
63
|
triggers?: unknown;
|
|
62
|
-
|
|
63
|
-
update?: Delegate<E>;
|
|
64
|
-
finalize?: Delegate<E>;
|
|
64
|
+
preset?: RxNodeDecl<E>;
|
|
65
65
|
};
|
|
66
66
|
export type RxNodeDriver<E = unknown> = {
|
|
67
67
|
readonly name: string;
|
|
68
68
|
readonly isPartitionSeparator: boolean;
|
|
69
69
|
readonly predefine?: SimpleDelegate<E>;
|
|
70
70
|
allocate(node: RxNode<E>): E;
|
|
71
|
-
|
|
71
|
+
activate(node: RxNode<E>): void;
|
|
72
72
|
mount(node: RxNode<E>): void;
|
|
73
73
|
update(node: RxNode<E>): void | Promise<void>;
|
|
74
|
-
|
|
74
|
+
deactivate(node: RxNode<E>, isLeader: boolean): boolean;
|
|
75
75
|
};
|
|
76
76
|
export type RxNodeContext<T extends Object = Object> = {
|
|
77
77
|
value: T;
|
|
@@ -82,10 +82,10 @@ export declare abstract class BaseDriver<E = unknown> implements RxNodeDriver<E>
|
|
|
82
82
|
readonly predefine?: SimpleDelegate<E, void> | undefined;
|
|
83
83
|
constructor(name: string, isPartitionSeparator: boolean, predefine?: SimpleDelegate<E, void> | undefined);
|
|
84
84
|
abstract allocate(node: RxNode<E>): E;
|
|
85
|
-
|
|
85
|
+
activate(node: RxNode<E>): void;
|
|
86
86
|
mount(node: RxNode<E>): void;
|
|
87
87
|
update(node: RxNode<E>): void | Promise<void>;
|
|
88
|
-
|
|
88
|
+
deactivate(node: RxNode<E>, isLeader: boolean): boolean;
|
|
89
89
|
}
|
|
90
90
|
export declare class RxNodeVariable<T extends Object = Object> {
|
|
91
91
|
readonly defaultValue: T | undefined;
|
|
@@ -106,9 +106,9 @@ export class RxNode {
|
|
|
106
106
|
triggerUpdateViaSeat(impl.seat);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
static
|
|
109
|
+
static triggerDeactivation(node) {
|
|
110
110
|
const impl = node;
|
|
111
|
-
|
|
111
|
+
triggerDeactivation(impl.seat, true, true);
|
|
112
112
|
}
|
|
113
113
|
static updateNestedNodesThenDo(action) {
|
|
114
114
|
runUpdateNestedNodesThenDo(undefined, action);
|
|
@@ -116,9 +116,9 @@ export class RxNode {
|
|
|
116
116
|
static markAsMounted(node, yes) {
|
|
117
117
|
const n = node;
|
|
118
118
|
if (n.stamp < 0)
|
|
119
|
-
throw new Error("
|
|
119
|
+
throw new Error("deactivated node cannot be mounted or unmounted");
|
|
120
120
|
if (n.stamp >= Number.MAX_SAFE_INTEGER)
|
|
121
|
-
throw new Error("node must be
|
|
121
|
+
throw new Error("node must be activated before mounting");
|
|
122
122
|
n.stamp = yes ? 0 : Number.MAX_SAFE_INTEGER - 1;
|
|
123
123
|
}
|
|
124
124
|
static findMatchingHost(node, match) {
|
|
@@ -155,18 +155,18 @@ export class BaseDriver {
|
|
|
155
155
|
this.isPartitionSeparator = isPartitionSeparator;
|
|
156
156
|
this.predefine = predefine;
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
activate(node) {
|
|
159
159
|
var _a;
|
|
160
160
|
(_a = this.predefine) === null || _a === void 0 ? void 0 : _a.call(this, node.element);
|
|
161
|
-
|
|
161
|
+
activateViaPresetChain(node.element, node.declaration);
|
|
162
162
|
}
|
|
163
163
|
mount(node) {
|
|
164
164
|
}
|
|
165
165
|
update(node) {
|
|
166
166
|
updateViaPresetChain(node.element, node.declaration);
|
|
167
167
|
}
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
deactivate(node, isLeader) {
|
|
169
|
+
deactivateViaPresetChain(node.element, node.declaration);
|
|
170
170
|
return isLeader;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -198,29 +198,29 @@ function getModeViaPresetChain(declaration) {
|
|
|
198
198
|
var _a;
|
|
199
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.preset) ? getModeViaPresetChain(declaration === null || declaration === void 0 ? void 0 : declaration.preset) : Mode.default);
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function activateViaPresetChain(element, declaration) {
|
|
202
202
|
const preset = declaration.preset;
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
205
|
-
|
|
203
|
+
const activation = declaration.activation;
|
|
204
|
+
if (activation)
|
|
205
|
+
activation(element, preset ? () => activateViaPresetChain(element, preset) : NOP);
|
|
206
206
|
else if (preset)
|
|
207
|
-
|
|
207
|
+
activateViaPresetChain(element, preset);
|
|
208
208
|
}
|
|
209
209
|
function updateViaPresetChain(element, declaration) {
|
|
210
210
|
const preset = declaration.preset;
|
|
211
|
-
const
|
|
212
|
-
if (
|
|
213
|
-
|
|
211
|
+
const content = declaration.content;
|
|
212
|
+
if (content)
|
|
213
|
+
content(element, preset ? () => updateViaPresetChain(element, preset) : NOP);
|
|
214
214
|
else if (preset)
|
|
215
215
|
updateViaPresetChain(element, preset);
|
|
216
216
|
}
|
|
217
|
-
function
|
|
217
|
+
function deactivateViaPresetChain(element, declaration) {
|
|
218
218
|
const preset = declaration.preset;
|
|
219
|
-
const
|
|
220
|
-
if (
|
|
221
|
-
|
|
219
|
+
const deactivation = declaration.deactivation;
|
|
220
|
+
if (deactivation)
|
|
221
|
+
deactivation(element, preset ? () => deactivateViaPresetChain(element, preset) : NOP);
|
|
222
222
|
else if (preset)
|
|
223
|
-
|
|
223
|
+
deactivateViaPresetChain(element, preset);
|
|
224
224
|
}
|
|
225
225
|
class RxNodeContextImpl extends ObservableObject {
|
|
226
226
|
constructor(variable, value) {
|
|
@@ -280,7 +280,7 @@ class RxNodeImpl extends RxNode {
|
|
|
280
280
|
}
|
|
281
281
|
configureReactronic(options) {
|
|
282
282
|
if (this.stamp < Number.MAX_SAFE_INTEGER - 1 || !this.has(Mode.independentUpdate))
|
|
283
|
-
throw new Error("reactronic can be configured only for elements with independent update mode and only
|
|
283
|
+
throw new Error("reactronic can be configured only for elements with independent update mode and only during activation");
|
|
284
284
|
return RxSystem.getReaction(this.update).configure(options);
|
|
285
285
|
}
|
|
286
286
|
static get ownSeat() {
|
|
@@ -354,7 +354,7 @@ function runUpdateNestedNodesThenDo(error, action) {
|
|
|
354
354
|
try {
|
|
355
355
|
children.endMerge(error);
|
|
356
356
|
for (const child of children.removedItems(true))
|
|
357
|
-
|
|
357
|
+
triggerDeactivation(child, true, true);
|
|
358
358
|
if (!error) {
|
|
359
359
|
const sequential = children.isStrict;
|
|
360
360
|
let p1 = undefined;
|
|
@@ -465,7 +465,7 @@ function mountOrRemountIfNecessary(node) {
|
|
|
465
465
|
if (node.stamp === Number.MAX_SAFE_INTEGER) {
|
|
466
466
|
unobs(() => {
|
|
467
467
|
node.stamp = Number.MAX_SAFE_INTEGER - 1;
|
|
468
|
-
driver.
|
|
468
|
+
driver.activate(node);
|
|
469
469
|
if (!node.has(Mode.manualMount)) {
|
|
470
470
|
node.stamp = 0;
|
|
471
471
|
if (node.host !== node)
|
|
@@ -503,14 +503,14 @@ function updateNow(seat) {
|
|
|
503
503
|
});
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
|
-
function
|
|
506
|
+
function triggerDeactivation(seat, isLeader, individual) {
|
|
507
507
|
const node = seat.instance;
|
|
508
508
|
if (node.stamp >= 0) {
|
|
509
509
|
const driver = node.driver;
|
|
510
510
|
if (individual && node.key !== node.declaration.key && !driver.isPartitionSeparator)
|
|
511
511
|
console.log(`WARNING: it is recommended to assign explicit key for conditional element in order to avoid unexpected side effects: ${node.key}`);
|
|
512
512
|
node.stamp = ~node.stamp;
|
|
513
|
-
const childrenAreLeaders = unobs(() => driver.
|
|
513
|
+
const childrenAreLeaders = unobs(() => driver.deactivate(node, isLeader));
|
|
514
514
|
if (node.has(Mode.independentUpdate)) {
|
|
515
515
|
seat.aux = undefined;
|
|
516
516
|
const last = gLastToDispose;
|
|
@@ -524,7 +524,7 @@ function triggerFinalization(seat, isLeader, individual) {
|
|
|
524
524
|
});
|
|
525
525
|
}
|
|
526
526
|
for (const child of node.children.items())
|
|
527
|
-
|
|
527
|
+
triggerDeactivation(child, childrenAreLeaders, false);
|
|
528
528
|
RxNodeImpl.grandNodeCount--;
|
|
529
529
|
}
|
|
530
530
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactronic",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.200",
|
|
4
4
|
"description": "Reactronic - Transactional Reactive State Management",
|
|
5
5
|
"publisher": "Nezaboodka Software",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/nezaboodka/reactronic/blob/master/README.md#readme",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/node": "20.11.
|
|
35
|
-
"@types/react": "18.2.
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
37
|
-
"@typescript-eslint/parser": "6.
|
|
34
|
+
"@types/node": "20.11.17",
|
|
35
|
+
"@types/react": "18.2.55",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "6.21.0",
|
|
37
|
+
"@typescript-eslint/parser": "6.21.0",
|
|
38
38
|
"ava": "6.1.1",
|
|
39
39
|
"c8": "9.1.0",
|
|
40
40
|
"eslint": "8.56.0",
|