reactronic 0.21.527 → 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.
@@ -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 deferredReactions: Operation[];
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;
@@ -298,8 +298,7 @@ class Operation extends Data_1.Observable {
298
298
  const interval = Date.now() + this.started;
299
299
  const hold = t ? t - interval : 0;
300
300
  if (now || hold < 0) {
301
- if (!this.error && (this.options.kind === Options_1.Kind.Transaction ||
302
- !this.successor || this.successor.transaction.isCanceled)) {
301
+ if (this.isNotUpToDate()) {
303
302
  try {
304
303
  const op = this.controller.useOrRun(false, undefined);
305
304
  if (op.result instanceof Promise)
@@ -323,6 +322,10 @@ class Operation extends Data_1.Observable {
323
322
  this.addToDeferredReactions();
324
323
  }
325
324
  }
325
+ isNotUpToDate() {
326
+ return !this.error && (this.options.kind === Options_1.Kind.Transaction ||
327
+ !this.successor || this.successor.transaction.isCanceled);
328
+ }
326
329
  reenterOver(head) {
327
330
  let error = undefined;
328
331
  const opponent = head.successor;
@@ -516,6 +519,21 @@ class Operation extends Data_1.Observable {
516
519
  curr.observers = undefined;
517
520
  }
518
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
+ }
519
537
  unsubscribeFromAllObservables() {
520
538
  var _a;
521
539
  (_a = this.observables) === null || _a === void 0 ? void 0 : _a.forEach((hint, value) => {
@@ -592,6 +610,7 @@ class Operation extends Data_1.Observable {
592
610
  Snapshot_1.Snapshot.isConflicting = Operation.isConflicting;
593
611
  Snapshot_1.Snapshot.propagateAllChangesThroughSubscriptions = Operation.propagateAllChangesThroughSubscriptions;
594
612
  Snapshot_1.Snapshot.revokeAllSubscriptions = Operation.revokeAllSubscriptions;
613
+ Snapshot_1.Snapshot.enqueueDetectedReactions = Operation.enqueueDetectedReactions;
595
614
  Hooks_1.Hooks.createControllerAndGetHook = Operation.createControllerAndGetHook;
596
615
  Hooks_1.Hooks.rememberOperationOptions = Operation.rememberOperationOptions;
597
616
  Promise.prototype.then = reactronicHookedThen;
@@ -618,6 +637,7 @@ class Operation extends Data_1.Observable {
618
637
  }
619
638
  }
620
639
  Operation.current = undefined;
640
+ Operation.queuedReactions = [];
621
641
  Operation.deferredReactions = [];
622
642
  function propagationHint(cause, full) {
623
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()}` : '';
@@ -230,16 +230,13 @@ class TransactionImpl extends Transaction {
230
230
  if (this.sealed && this.pending === 0) {
231
231
  this.applyOrDiscard();
232
232
  TransactionImpl.curr = outer;
233
- TransactionImpl.standalone(TransactionImpl.runReactions, this);
233
+ TransactionImpl.standalone(Snapshot_1.Snapshot.enqueueDetectedReactions, this.snapshot);
234
234
  }
235
235
  else
236
236
  TransactionImpl.curr = outer;
237
237
  }
238
238
  return result;
239
239
  }
240
- static runReactions(t) {
241
- t.snapshot.reactions.forEach(x => x.runIfNotUpToDate(false, true));
242
- }
243
240
  static seal(t, error, after) {
244
241
  if (!t.canceled && error) {
245
242
  t.canceled = error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.21.527",
3
+ "version": "0.21.528",
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",