reactronic 0.21.524 → 0.21.528
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/impl/Operation.d.ts +4 -1
- package/build/dist/source/impl/Operation.js +27 -5
- package/build/dist/source/impl/Snapshot.d.ts +1 -0
- package/build/dist/source/impl/Snapshot.js +1 -0
- package/build/dist/source/impl/Transaction.d.ts +2 -2
- package/build/dist/source/impl/Transaction.js +15 -18
- package/package.json +1 -1
|
@@ -34,7 +34,8 @@ export declare class OperationController extends Controller<any> {
|
|
|
34
34
|
}
|
|
35
35
|
declare class Operation extends Observable implements Observer {
|
|
36
36
|
static current?: Operation;
|
|
37
|
-
static
|
|
37
|
+
static queuedReactions: Array<Observer>;
|
|
38
|
+
static deferredReactions: Array<Operation>;
|
|
38
39
|
readonly margin: number;
|
|
39
40
|
readonly transaction: Transaction;
|
|
40
41
|
readonly controller: OperationController;
|
|
@@ -62,6 +63,7 @@ declare class Operation extends Observable implements Observer {
|
|
|
62
63
|
run(proxy: any, args: any[] | undefined): void;
|
|
63
64
|
markObsoleteDueTo(observable: Observable, cause: MemberInfo, since: number, reactions: Observer[]): void;
|
|
64
65
|
runIfNotUpToDate(now: boolean, nothrow: boolean): void;
|
|
66
|
+
isNotUpToDate(): boolean;
|
|
65
67
|
reenterOver(head: Operation): this;
|
|
66
68
|
private static run;
|
|
67
69
|
private enter;
|
|
@@ -77,6 +79,7 @@ declare class Operation extends Observable implements Observer {
|
|
|
77
79
|
private static propagateAllChangesThroughSubscriptions;
|
|
78
80
|
private static revokeAllSubscriptions;
|
|
79
81
|
private static propagateMemberChangeThroughSubscriptions;
|
|
82
|
+
private static enqueueDetectedReactions;
|
|
80
83
|
private unsubscribeFromAllObservables;
|
|
81
84
|
private subscribeTo;
|
|
82
85
|
private static canSubscribe;
|
|
@@ -107,7 +107,7 @@ class OperationController extends Controller_1.Controller {
|
|
|
107
107
|
peek(args) {
|
|
108
108
|
const ctx = Snapshot_1.Snapshot.current();
|
|
109
109
|
const r = ctx.seekRevision(this.ownHolder, this.memberName);
|
|
110
|
-
const op = this.peekFromRevision(r);
|
|
110
|
+
const op = this.peekFromRevision(r, args);
|
|
111
111
|
const isValid = op.options.kind !== Options_1.Kind.Transaction && op.cause !== ROOT_TRIGGER &&
|
|
112
112
|
(ctx === op.revision.snapshot || ctx.timestamp < op.obsoleteSince) &&
|
|
113
113
|
(!op.options.sensitiveArgs || args === undefined ||
|
|
@@ -125,7 +125,7 @@ class OperationController extends Controller_1.Controller {
|
|
|
125
125
|
const m = this.memberName;
|
|
126
126
|
const ctx = Snapshot_1.Snapshot.edit();
|
|
127
127
|
const r = ctx.getEditableRevision(h, m, Data_1.Meta.Holder, this);
|
|
128
|
-
let op = this.peekFromRevision(r);
|
|
128
|
+
let op = this.peekFromRevision(r, undefined);
|
|
129
129
|
if (op.revision !== r) {
|
|
130
130
|
const op2 = new Operation(this, r, op);
|
|
131
131
|
r.data[m] = op2.reenterOver(op);
|
|
@@ -135,7 +135,7 @@ class OperationController extends Controller_1.Controller {
|
|
|
135
135
|
}
|
|
136
136
|
return { operation: op, isUpToDate: true, snapshot: ctx, revision: r };
|
|
137
137
|
}
|
|
138
|
-
peekFromRevision(r) {
|
|
138
|
+
peekFromRevision(r, args) {
|
|
139
139
|
const m = this.memberName;
|
|
140
140
|
let op = r.data[m];
|
|
141
141
|
if (op.controller !== this) {
|
|
@@ -148,6 +148,8 @@ class OperationController extends Controller_1.Controller {
|
|
|
148
148
|
if (op2.controller !== this) {
|
|
149
149
|
r2 = Snapshot_1.Snapshot.edit().getEditableRevision(h, m, Data_1.Meta.Holder, this);
|
|
150
150
|
const t = new Operation(this, r2, op2);
|
|
151
|
+
if (args)
|
|
152
|
+
t.args = args;
|
|
151
153
|
t.cause = ROOT_TRIGGER;
|
|
152
154
|
r2.data[m] = t;
|
|
153
155
|
Snapshot_1.Snapshot.markEdited(op2, t, true, r2, m, h);
|
|
@@ -296,8 +298,7 @@ class Operation extends Data_1.Observable {
|
|
|
296
298
|
const interval = Date.now() + this.started;
|
|
297
299
|
const hold = t ? t - interval : 0;
|
|
298
300
|
if (now || hold < 0) {
|
|
299
|
-
if (
|
|
300
|
-
!this.successor || this.successor.transaction.isCanceled)) {
|
|
301
|
+
if (this.isNotUpToDate()) {
|
|
301
302
|
try {
|
|
302
303
|
const op = this.controller.useOrRun(false, undefined);
|
|
303
304
|
if (op.result instanceof Promise)
|
|
@@ -321,6 +322,10 @@ class Operation extends Data_1.Observable {
|
|
|
321
322
|
this.addToDeferredReactions();
|
|
322
323
|
}
|
|
323
324
|
}
|
|
325
|
+
isNotUpToDate() {
|
|
326
|
+
return !this.error && (this.options.kind === Options_1.Kind.Transaction ||
|
|
327
|
+
!this.successor || this.successor.transaction.isCanceled);
|
|
328
|
+
}
|
|
324
329
|
reenterOver(head) {
|
|
325
330
|
let error = undefined;
|
|
326
331
|
const opponent = head.successor;
|
|
@@ -514,6 +519,21 @@ class Operation extends Data_1.Observable {
|
|
|
514
519
|
curr.observers = undefined;
|
|
515
520
|
}
|
|
516
521
|
}
|
|
522
|
+
static enqueueDetectedReactions(snapshot) {
|
|
523
|
+
const queue = Operation.queuedReactions;
|
|
524
|
+
const isRoot = queue.length === 0;
|
|
525
|
+
for (const r of snapshot.reactions)
|
|
526
|
+
queue.push(r);
|
|
527
|
+
if (isRoot) {
|
|
528
|
+
let i = 0;
|
|
529
|
+
while (i < queue.length) {
|
|
530
|
+
const reaction = queue[i];
|
|
531
|
+
reaction.runIfNotUpToDate(false, true);
|
|
532
|
+
i++;
|
|
533
|
+
}
|
|
534
|
+
Operation.queuedReactions = [];
|
|
535
|
+
}
|
|
536
|
+
}
|
|
517
537
|
unsubscribeFromAllObservables() {
|
|
518
538
|
var _a;
|
|
519
539
|
(_a = this.observables) === null || _a === void 0 ? void 0 : _a.forEach((hint, value) => {
|
|
@@ -590,6 +610,7 @@ class Operation extends Data_1.Observable {
|
|
|
590
610
|
Snapshot_1.Snapshot.isConflicting = Operation.isConflicting;
|
|
591
611
|
Snapshot_1.Snapshot.propagateAllChangesThroughSubscriptions = Operation.propagateAllChangesThroughSubscriptions;
|
|
592
612
|
Snapshot_1.Snapshot.revokeAllSubscriptions = Operation.revokeAllSubscriptions;
|
|
613
|
+
Snapshot_1.Snapshot.enqueueDetectedReactions = Operation.enqueueDetectedReactions;
|
|
593
614
|
Hooks_1.Hooks.createControllerAndGetHook = Operation.createControllerAndGetHook;
|
|
594
615
|
Hooks_1.Hooks.rememberOperationOptions = Operation.rememberOperationOptions;
|
|
595
616
|
Promise.prototype.then = reactronicHookedThen;
|
|
@@ -616,6 +637,7 @@ class Operation extends Data_1.Observable {
|
|
|
616
637
|
}
|
|
617
638
|
}
|
|
618
639
|
Operation.current = undefined;
|
|
640
|
+
Operation.queuedReactions = [];
|
|
619
641
|
Operation.deferredReactions = [];
|
|
620
642
|
function propagationHint(cause, full) {
|
|
621
643
|
const result = [];
|
|
@@ -28,6 +28,7 @@ export declare class Snapshot implements AbstractSnapshot {
|
|
|
28
28
|
static isConflicting: (oldValue: any, newValue: any) => boolean;
|
|
29
29
|
static propagateAllChangesThroughSubscriptions: (snapshot: Snapshot) => void;
|
|
30
30
|
static revokeAllSubscriptions: (snapshot: Snapshot) => void;
|
|
31
|
+
static enqueueDetectedReactions: (snapshot: Snapshot) => void;
|
|
31
32
|
seekRevision(h: ObjectHolder, m: MemberName): ObjectRevision;
|
|
32
33
|
getCurrentRevision(h: ObjectHolder, m: MemberName): ObjectRevision;
|
|
33
34
|
getEditableRevision(h: ObjectHolder, m: MemberName, value: any, token?: any): ObjectRevision;
|
|
@@ -309,6 +309,7 @@ Snapshot.markEdited = Utils_1.UNDEF;
|
|
|
309
309
|
Snapshot.isConflicting = Utils_1.UNDEF;
|
|
310
310
|
Snapshot.propagateAllChangesThroughSubscriptions = (snapshot) => { };
|
|
311
311
|
Snapshot.revokeAllSubscriptions = (snapshot) => { };
|
|
312
|
+
Snapshot.enqueueDetectedReactions = (snapshot) => { };
|
|
312
313
|
class Dump {
|
|
313
314
|
static obj(h, m, stamp, op, xop, typeless) {
|
|
314
315
|
const member = m !== undefined ? `.${m.toString()}` : '';
|
|
@@ -24,7 +24,7 @@ export declare abstract class Transaction implements Worker {
|
|
|
24
24
|
static run<T>(func: F<T>, ...args: any[]): T;
|
|
25
25
|
static runAs<T>(options: SnapshotOptions | null, func: F<T>, ...args: any[]): T;
|
|
26
26
|
static standalone<T>(func: F<T>, ...args: any[]): T;
|
|
27
|
-
static
|
|
28
|
-
static
|
|
27
|
+
static isFrameOver(everyN?: number, timeLimit?: number): boolean;
|
|
28
|
+
static requestNextFrame(sleepTime?: number): Promise<void>;
|
|
29
29
|
static get isCanceled(): boolean;
|
|
30
30
|
}
|
|
@@ -22,8 +22,8 @@ class Transaction {
|
|
|
22
22
|
static run(func, ...args) { return TransactionImpl.run(func, ...args); }
|
|
23
23
|
static runAs(options, func, ...args) { return TransactionImpl.runAs(options, func, ...args); }
|
|
24
24
|
static standalone(func, ...args) { return TransactionImpl.standalone(func, ...args); }
|
|
25
|
-
static
|
|
26
|
-
static
|
|
25
|
+
static isFrameOver(everyN = 1, timeLimit = 14) { return TransactionImpl.isFrameOver(everyN, timeLimit); }
|
|
26
|
+
static requestNextFrame(sleepTime = 0) { return TransactionImpl.requestNextFrame(sleepTime); }
|
|
27
27
|
static get isCanceled() { return TransactionImpl.current.isCanceled; }
|
|
28
28
|
}
|
|
29
29
|
exports.Transaction = Transaction;
|
|
@@ -124,10 +124,11 @@ class TransactionImpl extends Transaction {
|
|
|
124
124
|
t.guard();
|
|
125
125
|
let result = t.runImpl(options === null || options === void 0 ? void 0 : options.trace, func, ...args);
|
|
126
126
|
if (root) {
|
|
127
|
-
if (result instanceof Promise)
|
|
127
|
+
if (result instanceof Promise) {
|
|
128
128
|
result = TransactionImpl.standalone(() => {
|
|
129
129
|
return t.wrapToRetry(t.wrapToWaitUntilFinish(result), func, ...args);
|
|
130
130
|
});
|
|
131
|
+
}
|
|
131
132
|
t.seal();
|
|
132
133
|
}
|
|
133
134
|
return result;
|
|
@@ -142,16 +143,16 @@ class TransactionImpl extends Transaction {
|
|
|
142
143
|
TransactionImpl.curr = outer;
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
|
-
static
|
|
146
|
-
TransactionImpl.
|
|
147
|
-
let result = TransactionImpl.
|
|
146
|
+
static isFrameOver(everyN = 1, timeLimit = 14) {
|
|
147
|
+
TransactionImpl.frameOverCounter++;
|
|
148
|
+
let result = TransactionImpl.frameOverCounter % everyN === 0;
|
|
148
149
|
if (result) {
|
|
149
|
-
const ms = performance.now() - TransactionImpl.
|
|
150
|
-
result = ms >
|
|
150
|
+
const ms = performance.now() - TransactionImpl.frameStartTime;
|
|
151
|
+
result = ms > timeLimit;
|
|
151
152
|
}
|
|
152
153
|
return result;
|
|
153
154
|
}
|
|
154
|
-
static
|
|
155
|
+
static requestNextFrame(sleepTime = 0) {
|
|
155
156
|
return (0, Utils_1.pause)(sleepTime);
|
|
156
157
|
}
|
|
157
158
|
static acquire(options) {
|
|
@@ -205,8 +206,8 @@ class TransactionImpl extends Transaction {
|
|
|
205
206
|
const outer = TransactionImpl.curr;
|
|
206
207
|
try {
|
|
207
208
|
if (outer === TransactionImpl.none) {
|
|
208
|
-
TransactionImpl.
|
|
209
|
-
TransactionImpl.
|
|
209
|
+
TransactionImpl.frameStartTime = performance.now();
|
|
210
|
+
TransactionImpl.frameOverCounter = 0;
|
|
210
211
|
}
|
|
211
212
|
TransactionImpl.curr = this;
|
|
212
213
|
this.pending++;
|
|
@@ -229,16 +230,13 @@ class TransactionImpl extends Transaction {
|
|
|
229
230
|
if (this.sealed && this.pending === 0) {
|
|
230
231
|
this.applyOrDiscard();
|
|
231
232
|
TransactionImpl.curr = outer;
|
|
232
|
-
TransactionImpl.standalone(
|
|
233
|
+
TransactionImpl.standalone(Snapshot_1.Snapshot.enqueueDetectedReactions, this.snapshot);
|
|
233
234
|
}
|
|
234
235
|
else
|
|
235
236
|
TransactionImpl.curr = outer;
|
|
236
237
|
}
|
|
237
238
|
return result;
|
|
238
239
|
}
|
|
239
|
-
static runReactions(t) {
|
|
240
|
-
t.snapshot.reactions.forEach(x => x.runIfNotUpToDate(false, true));
|
|
241
|
-
}
|
|
242
240
|
static seal(t, error, after) {
|
|
243
241
|
if (!t.canceled && error) {
|
|
244
242
|
t.canceled = error;
|
|
@@ -308,7 +306,6 @@ class TransactionImpl extends Transaction {
|
|
|
308
306
|
TransactionImpl.none = new TransactionImpl({ hint: '<none>' });
|
|
309
307
|
TransactionImpl.curr = TransactionImpl.none;
|
|
310
308
|
TransactionImpl.inspection = false;
|
|
311
|
-
TransactionImpl.
|
|
312
|
-
TransactionImpl.
|
|
313
|
-
TransactionImpl.checkCount = 0;
|
|
309
|
+
TransactionImpl.frameStartTime = 0;
|
|
310
|
+
TransactionImpl.frameOverCounter = 0;
|
|
314
311
|
TransactionImpl._init();
|