reactronic 0.96.26015 → 0.96.26017
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/Enums.d.ts +3 -2
- package/build/dist/source/Enums.js +2 -1
- package/build/dist/source/core/TreeNode.d.ts +7 -3
- package/build/dist/source/core/TreeNode.js +34 -20
- package/build/dist/source/util/LinkedList.d.ts +1 -1
- package/build/dist/source/util/LinkedList.js +5 -5
- package/build/dist/source/util/Utils.d.ts +1 -0
- package/build/dist/source/util/Utils.js +3 -0
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export var Mode;
|
|
2
2
|
(function (Mode) {
|
|
3
3
|
Mode[Mode["default"] = 0] = "default";
|
|
4
|
-
Mode[Mode["
|
|
4
|
+
Mode[Mode["primitive"] = 1] = "primitive";
|
|
5
5
|
Mode[Mode["external"] = 2] = "external";
|
|
6
|
+
Mode[Mode["artificial"] = 4] = "artificial";
|
|
6
7
|
})(Mode || (Mode = {}));
|
|
7
8
|
export var Priority;
|
|
8
9
|
(function (Priority) {
|
|
@@ -6,11 +6,11 @@ import { RxObject } from "../core/Mvcc.js";
|
|
|
6
6
|
export type Script<E> = (this: E, o: E, basis: () => void) => void;
|
|
7
7
|
export type ScriptAsync<E> = (this: E, o: E, basis: () => Promise<void>) => Promise<void>;
|
|
8
8
|
export type Handler<E = unknown, R = void> = (o: E) => R;
|
|
9
|
-
export declare function declare<E = void>(driver: ReactiveTreeNodeDriver<E>, body?: Script<E>, bodyTask?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationTask?: ScriptAsync<E>, finalization?: Script<E>, signalArgs?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
9
|
+
export declare function declare<E = void>(driver: ReactiveTreeNodeDriver<E>, body?: Script<E>, bodyTask?: ScriptAsync<E>, key?: string, mode?: Mode, unmounted?: boolean, preparation?: Script<E>, preparationTask?: ScriptAsync<E>, mounting?: Script<E>, finalization?: Script<E>, signalArgs?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
10
10
|
export declare function declare<E = void>(driver: ReactiveTreeNodeDriver<E>, declaration?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
11
|
-
export declare function declare<E = void>(driver: ReactiveTreeNodeDriver<E>, bodyOrDeclaration?: Script<E> | ReactiveTreeNodeDecl<E>, bodyTask?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationTask?: ScriptAsync<E>, finalization?: Script<E>, signalArgs?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
11
|
+
export declare function declare<E = void>(driver: ReactiveTreeNodeDriver<E>, bodyOrDeclaration?: Script<E> | ReactiveTreeNodeDecl<E>, bodyTask?: ScriptAsync<E>, key?: string, mode?: Mode, unmounted?: boolean, preparation?: Script<E>, preparationTask?: ScriptAsync<E>, mounting?: Script<E>, finalization?: Script<E>, signalArgs?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
|
|
12
12
|
export declare function derivative<E = void>(declaration?: ReactiveTreeNodeDecl<E>, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNodeDecl<E>;
|
|
13
|
-
export declare function launch<T>(func: (...args: any[]) => T, ...args: any[]):
|
|
13
|
+
export declare function launch<T>(func: (...args: any[]) => T, ...args: any[]): T;
|
|
14
14
|
export declare abstract class ReactiveTreeNode<E = unknown> extends LinkedItem<ReactiveTreeNode<E>> {
|
|
15
15
|
static readonly shortFrameDuration = 16;
|
|
16
16
|
static readonly longFrameDuration = 300;
|
|
@@ -32,6 +32,7 @@ export declare abstract class ReactiveTreeNode<E = unknown> extends LinkedItem<R
|
|
|
32
32
|
abstract strictOrder: boolean;
|
|
33
33
|
abstract getUri(relativeTo?: ReactiveTreeNode<any>): string;
|
|
34
34
|
abstract has(mode: Mode): boolean;
|
|
35
|
+
abstract hasAny(mode: Mode): boolean;
|
|
35
36
|
abstract configureReactivity(options: Partial<ReactivityOptions>): ReactivityOptions;
|
|
36
37
|
static get current(): ReactiveTreeNode;
|
|
37
38
|
static get isFirstBodyBuild(): boolean;
|
|
@@ -51,8 +52,10 @@ export type ReactiveTreeNodeDecl<E = unknown> = {
|
|
|
51
52
|
bodyTask?: ScriptAsync<E>;
|
|
52
53
|
key?: string;
|
|
53
54
|
mode?: Mode;
|
|
55
|
+
unmounted?: boolean;
|
|
54
56
|
preparation?: Script<E>;
|
|
55
57
|
preparationTask?: ScriptAsync<E>;
|
|
58
|
+
mounting?: Script<E>;
|
|
56
59
|
finalization?: Script<E>;
|
|
57
60
|
signalArgs?: unknown;
|
|
58
61
|
basis?: ReactiveTreeNodeDecl<E>;
|
|
@@ -126,6 +129,7 @@ declare class ReactiveTreeNode$<E = unknown> extends ReactiveTreeNode<E> {
|
|
|
126
129
|
set strictOrder(value: boolean);
|
|
127
130
|
get isMoved(): boolean;
|
|
128
131
|
has(mode: Mode): boolean;
|
|
132
|
+
hasAny(mode: Mode): boolean;
|
|
129
133
|
body(_signalArgs: unknown): void;
|
|
130
134
|
configureReactivity(options: Partial<ReactivityOptions>): ReactivityOptions;
|
|
131
135
|
static get node(): ReactiveTreeNode$;
|
|
@@ -16,12 +16,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
16
16
|
import { misuse } from "../util/Dbg.js";
|
|
17
17
|
import { Uri } from "../util/Uri.js";
|
|
18
18
|
import { LinkedList, LinkedItem, Mark, LinkedSubList } from "../util/LinkedList.js";
|
|
19
|
-
import { emitLetters, flags, getCallerInfo, proceedSyncOrAsync } from "../util/Utils.js";
|
|
19
|
+
import { emitLetters, flags, flagsAny, getCallerInfo, proceedSyncOrAsync } from "../util/Utils.js";
|
|
20
20
|
import { Priority, Mode, Isolation, Reentrance } from "../Enums.js";
|
|
21
21
|
import { RxObject } from "../core/Mvcc.js";
|
|
22
22
|
import { Transaction } from "../core/Transaction.js";
|
|
23
23
|
import { ReactiveSystem, options, signal, reaction, runTransactional, runNonReactive, manageReaction, disposeRxObject } from "../System.js";
|
|
24
|
-
export function declare(driver, bodyOrDeclaration, bodyTask, key, mode, preparation, preparationTask, finalization, signalArgs, basis) {
|
|
24
|
+
export function declare(driver, bodyOrDeclaration, bodyTask, key, mode, unmounted, preparation, preparationTask, mounting, finalization, signalArgs, basis) {
|
|
25
25
|
let result;
|
|
26
26
|
let declaration;
|
|
27
27
|
if (bodyOrDeclaration instanceof Function) {
|
|
@@ -66,7 +66,7 @@ export function derivative(declaration, basis) {
|
|
|
66
66
|
return declaration;
|
|
67
67
|
}
|
|
68
68
|
export function launch(func, ...args) {
|
|
69
|
-
runInsideContextOfNode(undefined, func, ...args);
|
|
69
|
+
return runInsideContextOfNode(undefined, func, ...args);
|
|
70
70
|
}
|
|
71
71
|
export class ReactiveTreeNode extends LinkedItem {
|
|
72
72
|
static get current() {
|
|
@@ -152,9 +152,10 @@ export class BaseDriver {
|
|
|
152
152
|
return isLeader;
|
|
153
153
|
}
|
|
154
154
|
runMount(node) {
|
|
155
|
+
invokeMountingUsingBasisChain(node.element, node.declaration);
|
|
155
156
|
}
|
|
156
157
|
rebuildBody(node) {
|
|
157
|
-
return
|
|
158
|
+
return invokeBodyUsingBasisChain(node.element, node.declaration);
|
|
158
159
|
}
|
|
159
160
|
declareChild(ownerNode, childDriver, childDeclaration, childBasis) {
|
|
160
161
|
return undefined;
|
|
@@ -192,7 +193,7 @@ export function getModeUsingBasisChain(declaration) {
|
|
|
192
193
|
var _a;
|
|
193
194
|
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);
|
|
194
195
|
}
|
|
195
|
-
function
|
|
196
|
+
function invokeBodyUsingBasisChain(element, declaration) {
|
|
196
197
|
let result = undefined;
|
|
197
198
|
const basis = declaration.basis;
|
|
198
199
|
const body = declaration.body;
|
|
@@ -200,11 +201,11 @@ function invokeScriptUsingBasisChain(element, declaration) {
|
|
|
200
201
|
if (body && bodyTask)
|
|
201
202
|
throw misuse("'body' and 'bodyTask' cannot be defined together");
|
|
202
203
|
if (body)
|
|
203
|
-
result = body.call(element, element, basis ? () =>
|
|
204
|
+
result = body.call(element, element, basis ? () => invokeBodyUsingBasisChain(element, basis) : NOP);
|
|
204
205
|
else if (bodyTask)
|
|
205
|
-
result = bodyTask.call(element, element, basis ? () =>
|
|
206
|
+
result = bodyTask.call(element, element, basis ? () => invokeBodyUsingBasisChain(element, basis) : NOP_ASYNC);
|
|
206
207
|
else if (basis)
|
|
207
|
-
result =
|
|
208
|
+
result = invokeBodyUsingBasisChain(element, basis);
|
|
208
209
|
return result;
|
|
209
210
|
}
|
|
210
211
|
function invokePreparationUsingBasisChain(element, declaration) {
|
|
@@ -222,6 +223,14 @@ function invokePreparationUsingBasisChain(element, declaration) {
|
|
|
222
223
|
result = invokePreparationUsingBasisChain(element, basis);
|
|
223
224
|
return result;
|
|
224
225
|
}
|
|
226
|
+
function invokeMountingUsingBasisChain(element, declaration) {
|
|
227
|
+
const basis = declaration.basis;
|
|
228
|
+
const mounting = declaration.mounting;
|
|
229
|
+
if (mounting)
|
|
230
|
+
mounting.call(element, element, basis ? () => invokeMountingUsingBasisChain(element, basis) : NOP);
|
|
231
|
+
else if (basis)
|
|
232
|
+
invokeMountingUsingBasisChain(element, basis);
|
|
233
|
+
}
|
|
225
234
|
function invokeFinalizationUsingBasisChain(element, declaration) {
|
|
226
235
|
const basis = declaration.basis;
|
|
227
236
|
const finalization = declaration.finalization;
|
|
@@ -271,7 +280,7 @@ class ReactiveTreeNode$ extends ReactiveTreeNode {
|
|
|
271
280
|
this.priority = Priority.realtime;
|
|
272
281
|
this.childrenShuffling = false;
|
|
273
282
|
ReactiveTreeNode$.grandNodeCount++;
|
|
274
|
-
if (this.has(Mode.
|
|
283
|
+
if (!this.has(Mode.primitive))
|
|
275
284
|
ReactiveTreeNode$.disposableNodeCount++;
|
|
276
285
|
}
|
|
277
286
|
getUri(relativeTo) {
|
|
@@ -291,17 +300,20 @@ class ReactiveTreeNode$ extends ReactiveTreeNode {
|
|
|
291
300
|
this.children.isStrictOrder = value;
|
|
292
301
|
}
|
|
293
302
|
get isMoved() {
|
|
294
|
-
return this.mark === Mark.
|
|
303
|
+
return this.mark === Mark.moved;
|
|
295
304
|
}
|
|
296
305
|
has(mode) {
|
|
297
306
|
return flags(getModeUsingBasisChain(this.declaration), mode);
|
|
298
307
|
}
|
|
308
|
+
hasAny(mode) {
|
|
309
|
+
return flagsAny(getModeUsingBasisChain(this.declaration), mode);
|
|
310
|
+
}
|
|
299
311
|
body(_signalArgs) {
|
|
300
312
|
rebuildBodyNow(this);
|
|
301
313
|
}
|
|
302
314
|
configureReactivity(options) {
|
|
303
|
-
if (this.stamp < Number.MAX_SAFE_INTEGER - 1 ||
|
|
304
|
-
throw misuse("
|
|
315
|
+
if (this.stamp < Number.MAX_SAFE_INTEGER - 1 || this.has(Mode.primitive))
|
|
316
|
+
throw misuse("reactivity can be configured only for elements with non-primitive mode and only during preparation");
|
|
305
317
|
return manageReaction(this.body).configure(options);
|
|
306
318
|
}
|
|
307
319
|
static get node() {
|
|
@@ -395,8 +407,8 @@ function launchNestedNodesThenDoImpl(node, error, action) {
|
|
|
395
407
|
if (Transaction.isCanceled)
|
|
396
408
|
break;
|
|
397
409
|
const child = c;
|
|
398
|
-
const
|
|
399
|
-
const host =
|
|
410
|
+
const isPartition = child.driver.isPartition;
|
|
411
|
+
const host = isPartition ? owner : partition;
|
|
400
412
|
mounting = markToMountIfNecessary(mounting, host, child, children, sequential);
|
|
401
413
|
const p = (_a = child.priority) !== null && _a !== void 0 ? _a : Priority.realtime;
|
|
402
414
|
if (p === Priority.realtime)
|
|
@@ -405,7 +417,7 @@ function launchNestedNodesThenDoImpl(node, error, action) {
|
|
|
405
417
|
p1 = push(child, p1);
|
|
406
418
|
else
|
|
407
419
|
p2 = push(child, p2);
|
|
408
|
-
if (
|
|
420
|
+
if (isPartition)
|
|
409
421
|
partition = child;
|
|
410
422
|
}
|
|
411
423
|
if (!Transaction.isCanceled && (p1 !== undefined || p2 !== undefined))
|
|
@@ -420,13 +432,15 @@ function launchNestedNodesThenDoImpl(node, error, action) {
|
|
|
420
432
|
});
|
|
421
433
|
}
|
|
422
434
|
function markToMountIfNecessary(mounting, host, node, children, sequential) {
|
|
423
|
-
if (node.
|
|
435
|
+
if (node.declaration.unmounted)
|
|
436
|
+
host = node;
|
|
437
|
+
if (!node.hasAny(Mode.external | Mode.artificial)) {
|
|
424
438
|
if (mounting || node.host !== host) {
|
|
425
|
-
LinkedItem.setStatus$(node, Mark.
|
|
439
|
+
LinkedItem.setStatus$(node, Mark.moved, node.rank);
|
|
426
440
|
mounting = false;
|
|
427
441
|
}
|
|
428
442
|
}
|
|
429
|
-
else if (sequential && node.mark === Mark.
|
|
443
|
+
else if (sequential && node.mark === Mark.moved)
|
|
430
444
|
mounting = true;
|
|
431
445
|
node.host = host;
|
|
432
446
|
return mounting;
|
|
@@ -473,7 +487,7 @@ function runNestedScriptsIncrementally(owner, stamp, allChildren, items, priorit
|
|
|
473
487
|
}
|
|
474
488
|
function rebuildBodyImpl(node) {
|
|
475
489
|
if (node.stamp >= 0) {
|
|
476
|
-
if (node.has(Mode.
|
|
490
|
+
if (!node.has(Mode.primitive)) {
|
|
477
491
|
if (node.stamp === Number.MAX_SAFE_INTEGER) {
|
|
478
492
|
Transaction.outside(() => {
|
|
479
493
|
if (ReactiveSystem.isLogging)
|
|
@@ -537,7 +551,7 @@ function launchFinalizationImpl(node, isLeader, individual) {
|
|
|
537
551
|
console.log(`WARNING: it is recommended to assign explicit key for conditional element in order to avoid unexpected side effects: ${node.key}`);
|
|
538
552
|
node.stamp = ~node.stamp;
|
|
539
553
|
const childrenAreLeaders = runNonReactive(() => driver.runFinalization(node, isLeader));
|
|
540
|
-
if (node.has(Mode.
|
|
554
|
+
if (!node.has(Mode.primitive)) {
|
|
541
555
|
LinkedItem.link$(gDisposeList, node, undefined);
|
|
542
556
|
if (gDisposeList.first === node)
|
|
543
557
|
runTransactional({ isolation: Isolation.disjoinForInternalDisposal, hint: `runDisposalLoop(initiator=${node.key})` }, () => {
|
|
@@ -120,7 +120,7 @@ export var Mark;
|
|
|
120
120
|
(function (Mark) {
|
|
121
121
|
Mark[Mark["reaffirmed"] = 0] = "reaffirmed";
|
|
122
122
|
Mark[Mark["added"] = 1] = "added";
|
|
123
|
-
Mark[Mark["
|
|
123
|
+
Mark[Mark["moved"] = 2] = "moved";
|
|
124
124
|
Mark[Mark["removed"] = 3] = "removed";
|
|
125
125
|
})(Mark || (Mark = {}));
|
|
126
126
|
const MARK_MOD = 4;
|
|
@@ -271,7 +271,7 @@ export class LinkedListRenovation {
|
|
|
271
271
|
const expected = (_a = grabExternalIfAny(result, x)) !== null && _a !== void 0 ? _a : x;
|
|
272
272
|
LinkedItem.link$(result, x, undefined);
|
|
273
273
|
if (list.isStrictOrder && expected !== this.expected) {
|
|
274
|
-
LinkedItem.setStatus$(x, Mark.
|
|
274
|
+
LinkedItem.setStatus$(x, Mark.moved, result.count);
|
|
275
275
|
(_b = this.diff) === null || _b === void 0 ? void 0 : _b.push(x);
|
|
276
276
|
}
|
|
277
277
|
else
|
|
@@ -303,8 +303,8 @@ export class LinkedListRenovation {
|
|
|
303
303
|
throw misuse("only reaffirmed items can be marked as modified");
|
|
304
304
|
const m = item.mark;
|
|
305
305
|
if (m === Mark.reaffirmed)
|
|
306
|
-
LinkedItem.setStatus$(item, Mark.
|
|
307
|
-
else if (m !== Mark.
|
|
306
|
+
LinkedItem.setStatus$(item, Mark.moved, item.rank);
|
|
307
|
+
else if (m !== Mark.moved)
|
|
308
308
|
throw misuse("item is renovated already and cannot be marked as modified");
|
|
309
309
|
}
|
|
310
310
|
thisIsMoved(item, before) {
|
|
@@ -312,7 +312,7 @@ export class LinkedListRenovation {
|
|
|
312
312
|
if (item.list !== this.former)
|
|
313
313
|
throw misuse("cannot move item which doesn't belong to former list");
|
|
314
314
|
LinkedList.move$(this.list, item, before);
|
|
315
|
-
LinkedItem.setStatus$(item, Mark.
|
|
315
|
+
LinkedItem.setStatus$(item, Mark.moved, 0);
|
|
316
316
|
(_a = this.diff) === null || _a === void 0 ? void 0 : _a.push(item);
|
|
317
317
|
}
|
|
318
318
|
thisIsRemoved(item) {
|
|
@@ -5,6 +5,7 @@ export declare class Utils {
|
|
|
5
5
|
static copyAllMembers(source: any, target: any): any;
|
|
6
6
|
}
|
|
7
7
|
export declare function flags(value: number, flags: number): boolean;
|
|
8
|
+
export declare function flagsAny(value: number, flags: number): boolean;
|
|
8
9
|
export declare function UNDEF(...args: any[]): never;
|
|
9
10
|
export declare function all(promises: Array<Promise<any>>): Promise<any[]>;
|
|
10
11
|
export declare function pause<T>(timeout: number): Promise<T>;
|
|
@@ -40,6 +40,9 @@ export class Utils {
|
|
|
40
40
|
export function flags(value, flags) {
|
|
41
41
|
return (value & flags) === flags;
|
|
42
42
|
}
|
|
43
|
+
export function flagsAny(value, flags) {
|
|
44
|
+
return (value & flags) !== 0;
|
|
45
|
+
}
|
|
43
46
|
export function UNDEF(...args) {
|
|
44
47
|
throw fatal(new Error("this method should never be called"));
|
|
45
48
|
}
|