reactronic 0.21.516 → 0.21.520
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 +1 -1
- package/build/dist/source/Ref.d.ts +3 -3
- package/build/dist/source/Ref.js +8 -8
- package/build/dist/source/Trace.d.ts +3 -3
- package/build/dist/source/Trace.js +3 -3
- package/build/dist/source/impl/Operation.js +15 -15
- package/build/dist/source/util/Dbg.js +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://circleci.com/gh/nezaboodka/reactronic)
|
|
7
7
|

|
|
8
8
|

|
|
9
|
-
[](https://gitlab.com/nezaboodka/nevod.
|
|
9
|
+
[](https://gitlab.com/nezaboodka/nevod.website/-/blob/master/README.md)
|
|
10
10
|
|
|
11
11
|
# **Reactronic** - Transactional Reactive State Management
|
|
12
12
|
|
|
@@ -27,8 +27,8 @@ export declare class Ref<T = any> {
|
|
|
27
27
|
static similarRefs(v1: Ref, v2: Ref): boolean;
|
|
28
28
|
}
|
|
29
29
|
export declare class ToggleRef<T = boolean> extends Ref<T> {
|
|
30
|
-
readonly
|
|
31
|
-
readonly
|
|
32
|
-
constructor(owner: any, name: string,
|
|
30
|
+
readonly valueOn: T;
|
|
31
|
+
readonly valueOff: T;
|
|
32
|
+
constructor(owner: any, name: string, valueOn: T, valueOff: T);
|
|
33
33
|
toggle(): void;
|
|
34
34
|
}
|
package/build/dist/source/Ref.js
CHANGED
|
@@ -49,22 +49,22 @@ class Ref {
|
|
|
49
49
|
}
|
|
50
50
|
exports.Ref = Ref;
|
|
51
51
|
class ToggleRef extends Ref {
|
|
52
|
-
constructor(owner, name,
|
|
52
|
+
constructor(owner, name, valueOn, valueOff) {
|
|
53
53
|
super(owner, name);
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
54
|
+
this.valueOn = valueOn;
|
|
55
|
+
this.valueOff = valueOff;
|
|
56
56
|
}
|
|
57
57
|
toggle() {
|
|
58
58
|
const o = this.owner;
|
|
59
59
|
const p = this.name;
|
|
60
60
|
Transaction_1.Transaction.runAs({ hint: `toggle ${o.constructor.name}.${p}` }, () => {
|
|
61
61
|
const v = o[p];
|
|
62
|
-
const
|
|
63
|
-
Ref.sameRefs(v, this.
|
|
64
|
-
if (!
|
|
65
|
-
o[p] = this.
|
|
62
|
+
const isOn = v === this.valueOn || (v instanceof Ref && this.valueOn instanceof Ref &&
|
|
63
|
+
Ref.sameRefs(v, this.valueOn));
|
|
64
|
+
if (!isOn)
|
|
65
|
+
o[p] = this.valueOn;
|
|
66
66
|
else
|
|
67
|
-
o[p] = this.
|
|
67
|
+
o[p] = this.valueOff;
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -24,10 +24,10 @@ export interface ProfilingOptions {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const TraceLevel: {
|
|
26
26
|
Error: TraceOptions;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
Transactions: TraceOptions;
|
|
28
|
+
Operations: TraceOptions;
|
|
29
29
|
Debug: TraceOptions;
|
|
30
|
-
|
|
30
|
+
Silent: TraceOptions;
|
|
31
31
|
};
|
|
32
32
|
declare global {
|
|
33
33
|
interface Window {
|
|
@@ -20,7 +20,7 @@ exports.TraceLevel = {
|
|
|
20
20
|
margin1: 0,
|
|
21
21
|
margin2: 0,
|
|
22
22
|
},
|
|
23
|
-
|
|
23
|
+
Transactions: {
|
|
24
24
|
silent: false,
|
|
25
25
|
transaction: true,
|
|
26
26
|
operation: false,
|
|
@@ -38,7 +38,7 @@ exports.TraceLevel = {
|
|
|
38
38
|
margin1: 0,
|
|
39
39
|
margin2: 0,
|
|
40
40
|
},
|
|
41
|
-
|
|
41
|
+
Operations: {
|
|
42
42
|
silent: false,
|
|
43
43
|
transaction: true,
|
|
44
44
|
operation: true,
|
|
@@ -74,7 +74,7 @@ exports.TraceLevel = {
|
|
|
74
74
|
margin1: 0,
|
|
75
75
|
margin2: 0,
|
|
76
76
|
},
|
|
77
|
-
|
|
77
|
+
Silent: {
|
|
78
78
|
silent: true,
|
|
79
79
|
transaction: false,
|
|
80
80
|
operation: false,
|
|
@@ -12,7 +12,7 @@ const Hooks_1 = require("./Hooks");
|
|
|
12
12
|
const TransactionJournal_1 = require("./TransactionJournal");
|
|
13
13
|
const ROOT_ARGS = [];
|
|
14
14
|
const ROOT_HOLDER = new Data_1.ObjectHolder(undefined, undefined, Hooks_1.Hooks.proxy, Snapshot_1.ROOT_REV, 'root-holder');
|
|
15
|
-
const
|
|
15
|
+
const ROOT_TRIGGER = { revision: Snapshot_1.ROOT_REV, memberName: 'root-trigger', usageCount: 0 };
|
|
16
16
|
class OperationController extends Controller_1.Controller {
|
|
17
17
|
constructor(ownHolder, memberName) {
|
|
18
18
|
super();
|
|
@@ -35,7 +35,7 @@ class OperationController extends Controller_1.Controller {
|
|
|
35
35
|
const op = oc.operation;
|
|
36
36
|
const opts = op.options;
|
|
37
37
|
if (!oc.isUpToDate && oc.revision.data[Data_1.Meta.Disposed] === undefined
|
|
38
|
-
&& (!weak || op.cause ===
|
|
38
|
+
&& (!weak || op.cause === ROOT_TRIGGER || !op.successor ||
|
|
39
39
|
op.successor.transaction.isFinished)) {
|
|
40
40
|
const standalone = weak || opts.kind === Options_1.Kind.Reaction ||
|
|
41
41
|
(opts.kind === Options_1.Kind.Cache && (oc.revision.snapshot.sealed ||
|
|
@@ -69,7 +69,7 @@ class OperationController extends Controller_1.Controller {
|
|
|
69
69
|
throw (0, Dbg_1.misuse)('a method is expected with reactronic decorator');
|
|
70
70
|
op.options = new Hooks_1.OptionsImpl(op.options.getter, op.options.setter, op.options, options, false);
|
|
71
71
|
if (Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.write)
|
|
72
|
-
Dbg_1.Dbg.log('║', '
|
|
72
|
+
Dbg_1.Dbg.log('║', ' ✎', `${op.hint()}.options = ...`);
|
|
73
73
|
return op.options;
|
|
74
74
|
}
|
|
75
75
|
static runWithin(op, func, ...args) {
|
|
@@ -105,7 +105,7 @@ class OperationController extends Controller_1.Controller {
|
|
|
105
105
|
const ctx = Snapshot_1.Snapshot.current();
|
|
106
106
|
const r = ctx.seekRevision(this.ownHolder, this.memberName);
|
|
107
107
|
const op = this.peekFromRevision(r);
|
|
108
|
-
const isValid = op.options.kind !== Options_1.Kind.Transaction && op.cause !==
|
|
108
|
+
const isValid = op.options.kind !== Options_1.Kind.Transaction && op.cause !== ROOT_TRIGGER &&
|
|
109
109
|
(ctx === op.revision.snapshot || ctx.timestamp < op.obsoleteSince) &&
|
|
110
110
|
(!op.options.sensitiveArgs || args === undefined ||
|
|
111
111
|
op.args.length === args.length && op.args.every((t, i) => t === args[i])) ||
|
|
@@ -144,7 +144,7 @@ class OperationController extends Controller_1.Controller {
|
|
|
144
144
|
if (op2.controller !== this) {
|
|
145
145
|
r2 = Snapshot_1.Snapshot.edit().getEditableRevision(h, m, Data_1.Meta.Holder, this);
|
|
146
146
|
op2 = r2.data[m] = new Operation(this, r2, op2);
|
|
147
|
-
op2.cause =
|
|
147
|
+
op2.cause = ROOT_TRIGGER;
|
|
148
148
|
Snapshot_1.Snapshot.markEdited(op2, true, r2, m, h);
|
|
149
149
|
}
|
|
150
150
|
return op2;
|
|
@@ -160,7 +160,7 @@ class OperationController extends Controller_1.Controller {
|
|
|
160
160
|
if (!oc.operation.transaction.isCanceled) {
|
|
161
161
|
oc = this.edit();
|
|
162
162
|
if (Dbg_1.Dbg.isOn && (Dbg_1.Dbg.trace.transaction || Dbg_1.Dbg.trace.operation || Dbg_1.Dbg.trace.obsolete))
|
|
163
|
-
Dbg_1.Dbg.log('║', '
|
|
163
|
+
Dbg_1.Dbg.log('║', ' 𝑓', `${oc.operation.why()}`);
|
|
164
164
|
oc.operation.run(this.ownHolder.proxy, argsx);
|
|
165
165
|
}
|
|
166
166
|
else {
|
|
@@ -168,7 +168,7 @@ class OperationController extends Controller_1.Controller {
|
|
|
168
168
|
if (oc.operation.options.kind === Options_1.Kind.Transaction || !oc.isUpToDate) {
|
|
169
169
|
oc = this.edit();
|
|
170
170
|
if (Dbg_1.Dbg.isOn && (Dbg_1.Dbg.trace.transaction || Dbg_1.Dbg.trace.operation || Dbg_1.Dbg.trace.obsolete))
|
|
171
|
-
Dbg_1.Dbg.log('║', '
|
|
171
|
+
Dbg_1.Dbg.log('║', ' 𝑓', `${oc.operation.why()}`);
|
|
172
172
|
oc.operation.run(this.ownHolder.proxy, argsx);
|
|
173
173
|
}
|
|
174
174
|
}
|
|
@@ -215,14 +215,14 @@ class Operation extends Data_1.Observable {
|
|
|
215
215
|
const prev = this.revision.prev.revision.data[this.controller.memberName];
|
|
216
216
|
if (prev instanceof Operation)
|
|
217
217
|
ms = prev.started !== 0 ? Math.abs(this.started || ms) - Math.abs(prev.started) : Infinity;
|
|
218
|
-
let
|
|
218
|
+
let trigger;
|
|
219
219
|
if (this.cause)
|
|
220
|
-
|
|
220
|
+
trigger = ` << ${propagationHint(this.cause, true).join(' << ')}`;
|
|
221
221
|
else if (this.controller.options.kind === Options_1.Kind.Transaction)
|
|
222
|
-
|
|
222
|
+
trigger = ' << operation';
|
|
223
223
|
else
|
|
224
|
-
|
|
225
|
-
return `${this.hint()}${
|
|
224
|
+
trigger = ` << called within ${this.revision.snapshot.hint}`;
|
|
225
|
+
return `${this.hint()}${trigger} (${ms !== Infinity ? `${ms}ms since previous run` : 'initial run'})`;
|
|
226
226
|
}
|
|
227
227
|
briefWhy() {
|
|
228
228
|
return this.cause ? propagationHint(this.cause, false)[0] : ROOT_HOLDER.hint;
|
|
@@ -443,12 +443,12 @@ class Operation extends Data_1.Observable {
|
|
|
443
443
|
static markEdited(value, edited, r, m, h) {
|
|
444
444
|
edited ? r.changes.set(m, Operation.current) : r.changes.delete(m);
|
|
445
445
|
if (Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.write)
|
|
446
|
-
edited ? Dbg_1.Dbg.log('║', '
|
|
446
|
+
edited ? Dbg_1.Dbg.log('║', ' ✎', `${Snapshot_1.Dump.rev(r, m)} = ${valueHint(value)}`) : Dbg_1.Dbg.log('║', ' ✎', `${Snapshot_1.Dump.rev(r, m)} = ${valueHint(value)}`, undefined, ' (same as previous)');
|
|
447
447
|
}
|
|
448
448
|
static isConflicting(oldValue, newValue) {
|
|
449
449
|
let result = oldValue !== newValue;
|
|
450
450
|
if (result)
|
|
451
|
-
result = oldValue instanceof Operation && oldValue.cause !==
|
|
451
|
+
result = oldValue instanceof Operation && oldValue.cause !== ROOT_TRIGGER;
|
|
452
452
|
return result;
|
|
453
453
|
}
|
|
454
454
|
static propagateAllChangesThroughSubscriptions(snapshot) {
|
|
@@ -569,7 +569,7 @@ class Operation extends Data_1.Observable {
|
|
|
569
569
|
}
|
|
570
570
|
static init() {
|
|
571
571
|
Object.freeze(ROOT_ARGS);
|
|
572
|
-
Object.freeze(
|
|
572
|
+
Object.freeze(ROOT_TRIGGER);
|
|
573
573
|
Dbg_1.Dbg.getMergedTraceOptions = getMergedTraceOptions;
|
|
574
574
|
Snapshot_1.Snapshot.markUsed = Operation.markUsed;
|
|
575
575
|
Snapshot_1.Snapshot.markEdited = Operation.markEdited;
|
|
@@ -27,7 +27,7 @@ class Dbg {
|
|
|
27
27
|
const t = Dbg.global;
|
|
28
28
|
const o = Object.keys(Dbg.global).filter(x => t[x] === true).join(', ');
|
|
29
29
|
Dbg.log('', '', `Reactronic trace is enabled: ${o}`);
|
|
30
|
-
Dbg.log('', '', 'Method-level trace can be configured with @trace decorator');
|
|
30
|
+
Dbg.log('', '', 'Method-level trace can be configured with @options({ trace: ... }) decorator');
|
|
31
31
|
}
|
|
32
32
|
else
|
|
33
33
|
Dbg.log('', '', 'Reactronic trace is disabled');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactronic",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.520",
|
|
4
4
|
"description": "Reactronic - Transactional Reactive State Management",
|
|
5
5
|
"main": "build/dist/source/api.js",
|
|
6
6
|
"types": "build/dist/source/api.d.ts",
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/nezaboodka/reactronic/blob/master/README.md#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "16.10
|
|
33
|
-
"@types/react": "17.0.
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "4.
|
|
35
|
-
"@typescript-eslint/parser": "4.
|
|
32
|
+
"@types/node": "16.11.10",
|
|
33
|
+
"@types/react": "17.0.37",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "5.4.0",
|
|
35
|
+
"@typescript-eslint/parser": "5.4.0",
|
|
36
36
|
"ava": "3.15.0",
|
|
37
|
-
"eslint": "
|
|
37
|
+
"eslint": "8.3.0",
|
|
38
38
|
"nyc": "15.1.0",
|
|
39
39
|
"react": "17.0.2",
|
|
40
|
-
"ts-node": "10.
|
|
41
|
-
"tsconfig-paths": "3.
|
|
40
|
+
"ts-node": "10.4.0",
|
|
41
|
+
"tsconfig-paths": "3.12.0",
|
|
42
42
|
"typescript": "4.4.3"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|