reactronic 0.95.25047 → 0.95.25048
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/README.md +5 -5
- package/build/dist/source/System.d.ts +1 -1
- package/build/dist/source/System.js +1 -1
- package/build/dist/source/api.d.ts +1 -1
- package/build/dist/source/api.js +1 -1
- package/build/dist/source/core/TreeNode.d.ts +6 -6
- package/build/dist/source/core/TreeNode.js +14 -14
- package/build/dist/source/util/LinkedList.d.ts +3 -2
- package/build/dist/source/util/LinkedList.js +15 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ Quick introduction and detailed description is below.
|
|
|
48
48
|
Here is an example of transactional reactive code:
|
|
49
49
|
|
|
50
50
|
``` typescript
|
|
51
|
-
class Demo extends
|
|
51
|
+
class Demo extends RxObject {
|
|
52
52
|
name: string = 'Nezaboodka Software'
|
|
53
53
|
email: string = 'contact@nezaboodka.com'
|
|
54
54
|
|
|
@@ -115,7 +115,7 @@ to track access to their properties, both on reads and
|
|
|
115
115
|
writes.
|
|
116
116
|
|
|
117
117
|
``` typescript
|
|
118
|
-
class MyModel extends
|
|
118
|
+
class MyModel extends RxObject {
|
|
119
119
|
url: string = "https://github.com/nezaboodka/reactronic"
|
|
120
120
|
content: string = "transactional reactive state management"
|
|
121
121
|
timestamp: Date = Date.now()
|
|
@@ -123,7 +123,7 @@ class MyModel extends SignallingObject {
|
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
In the example above, the class `MyModel` is based on
|
|
126
|
-
Reactronic's `
|
|
126
|
+
Reactronic's `RxObject` class and all its
|
|
127
127
|
properties `url`, `content`, and `timestamp` are hooked.
|
|
128
128
|
|
|
129
129
|
## Transactional Function
|
|
@@ -136,7 +136,7 @@ provide transparent atomicity (by implicit context
|
|
|
136
136
|
switching and isolation).
|
|
137
137
|
|
|
138
138
|
``` typescript
|
|
139
|
-
class MyModel extends
|
|
139
|
+
class MyModel extends RxObject {
|
|
140
140
|
// ...
|
|
141
141
|
@transaction
|
|
142
142
|
async load(url: string): Promise<void> {
|
|
@@ -232,7 +232,7 @@ class Component<P> extends React.Component<P> {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
componentWillUnmount(): void {
|
|
235
|
-
runTransactional(
|
|
235
|
+
runTransactional(disposeRxObject, this)
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
```
|
|
@@ -20,7 +20,7 @@ export declare function runSensitive<T>(sensitivity: boolean, func: F<T>, ...arg
|
|
|
20
20
|
export declare function runContextual<T>(p: Promise<T>): Promise<T>;
|
|
21
21
|
export declare function manageReaction<T>(method: F<T>): Reaction<T>;
|
|
22
22
|
export declare function configureCurrentReaction(options: Partial<ReactivityOptions>): ReactivityOptions;
|
|
23
|
-
export declare function
|
|
23
|
+
export declare function disposeRxObject(obj: any): void;
|
|
24
24
|
export declare function signal(enabled: boolean): (proto: object, prop: PropertyKey) => any;
|
|
25
25
|
export declare function signal<T>(proto: object, prop: PropertyKey): any;
|
|
26
26
|
export declare function transaction(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
|
|
@@ -47,7 +47,7 @@ export function manageReaction(method) {
|
|
|
47
47
|
export function configureCurrentReaction(options) {
|
|
48
48
|
return ReactionImpl.configureImpl(undefined, options);
|
|
49
49
|
}
|
|
50
|
-
export function
|
|
50
|
+
export function disposeRxObject(obj) {
|
|
51
51
|
Changeset.dispose(obj);
|
|
52
52
|
}
|
|
53
53
|
export function signal(protoOrEnabled, prop) {
|
|
@@ -18,7 +18,7 @@ export { Changeset } from "./core/Changeset.js";
|
|
|
18
18
|
export { Transaction } from "./core/Transaction.js";
|
|
19
19
|
export { Indicator } from "./core/Indicator.js";
|
|
20
20
|
export { Journal } from "./core/Journal.js";
|
|
21
|
-
export { runTransactional, runNonReactive, runSensitive, runContextual, manageReaction, configureCurrentReaction,
|
|
21
|
+
export { runTransactional, runNonReactive, runSensitive, runContextual, manageReaction, configureCurrentReaction, disposeRxObject } from "./System.js";
|
|
22
22
|
export { ReactiveSystem, signal, transaction, reaction, cache, options } from "./System.js";
|
|
23
23
|
export { ReactionEx } from "./OperationEx.js";
|
|
24
24
|
export { declare, derivative, launch, ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
|
package/build/dist/source/api.js
CHANGED
|
@@ -14,7 +14,7 @@ export { Changeset } from "./core/Changeset.js";
|
|
|
14
14
|
export { Transaction } from "./core/Transaction.js";
|
|
15
15
|
export { Indicator } from "./core/Indicator.js";
|
|
16
16
|
export { Journal } from "./core/Journal.js";
|
|
17
|
-
export { runTransactional, runNonReactive, runSensitive, runContextual, manageReaction, configureCurrentReaction,
|
|
17
|
+
export { runTransactional, runNonReactive, runSensitive, runContextual, manageReaction, configureCurrentReaction, disposeRxObject } from "./System.js";
|
|
18
18
|
export { ReactiveSystem, signal, transaction, reaction, cache, options } from "./System.js";
|
|
19
19
|
export { ReactionEx } from "./OperationEx.js";
|
|
20
20
|
export { declare, derivative, launch, ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
|
|
@@ -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>, script?: Script<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>,
|
|
9
|
+
export declare function 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>, 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>, scriptOrDeclaration?: Script<E> | ReactiveTreeNodeDecl<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>,
|
|
11
|
+
export declare function 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>, 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>(node: ReactiveTreeNode<T>,
|
|
13
|
+
export declare function launch<T>(node: ReactiveTreeNode<T>, signalArgs?: unknown): ReactiveTreeNode<T>;
|
|
14
14
|
export declare abstract class ReactiveTreeNode<E = unknown> {
|
|
15
15
|
static readonly shortFrameDuration = 16;
|
|
16
16
|
static readonly longFrameDuration = 300;
|
|
@@ -36,7 +36,7 @@ export declare abstract class ReactiveTreeNode<E = unknown> {
|
|
|
36
36
|
abstract configureReactivity(options: Partial<ReactivityOptions>): ReactivityOptions;
|
|
37
37
|
static get current(): ReactiveTreeNode;
|
|
38
38
|
static get isFirstScriptRun(): boolean;
|
|
39
|
-
static launchScript(node: ReactiveTreeNode<any>,
|
|
39
|
+
static launchScript(node: ReactiveTreeNode<any>, signalArgs: unknown): void;
|
|
40
40
|
static launchFinalization(node: ReactiveTreeNode<any>): void;
|
|
41
41
|
static launchNestedNodesThenDo(action: (error: unknown) => void): void;
|
|
42
42
|
static markAsMounted(node: ReactiveTreeNode<any>, yes: boolean): void;
|
|
@@ -55,7 +55,7 @@ export type ReactiveTreeNodeDecl<E = unknown> = {
|
|
|
55
55
|
preparation?: Script<E>;
|
|
56
56
|
preparationAsync?: ScriptAsync<E>;
|
|
57
57
|
finalization?: Script<E>;
|
|
58
|
-
|
|
58
|
+
signalArgs?: unknown;
|
|
59
59
|
basis?: ReactiveTreeNodeDecl<E>;
|
|
60
60
|
};
|
|
61
61
|
export type ReactiveTreeNodeDriver<E = unknown> = {
|
|
@@ -126,7 +126,7 @@ declare class ReactiveTreeNode$<E = unknown> extends ReactiveTreeNode<E> {
|
|
|
126
126
|
set strictOrder(value: boolean);
|
|
127
127
|
get isMoved(): boolean;
|
|
128
128
|
has(mode: Mode): boolean;
|
|
129
|
-
script(
|
|
129
|
+
script(_signalArgs: unknown): void;
|
|
130
130
|
configureReactivity(options: Partial<ReactivityOptions>): ReactivityOptions;
|
|
131
131
|
static get nodeSlot(): LinkedItem<ReactiveTreeNode$>;
|
|
132
132
|
static tryUseTreeVariableValue<T extends Object>(variable: ReactiveTreeVariable<T>): T | undefined;
|
|
@@ -23,14 +23,14 @@ import { emitLetters, flags, getCallerInfo, proceedSyncOrAsync } from "../util/U
|
|
|
23
23
|
import { Priority, Mode, Isolation, Reentrance } from "../Enums.js";
|
|
24
24
|
import { RxObject } from "../core/Mvcc.js";
|
|
25
25
|
import { Transaction } from "../core/Transaction.js";
|
|
26
|
-
import { ReactiveSystem, options, signal, reaction, runTransactional, runNonReactive, manageReaction,
|
|
27
|
-
export function declare(driver, scriptOrDeclaration, scriptAsync, key, mode, preparation, preparationAsync, finalization,
|
|
26
|
+
import { ReactiveSystem, options, signal, reaction, runTransactional, runNonReactive, manageReaction, disposeRxObject } from "../System.js";
|
|
27
|
+
export function declare(driver, scriptOrDeclaration, scriptAsync, key, mode, preparation, preparationAsync, finalization, signalArgs, basis) {
|
|
28
28
|
let result;
|
|
29
29
|
let declaration;
|
|
30
30
|
if (scriptOrDeclaration instanceof Function) {
|
|
31
31
|
declaration = {
|
|
32
32
|
script: scriptOrDeclaration, scriptAsync, key, mode,
|
|
33
|
-
preparation, preparationAsync, finalization,
|
|
33
|
+
preparation, preparationAsync, finalization, signalArgs, basis,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
else
|
|
@@ -45,9 +45,9 @@ export function declare(driver, scriptOrDeclaration, scriptAsync, key, mode, pre
|
|
|
45
45
|
result = existing.instance;
|
|
46
46
|
if (result.driver !== driver && driver !== undefined)
|
|
47
47
|
throw misuse(`changing element driver is not yet supported: "${result.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
|
|
48
|
-
const
|
|
49
|
-
if (signalsAreEqual(declaration.
|
|
50
|
-
declaration.
|
|
48
|
+
const exSignalArgs = result.declaration.signalArgs;
|
|
49
|
+
if (signalsAreEqual(declaration.signalArgs, exSignalArgs))
|
|
50
|
+
declaration.signalArgs = exSignalArgs;
|
|
51
51
|
result.declaration = declaration;
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
@@ -68,8 +68,8 @@ export function derivative(declaration, basis) {
|
|
|
68
68
|
declaration = basis !== null && basis !== void 0 ? basis : {};
|
|
69
69
|
return declaration;
|
|
70
70
|
}
|
|
71
|
-
export function launch(node,
|
|
72
|
-
ReactiveTreeNode.launchScript(node,
|
|
71
|
+
export function launch(node, signalArgs) {
|
|
72
|
+
ReactiveTreeNode.launchScript(node, signalArgs);
|
|
73
73
|
return node;
|
|
74
74
|
}
|
|
75
75
|
export class ReactiveTreeNode {
|
|
@@ -79,11 +79,11 @@ export class ReactiveTreeNode {
|
|
|
79
79
|
static get isFirstScriptRun() {
|
|
80
80
|
return ReactiveTreeNode.current.stamp === 1;
|
|
81
81
|
}
|
|
82
|
-
static launchScript(node,
|
|
82
|
+
static launchScript(node, signalArgs) {
|
|
83
83
|
const impl = node;
|
|
84
84
|
const declaration = impl.declaration;
|
|
85
|
-
if (node.stamp >= Number.MAX_SAFE_INTEGER || !signalsAreEqual(
|
|
86
|
-
declaration.
|
|
85
|
+
if (node.stamp >= Number.MAX_SAFE_INTEGER || !signalsAreEqual(signalArgs, declaration.signalArgs)) {
|
|
86
|
+
declaration.signalArgs = signalArgs;
|
|
87
87
|
launchScriptViaSlot(impl.slot);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -303,7 +303,7 @@ class ReactiveTreeNode$ extends ReactiveTreeNode {
|
|
|
303
303
|
has(mode) {
|
|
304
304
|
return flags(getModeUsingBasisChain(this.declaration), mode);
|
|
305
305
|
}
|
|
306
|
-
script(
|
|
306
|
+
script(_signalArgs) {
|
|
307
307
|
runScriptNow(this.slot);
|
|
308
308
|
}
|
|
309
309
|
configureReactivity(options) {
|
|
@@ -494,7 +494,7 @@ function launchScriptViaSlot(nodeSlot) {
|
|
|
494
494
|
});
|
|
495
495
|
});
|
|
496
496
|
}
|
|
497
|
-
runNonReactive(node.script, node.declaration.
|
|
497
|
+
runNonReactive(node.script, node.declaration.signalArgs);
|
|
498
498
|
}
|
|
499
499
|
else if (node.owner !== node)
|
|
500
500
|
runScriptNow(nodeSlot);
|
|
@@ -574,7 +574,7 @@ function runDisposalLoop() {
|
|
|
574
574
|
while (slot !== undefined) {
|
|
575
575
|
if (Transaction.isFrameOver(500, 5))
|
|
576
576
|
yield Transaction.requestNextFrame();
|
|
577
|
-
|
|
577
|
+
disposeRxObject(slot.instance);
|
|
578
578
|
slot = slot.aux;
|
|
579
579
|
ReactiveTreeNode$.disposableNodeCount--;
|
|
580
580
|
}
|
|
@@ -5,10 +5,11 @@ export declare class LinkedList<T extends LinkedItem<T>> {
|
|
|
5
5
|
private isStrictOrder$;
|
|
6
6
|
private map;
|
|
7
7
|
items$: LinkedSubList<T>;
|
|
8
|
-
private renovation
|
|
8
|
+
private renovation$;
|
|
9
9
|
constructor(keyExtractor: KeyExtractor<T>, isStrictOrder?: boolean);
|
|
10
10
|
get isStrictOrder(): boolean;
|
|
11
11
|
set isStrictOrder(value: boolean);
|
|
12
|
+
get renovation(): LinkedListRenovation<T>;
|
|
12
13
|
get isRenovationInProgress(): boolean;
|
|
13
14
|
get count(): number;
|
|
14
15
|
items(): Generator<T>;
|
|
@@ -17,7 +18,7 @@ export declare class LinkedList<T extends LinkedItem<T>> {
|
|
|
17
18
|
move(item: T, before: T | undefined): void;
|
|
18
19
|
remove(item: T): void;
|
|
19
20
|
beginRenovation(diff?: Array<T>): LinkedListRenovation<T>;
|
|
20
|
-
endRenovation(error?: unknown):
|
|
21
|
+
endRenovation(error?: unknown): LinkedListRenovation<T>;
|
|
21
22
|
static move$<T extends LinkedItem<T>>(list: LinkedList<T>, item: T, before: T | undefined): void;
|
|
22
23
|
static remove$<T extends LinkedItem<T>>(list: LinkedList<T>, item: T): void;
|
|
23
24
|
static removeKey$<T extends LinkedItem<T>>(list: LinkedList<T>, key: string | undefined): void;
|
|
@@ -5,20 +5,26 @@ export class LinkedList {
|
|
|
5
5
|
this.isStrictOrder$ = isStrictOrder;
|
|
6
6
|
this.map = new Map();
|
|
7
7
|
this.items$ = new LinkedSubList();
|
|
8
|
-
this.renovation = undefined;
|
|
8
|
+
this.renovation$ = undefined;
|
|
9
9
|
}
|
|
10
10
|
get isStrictOrder() { return this.isStrictOrder$; }
|
|
11
11
|
set isStrictOrder(value) {
|
|
12
|
-
if (this.renovation !== undefined)
|
|
12
|
+
if (this.renovation$ !== undefined)
|
|
13
13
|
throw misuse("cannot change strict mode in the middle of renovation");
|
|
14
14
|
this.isStrictOrder$ = value;
|
|
15
15
|
}
|
|
16
|
+
get renovation() {
|
|
17
|
+
const r = this.renovation$;
|
|
18
|
+
if (r === undefined)
|
|
19
|
+
throw misuse("renovation is not in progress");
|
|
20
|
+
return r;
|
|
21
|
+
}
|
|
16
22
|
get isRenovationInProgress() {
|
|
17
|
-
return this.renovation !== undefined;
|
|
23
|
+
return this.renovation$ !== undefined;
|
|
18
24
|
}
|
|
19
25
|
get count() {
|
|
20
26
|
var _a, _b;
|
|
21
|
-
return this.items$.count + ((_b = (_a = this.renovation) === null || _a === void 0 ? void 0 : _a.lostItemCount) !== null && _b !== void 0 ? _b : 0);
|
|
27
|
+
return this.items$.count + ((_b = (_a = this.renovation$) === null || _a === void 0 ? void 0 : _a.lostItemCount) !== null && _b !== void 0 ? _b : 0);
|
|
22
28
|
}
|
|
23
29
|
items() {
|
|
24
30
|
return this.items$.items();
|
|
@@ -48,16 +54,16 @@ export class LinkedList {
|
|
|
48
54
|
LinkedList.remove$(this, item);
|
|
49
55
|
}
|
|
50
56
|
beginRenovation(diff) {
|
|
51
|
-
if (this.renovation !== undefined)
|
|
57
|
+
if (this.renovation$ !== undefined)
|
|
52
58
|
throw misuse("renovation is in progress already");
|
|
53
59
|
const former = this.items$;
|
|
54
60
|
const renovation = new LinkedListRenovation(this, former, diff);
|
|
55
61
|
this.items$ = new LinkedSubList();
|
|
56
|
-
this.renovation = renovation;
|
|
62
|
+
this.renovation$ = renovation;
|
|
57
63
|
return renovation;
|
|
58
64
|
}
|
|
59
65
|
endRenovation(error) {
|
|
60
|
-
const renovation = this.renovation
|
|
66
|
+
const renovation = this.renovation$;
|
|
61
67
|
if (renovation === undefined)
|
|
62
68
|
throw misuse("renovation is ended already");
|
|
63
69
|
const items = this.items$;
|
|
@@ -77,7 +83,8 @@ export class LinkedList {
|
|
|
77
83
|
LinkedItem.setStatus$(x, Mark.prolonged, items.count);
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
|
-
this.renovation = undefined;
|
|
86
|
+
this.renovation$ = undefined;
|
|
87
|
+
return renovation;
|
|
81
88
|
}
|
|
82
89
|
static move$(list, item, before) {
|
|
83
90
|
LinkedItem.link$(list.items$, item, before);
|