reactronic 0.22.103 → 0.22.107
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 -2
- package/build/dist/source/Rx.d.ts +0 -1
- package/build/dist/source/Rx.js +1 -6
- package/build/dist/source/api.d.ts +2 -2
- package/build/dist/source/api.js +1 -2
- package/build/dist/source/impl/Data.d.ts +5 -7
- package/build/dist/source/impl/Data.js +1 -1
- package/build/dist/source/impl/Operation.d.ts +3 -3
- package/build/dist/source/impl/Operation.js +7 -7
- package/build/dist/source/impl/Snapshot.d.ts +2 -2
- package/build/dist/source/impl/Snapshot.js +14 -12
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -196,7 +196,7 @@ class Component<P> extends React.Component<P> {
|
|
|
196
196
|
@reaction // called immediately in response to changes
|
|
197
197
|
ensureUpToDate(): void {
|
|
198
198
|
if (this.shouldComponentUpdate())
|
|
199
|
-
|
|
199
|
+
Transaction.off(() => this.setState({})) // ask React to re-render
|
|
200
200
|
} // ensureUpToDate is subscribed to render
|
|
201
201
|
|
|
202
202
|
shouldComponentUpdate(): boolean {
|
|
@@ -310,7 +310,6 @@ function monitor(value: Monitor | null)
|
|
|
310
310
|
function trace(value: Partial<TraceOptions>)
|
|
311
311
|
|
|
312
312
|
function nonreactive<T>(func: F<T>, ...args: any[]): T
|
|
313
|
-
function nontransactional<T>(func: F<T>, ...args: any[]): T
|
|
314
313
|
function sensitive<T>(sensitivity: Sensitivity, func: F<T>, ...args: any[]): T
|
|
315
314
|
|
|
316
315
|
// Options, ObjectOptions, Kind, Reentrance, Monitor, TraceOptions, ProfilingOptions
|
|
@@ -18,7 +18,6 @@ export declare class Rx {
|
|
|
18
18
|
static setProfilingMode(enabled: boolean, options?: Partial<ProfilingOptions>): void;
|
|
19
19
|
}
|
|
20
20
|
export declare function nonreactive<T>(func: F<T>, ...args: any[]): T;
|
|
21
|
-
export declare function nontransactional<T>(func: F<T>, ...args: any[]): T;
|
|
22
21
|
export declare function sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
|
|
23
22
|
export declare function unobservable(proto: object, prop: PropertyKey): any;
|
|
24
23
|
export declare function transaction(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
|
package/build/dist/source/Rx.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.options = exports.cached = exports.reaction = exports.transaction = exports.unobservable = exports.sensitive = exports.
|
|
3
|
+
exports.options = exports.cached = exports.reaction = exports.transaction = exports.unobservable = exports.sensitive = exports.nonreactive = exports.Rx = void 0;
|
|
4
4
|
const Dbg_1 = require("./util/Dbg");
|
|
5
5
|
const Options_1 = require("./Options");
|
|
6
6
|
const Data_1 = require("./impl/Data");
|
|
7
7
|
const Snapshot_1 = require("./impl/Snapshot");
|
|
8
8
|
const Hooks_1 = require("./impl/Hooks");
|
|
9
9
|
const Operation_1 = require("./impl/Operation");
|
|
10
|
-
const Transaction_1 = require("./impl/Transaction");
|
|
11
10
|
class Rx {
|
|
12
11
|
static why(brief = false) { return brief ? Operation_1.OperationController.briefWhy() : Operation_1.OperationController.why(); }
|
|
13
12
|
static getController(method) { return Operation_1.OperationController.of(method); }
|
|
@@ -29,10 +28,6 @@ function nonreactive(func, ...args) {
|
|
|
29
28
|
return Operation_1.OperationController.runWithin(undefined, func, ...args);
|
|
30
29
|
}
|
|
31
30
|
exports.nonreactive = nonreactive;
|
|
32
|
-
function nontransactional(func, ...args) {
|
|
33
|
-
return Transaction_1.Transaction.off(func, ...args);
|
|
34
|
-
}
|
|
35
|
-
exports.nontransactional = nontransactional;
|
|
36
31
|
function sensitive(sensitivity, func, ...args) {
|
|
37
32
|
return Hooks_1.Hooks.sensitive(sensitivity, func, ...args);
|
|
38
33
|
}
|
|
@@ -2,7 +2,7 @@ export { all, pause } from './util/Utils';
|
|
|
2
2
|
export { SealedArray } from './util/SealedArray';
|
|
3
3
|
export { SealedMap } from './util/SealedMap';
|
|
4
4
|
export { SealedSet } from './util/SealedSet';
|
|
5
|
-
export { MemberOptions, Kind, Reentrance, TraceOptions, ProfilingOptions, TraceLevel } from './Options';
|
|
5
|
+
export { MemberOptions, SnapshotOptions, Kind, Reentrance, TraceOptions, ProfilingOptions, TraceLevel } from './Options';
|
|
6
6
|
export { Worker } from './Worker';
|
|
7
7
|
export { Controller } from './Controller';
|
|
8
8
|
export { Ref, ToggleRef, BoolOnly, GivenTypeOnly } from './Ref';
|
|
@@ -11,4 +11,4 @@ export { Snapshot } from './impl/Snapshot';
|
|
|
11
11
|
export { Transaction } from './impl/Transaction';
|
|
12
12
|
export { Monitor } from './impl/Monitor';
|
|
13
13
|
export { TransactionJournal } from './impl/TransactionJournal';
|
|
14
|
-
export { Rx, nonreactive,
|
|
14
|
+
export { Rx, nonreactive, sensitive, unobservable, transaction, reaction, cached, options } from './Rx';
|
package/build/dist/source/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.options = exports.cached = exports.reaction = exports.transaction = exports.unobservable = exports.sensitive = exports.
|
|
3
|
+
exports.options = exports.cached = exports.reaction = exports.transaction = exports.unobservable = exports.sensitive = exports.nonreactive = exports.Rx = exports.TransactionJournal = exports.Monitor = exports.Transaction = exports.Snapshot = exports.ObservableObject = exports.ToggleRef = exports.Ref = exports.Controller = exports.TraceLevel = exports.Reentrance = exports.Kind = exports.SealedSet = exports.SealedMap = exports.SealedArray = exports.pause = exports.all = void 0;
|
|
4
4
|
var Utils_1 = require("./util/Utils");
|
|
5
5
|
Object.defineProperty(exports, "all", { enumerable: true, get: function () { return Utils_1.all; } });
|
|
6
6
|
Object.defineProperty(exports, "pause", { enumerable: true, get: function () { return Utils_1.pause; } });
|
|
@@ -32,7 +32,6 @@ Object.defineProperty(exports, "TransactionJournal", { enumerable: true, get: fu
|
|
|
32
32
|
var Rx_1 = require("./Rx");
|
|
33
33
|
Object.defineProperty(exports, "Rx", { enumerable: true, get: function () { return Rx_1.Rx; } });
|
|
34
34
|
Object.defineProperty(exports, "nonreactive", { enumerable: true, get: function () { return Rx_1.nonreactive; } });
|
|
35
|
-
Object.defineProperty(exports, "nontransactional", { enumerable: true, get: function () { return Rx_1.nontransactional; } });
|
|
36
35
|
Object.defineProperty(exports, "sensitive", { enumerable: true, get: function () { return Rx_1.sensitive; } });
|
|
37
36
|
Object.defineProperty(exports, "unobservable", { enumerable: true, get: function () { return Rx_1.unobservable; } });
|
|
38
37
|
Object.defineProperty(exports, "transaction", { enumerable: true, get: function () { return Rx_1.transaction; } });
|
|
@@ -9,23 +9,21 @@ export declare class Observable {
|
|
|
9
9
|
value: any;
|
|
10
10
|
observers?: Set<Observer>;
|
|
11
11
|
get isOperation(): boolean;
|
|
12
|
-
get
|
|
12
|
+
get originSnapshotId(): number | undefined;
|
|
13
13
|
constructor(value: any);
|
|
14
14
|
}
|
|
15
|
-
export declare type StandaloneMode = boolean | 'isolated';
|
|
15
|
+
export declare type StandaloneMode = boolean | 'isolated' | 'disposal';
|
|
16
16
|
export interface Observer {
|
|
17
17
|
readonly order: number;
|
|
18
|
-
readonly observables: Map<Observable,
|
|
18
|
+
readonly observables: Map<Observable, ObservableInfo> | undefined;
|
|
19
19
|
readonly obsoleteSince: number;
|
|
20
20
|
hint(nop?: boolean): string;
|
|
21
21
|
markObsoleteDueTo(observable: Observable, memberName: MemberName, snapshot: AbstractSnapshot, holder: ObjectHolder, outer: string, since: number, reactions: Observer[]): void;
|
|
22
22
|
runIfNotUpToDate(now: boolean, nothrow: boolean): void;
|
|
23
23
|
}
|
|
24
24
|
export declare type MemberName = PropertyKey;
|
|
25
|
-
export interface
|
|
26
|
-
readonly
|
|
27
|
-
readonly snapshot: AbstractSnapshot;
|
|
28
|
-
readonly memberName: MemberName;
|
|
25
|
+
export interface ObservableInfo {
|
|
26
|
+
readonly memberHint: string;
|
|
29
27
|
readonly usageCount: number;
|
|
30
28
|
}
|
|
31
29
|
export declare class ObjectRevision {
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "Meta", { enumerable: true, get: function () { re
|
|
|
8
8
|
class Observable {
|
|
9
9
|
constructor(value) { this.value = value; }
|
|
10
10
|
get isOperation() { return false; }
|
|
11
|
-
get
|
|
11
|
+
get originSnapshotId() { return 0; }
|
|
12
12
|
}
|
|
13
13
|
exports.Observable = Observable;
|
|
14
14
|
class ObjectRevision {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { F } from '../util/Utils';
|
|
2
2
|
import { MemberOptions } from '../Options';
|
|
3
3
|
import { Controller } from '../Controller';
|
|
4
|
-
import { MemberName, ObjectHolder, Observable, Observer,
|
|
4
|
+
import { MemberName, ObjectHolder, Observable, Observer, ObservableInfo, AbstractSnapshot } from './Data';
|
|
5
5
|
import { Transaction } from './Transaction';
|
|
6
6
|
import { OptionsImpl } from './Hooks';
|
|
7
7
|
export declare class OperationController extends Controller<any> {
|
|
@@ -40,7 +40,7 @@ declare class Operation extends Observable implements Observer {
|
|
|
40
40
|
readonly transaction: Transaction;
|
|
41
41
|
readonly controller: OperationController;
|
|
42
42
|
readonly snapshot: AbstractSnapshot;
|
|
43
|
-
observables: Map<Observable,
|
|
43
|
+
observables: Map<Observable, ObservableInfo> | undefined;
|
|
44
44
|
options: OptionsImpl;
|
|
45
45
|
cause: string | undefined;
|
|
46
46
|
args: any[];
|
|
@@ -52,7 +52,7 @@ declare class Operation extends Observable implements Observer {
|
|
|
52
52
|
successor: Operation | undefined;
|
|
53
53
|
constructor(controller: OperationController, snapshot: AbstractSnapshot, prev: Operation | OptionsImpl);
|
|
54
54
|
get isOperation(): boolean;
|
|
55
|
-
get
|
|
55
|
+
get originSnapshotId(): number;
|
|
56
56
|
hint(): string;
|
|
57
57
|
get order(): number;
|
|
58
58
|
get ['#this'](): string;
|
|
@@ -216,7 +216,7 @@ class Operation extends Data_1.Observable {
|
|
|
216
216
|
this.successor = undefined;
|
|
217
217
|
}
|
|
218
218
|
get isOperation() { return true; }
|
|
219
|
-
get
|
|
219
|
+
get originSnapshotId() { return this.snapshot.id; }
|
|
220
220
|
hint() { return `${Snapshot_1.Dump.rev2(this.controller.ownHolder, this.snapshot, this.controller.memberName)}`; }
|
|
221
221
|
get order() { return this.options.order; }
|
|
222
222
|
get ['#this']() {
|
|
@@ -510,9 +510,9 @@ class Operation extends Data_1.Observable {
|
|
|
510
510
|
if (curr instanceof Operation) {
|
|
511
511
|
if (curr.snapshot === r.snapshot && curr.observables !== undefined) {
|
|
512
512
|
if (Hooks_1.Hooks.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
|
|
513
|
-
curr.observables.forEach((
|
|
514
|
-
if (
|
|
515
|
-
Dbg_1.Dbg.log('', '[!]', `${curr.hint()} uses ${
|
|
513
|
+
curr.observables.forEach((info, v) => {
|
|
514
|
+
if (info.usageCount > Hooks_1.Hooks.repetitiveUsageWarningThreshold)
|
|
515
|
+
Dbg_1.Dbg.log('', '[!]', `${curr.hint()} uses ${info.memberHint} ${info.usageCount} times (consider remembering it in a local variable)`, 0, ' *** WARNING ***');
|
|
516
516
|
});
|
|
517
517
|
}
|
|
518
518
|
if (unsubscribe)
|
|
@@ -548,11 +548,11 @@ class Operation extends Data_1.Observable {
|
|
|
548
548
|
}
|
|
549
549
|
unsubscribeFromAllObservables() {
|
|
550
550
|
var _a;
|
|
551
|
-
(_a = this.observables) === null || _a === void 0 ? void 0 : _a.forEach((
|
|
551
|
+
(_a = this.observables) === null || _a === void 0 ? void 0 : _a.forEach((info, value) => {
|
|
552
552
|
var _a;
|
|
553
553
|
value.observers.delete(this);
|
|
554
554
|
if (Dbg_1.Dbg.isOn && (Dbg_1.Dbg.trace.read || ((_a = this.options.trace) === null || _a === void 0 ? void 0 : _a.read)))
|
|
555
|
-
Dbg_1.Dbg.log(Dbg_1.Dbg.trace.transaction && !Snapshot_1.Snapshot.current().sealed ? '║' : ' ', '-', `${this.hint()} is unsubscribed from ${
|
|
555
|
+
Dbg_1.Dbg.log(Dbg_1.Dbg.trace.transaction && !Snapshot_1.Snapshot.current().sealed ? '║' : ' ', '-', `${this.hint()} is unsubscribed from ${info.memberHint}`);
|
|
556
556
|
});
|
|
557
557
|
this.observables = undefined;
|
|
558
558
|
}
|
|
@@ -568,7 +568,7 @@ class Operation extends Data_1.Observable {
|
|
|
568
568
|
if (this.observables !== undefined) {
|
|
569
569
|
if (!observable.observers)
|
|
570
570
|
observable.observers = new Set();
|
|
571
|
-
const info = {
|
|
571
|
+
const info = { memberHint: Snapshot_1.Dump.rev2(h, r.snapshot, m), usageCount: times };
|
|
572
572
|
observable.observers.add(this);
|
|
573
573
|
this.observables.set(observable, info);
|
|
574
574
|
if (Dbg_1.Dbg.isOn && (Dbg_1.Dbg.trace.read || ((_a = this.options.trace) === null || _a === void 0 ? void 0 : _a.read)))
|
|
@@ -39,7 +39,7 @@ export declare class Snapshot implements AbstractSnapshot {
|
|
|
39
39
|
acquire(outer: Snapshot): void;
|
|
40
40
|
bumpBy(timestamp: number): void;
|
|
41
41
|
rebase(): ObjectRevision[] | undefined;
|
|
42
|
-
private
|
|
42
|
+
private merge;
|
|
43
43
|
applyOrDiscard(error?: any): Array<Observer>;
|
|
44
44
|
static sealObjectRevision(h: ObjectHolder, r: ObjectRevision): void;
|
|
45
45
|
static sealObservable(observable: Observable | symbol, m: MemberName, typeName: string): void;
|
|
@@ -49,7 +49,7 @@ export declare class Snapshot implements AbstractSnapshot {
|
|
|
49
49
|
static _init(): void;
|
|
50
50
|
}
|
|
51
51
|
export declare class Dump {
|
|
52
|
-
static obj(h: ObjectHolder | undefined, m?: MemberName | undefined, stamp?: number,
|
|
52
|
+
static obj(h: ObjectHolder | undefined, m?: MemberName | undefined, stamp?: number, snapshotId?: number, originSnapshotId?: number, typeless?: boolean): string;
|
|
53
53
|
static rev2(h: ObjectHolder, s: AbstractSnapshot, m?: MemberName, value?: Observable): string;
|
|
54
54
|
static rev(r: ObjectRevision, m?: MemberName): string;
|
|
55
55
|
static conflicts(conflicts: ObjectRevision[]): string;
|
|
@@ -130,7 +130,7 @@ class Snapshot {
|
|
|
130
130
|
if (this.changeset.size > 0) {
|
|
131
131
|
this.changeset.forEach((r, h) => {
|
|
132
132
|
if (r.prev.revision !== h.head) {
|
|
133
|
-
const merged =
|
|
133
|
+
const merged = this.merge(h, r);
|
|
134
134
|
if (r.conflicts.size > 0) {
|
|
135
135
|
if (!conflicts)
|
|
136
136
|
conflicts = [];
|
|
@@ -154,19 +154,21 @@ class Snapshot {
|
|
|
154
154
|
}
|
|
155
155
|
return conflicts;
|
|
156
156
|
}
|
|
157
|
-
|
|
157
|
+
merge(h, ours) {
|
|
158
158
|
let counter = 0;
|
|
159
159
|
const head = h.head;
|
|
160
|
-
const
|
|
160
|
+
const headDisposed = head.changes.has(Data_1.Meta.Disposed);
|
|
161
161
|
const merged = Object.assign({}, head.data);
|
|
162
162
|
ours.changes.forEach((o, m) => {
|
|
163
163
|
counter++;
|
|
164
164
|
merged[m] = ours.data[m];
|
|
165
|
-
if (
|
|
166
|
-
if (
|
|
167
|
-
if (
|
|
168
|
-
Dbg_1.Dbg.
|
|
169
|
-
|
|
165
|
+
if (headDisposed || m === Data_1.Meta.Disposed) {
|
|
166
|
+
if (headDisposed !== (m === Data_1.Meta.Disposed)) {
|
|
167
|
+
if (headDisposed || this.options.standalone !== 'disposal') {
|
|
168
|
+
if (Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.change)
|
|
169
|
+
Dbg_1.Dbg.log('║╠', '', `${Dump.rev2(h, ours.snapshot, m)} <> ${Dump.rev2(h, head.snapshot, m)}`, 0, ' *** CONFLICT ***');
|
|
170
|
+
ours.conflicts.set(m, head);
|
|
171
|
+
}
|
|
170
172
|
}
|
|
171
173
|
}
|
|
172
174
|
else {
|
|
@@ -309,19 +311,19 @@ Snapshot.propagateAllChangesThroughSubscriptions = (snapshot) => { };
|
|
|
309
311
|
Snapshot.revokeAllSubscriptions = (snapshot) => { };
|
|
310
312
|
Snapshot.enqueueReactionsToRun = (reactions) => { };
|
|
311
313
|
class Dump {
|
|
312
|
-
static obj(h, m, stamp,
|
|
314
|
+
static obj(h, m, stamp, snapshotId, originSnapshotId, typeless) {
|
|
313
315
|
const member = m !== undefined ? `.${m.toString()}` : '';
|
|
314
316
|
return h === undefined
|
|
315
317
|
? `root${member}`
|
|
316
|
-
: stamp === undefined ? `${h.hint}${member} #${h.id}` : `${h.hint}${member} #${h.id}t${
|
|
318
|
+
: stamp === undefined ? `${h.hint}${member} #${h.id}` : `${h.hint}${member} #${h.id}t${snapshotId}v${stamp}${originSnapshotId !== undefined && originSnapshotId !== 0 ? `t${originSnapshotId}` : ''}`;
|
|
317
319
|
}
|
|
318
320
|
static rev2(h, s, m, value) {
|
|
319
|
-
return Dump.obj(h, m, s.timestamp, s.id, value === null || value === void 0 ? void 0 : value.
|
|
321
|
+
return Dump.obj(h, m, s.timestamp, s.id, value === null || value === void 0 ? void 0 : value.originSnapshotId);
|
|
320
322
|
}
|
|
321
323
|
static rev(r, m) {
|
|
322
324
|
const h = Data_1.Meta.get(r.data, Data_1.Meta.Holder);
|
|
323
325
|
const value = m !== undefined ? r.data[m] : undefined;
|
|
324
|
-
return Dump.obj(h, m, r.snapshot.timestamp, r.snapshot.id, value === null || value === void 0 ? void 0 : value.
|
|
326
|
+
return Dump.obj(h, m, r.snapshot.timestamp, r.snapshot.id, value === null || value === void 0 ? void 0 : value.originSnapshotId);
|
|
325
327
|
}
|
|
326
328
|
static conflicts(conflicts) {
|
|
327
329
|
return conflicts.map(ours => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactronic",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.107",
|
|
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,12 +29,12 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/nezaboodka/reactronic/blob/master/README.md#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "17.0.
|
|
33
|
-
"@types/react": "17.0.
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
35
|
-
"@typescript-eslint/parser": "5.
|
|
32
|
+
"@types/node": "17.0.7",
|
|
33
|
+
"@types/react": "17.0.38",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "5.9.0",
|
|
35
|
+
"@typescript-eslint/parser": "5.9.0",
|
|
36
36
|
"ava": "3.15.0",
|
|
37
|
-
"eslint": "8.
|
|
37
|
+
"eslint": "8.6.0",
|
|
38
38
|
"nyc": "15.1.0",
|
|
39
39
|
"react": "17.0.2",
|
|
40
40
|
"ts-node": "10.4.0",
|