reactronic 0.21.601 → 0.21.602

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.
@@ -33,7 +33,7 @@ export declare class ObjectRevision {
33
33
  revision: ObjectRevision;
34
34
  };
35
35
  readonly data: any;
36
- readonly changes: Map<MemberName, Observer>;
36
+ readonly changes: Set<MemberName>;
37
37
  readonly conflicts: Map<MemberName, ObjectRevision>;
38
38
  constructor(snapshot: AbstractSnapshot, prev: ObjectRevision | undefined, data: object);
39
39
  }
@@ -16,7 +16,7 @@ class ObjectRevision {
16
16
  this.snapshot = snapshot;
17
17
  this.prev = { revision: prev || this };
18
18
  this.data = data;
19
- this.changes = new Map();
19
+ this.changes = new Set();
20
20
  this.conflicts = new Map();
21
21
  if (Dbg_1.Dbg.isOn)
22
22
  Object.freeze(this);
@@ -79,7 +79,7 @@ declare class Operation extends Observable implements Observer {
79
79
  private static propagateAllChangesThroughSubscriptions;
80
80
  private static revokeAllSubscriptions;
81
81
  private static propagateMemberChangeThroughSubscriptions;
82
- private static enqueueDetectedReactions;
82
+ private static enqueueReactionsToRun;
83
83
  private static runQueuedReactionsLoop;
84
84
  private unsubscribeFromAllObservables;
85
85
  private subscribeTo;
@@ -269,7 +269,10 @@ class Operation extends Data_1.Observable {
269
269
  markObsoleteDueTo(observable, cause, since, reactions) {
270
270
  var _a, _b, _c;
271
271
  if (this.observables !== undefined) {
272
- if (observable.isOperation || this !== cause.revision.changes.get(cause.memberName)) {
272
+ const skip = !observable.isOperation &&
273
+ cause.revision.snapshot === this.revision.snapshot &&
274
+ cause.revision.changes.has(cause.memberName);
275
+ if (!skip) {
273
276
  this.unsubscribeFromAllObservables();
274
277
  this.obsoleteDueTo = cause;
275
278
  this.obsoleteSince = since;
@@ -407,6 +410,7 @@ class Operation extends Data_1.Observable {
407
410
  Dbg_1.Dbg.log('║', `${op}`, `${this.hint()} ${message}`, ms, highlight);
408
411
  if (ms > (main ? Hooks_1.Hooks.mainThreadBlockingWarningThreshold : Hooks_1.Hooks.asyncActionDurationWarningThreshold))
409
412
  Dbg_1.Dbg.log('', '[!]', this.why(), ms, main ? ' *** main thread is too busy ***' : ' *** async is too long ***');
413
+ this.cause = undefined;
410
414
  if (this.options.monitor)
411
415
  this.monitorLeave(this.options.monitor);
412
416
  }
@@ -456,7 +460,7 @@ class Operation extends Data_1.Observable {
456
460
  }
457
461
  }
458
462
  static markEdited(oldValue, newValue, edited, r, m, h) {
459
- edited ? r.changes.set(m, Operation.current) : r.changes.delete(m);
463
+ edited ? r.changes.add(m) : r.changes.delete(m);
460
464
  if (Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.write)
461
465
  edited ? Dbg_1.Dbg.log('║', ' ✎', `${Snapshot_1.Dump.rev(r, m)} is changed from ${valueHint(oldValue, m)} to ${valueHint(newValue, m)}`) : Dbg_1.Dbg.log('║', ' ✎', `${Snapshot_1.Dump.rev(r, m)} is changed from ${valueHint(oldValue, m)} to ${valueHint(newValue, m)}`, undefined, ' (same as previous)');
462
466
  }
@@ -524,10 +528,10 @@ class Operation extends Data_1.Observable {
524
528
  curr.observers = undefined;
525
529
  }
526
530
  }
527
- static enqueueDetectedReactions(snapshot) {
531
+ static enqueueReactionsToRun(reactions) {
528
532
  const queue = Operation.queuedReactions;
529
533
  const isReactionLoopRequired = queue.length === 0;
530
- for (const r of snapshot.reactions)
534
+ for (const r of reactions)
531
535
  queue.push(r);
532
536
  if (isReactionLoopRequired)
533
537
  OperationController.runWithin(undefined, Operation.runQueuedReactionsLoop);
@@ -618,7 +622,7 @@ class Operation extends Data_1.Observable {
618
622
  Snapshot_1.Snapshot.isConflicting = Operation.isConflicting;
619
623
  Snapshot_1.Snapshot.propagateAllChangesThroughSubscriptions = Operation.propagateAllChangesThroughSubscriptions;
620
624
  Snapshot_1.Snapshot.revokeAllSubscriptions = Operation.revokeAllSubscriptions;
621
- Snapshot_1.Snapshot.enqueueDetectedReactions = Operation.enqueueDetectedReactions;
625
+ Snapshot_1.Snapshot.enqueueReactionsToRun = Operation.enqueueReactionsToRun;
622
626
  Hooks_1.Hooks.createControllerAndGetHook = Operation.createControllerAndGetHook;
623
627
  Hooks_1.Hooks.rememberOperationOptions = Operation.rememberOperationOptions;
624
628
  Promise.prototype.then = reactronicHookedThen;
@@ -17,8 +17,8 @@ export declare class Snapshot implements AbstractSnapshot {
17
17
  get timestamp(): number;
18
18
  private stamp;
19
19
  private bumper;
20
- readonly changeset: Map<ObjectHolder, ObjectRevision>;
21
- readonly reactions: Observer[];
20
+ changeset: Map<ObjectHolder, ObjectRevision>;
21
+ reactions: Observer[];
22
22
  sealed: boolean;
23
23
  constructor(options: SnapshotOptions | null);
24
24
  static current: () => Snapshot;
@@ -28,7 +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
+ static enqueueReactionsToRun: (reactions: Array<Observer>) => void;
32
32
  seekRevision(h: ObjectHolder, m: MemberName): ObjectRevision;
33
33
  getCurrentRevision(h: ObjectHolder, m: MemberName): ObjectRevision;
34
34
  getEditableRevision(h: ObjectHolder, m: MemberName, value: any, token?: any): ObjectRevision;
@@ -40,7 +40,7 @@ export declare class Snapshot implements AbstractSnapshot {
40
40
  bumpBy(timestamp: number): void;
41
41
  rebase(): ObjectRevision[] | undefined;
42
42
  private static merge;
43
- applyOrDiscard(error?: any): void;
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;
46
46
  collectGarbage(): void;
@@ -27,6 +27,8 @@ Object.defineProperty(Data_1.ObjectHolder.prototype, '#this', {
27
27
  return result;
28
28
  },
29
29
  });
30
+ const EMPTY_ARRAY = Object.freeze([]);
31
+ const EMPTY_MAP = Utils_1.Utils.freezeMap(new Map());
30
32
  class Snapshot {
31
33
  constructor(options) {
32
34
  this.id = ++Snapshot.idGen;
@@ -208,6 +210,7 @@ class Snapshot {
208
210
  }
209
211
  if (!error)
210
212
  Snapshot.propagateAllChangesThroughSubscriptions(this);
213
+ return this.reactions;
211
214
  }
212
215
  static sealObjectRevision(h, r) {
213
216
  if (!r.changes.has(Data_1.Meta.Disposed))
@@ -229,6 +232,8 @@ class Snapshot {
229
232
  }
230
233
  }
231
234
  collectGarbage() {
235
+ this.changeset = EMPTY_MAP;
236
+ this.reactions = EMPTY_ARRAY;
232
237
  if (Dbg_1.Dbg.isOn) {
233
238
  Utils_1.Utils.freezeMap(this.changeset);
234
239
  Object.freeze(this.reactions);
@@ -238,7 +243,7 @@ class Snapshot {
238
243
  }
239
244
  static freezeObjectRevision(r) {
240
245
  Object.freeze(r.data);
241
- Utils_1.Utils.freezeMap(r.changes);
246
+ Utils_1.Utils.freezeSet(r.changes);
242
247
  Utils_1.Utils.freezeMap(r.conflicts);
243
248
  return r;
244
249
  }
@@ -269,12 +274,10 @@ class Snapshot {
269
274
  if (Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.gc && r.prev.revision !== exports.ROOT_REV)
270
275
  Dbg_1.Dbg.log(' ', ' ', `${Dump.rev(r.prev.revision)} is ready for GC because overwritten by ${Dump.rev(r)}`);
271
276
  if (Snapshot.garbageCollectionSummaryInterval < Number.MAX_SAFE_INTEGER) {
272
- if (r.prev.revision !== exports.ROOT_REV) {
277
+ if (r.prev.revision !== exports.ROOT_REV)
273
278
  Snapshot.totalObjectRevisionCount--;
274
- }
275
- if (r.changes.has(Data_1.Meta.Disposed)) {
279
+ if (r.changes.has(Data_1.Meta.Disposed))
276
280
  Snapshot.totalObjectHolderCount--;
277
- }
278
281
  }
279
282
  r.prev.revision = exports.ROOT_REV;
280
283
  });
@@ -309,7 +312,7 @@ Snapshot.markEdited = Utils_1.UNDEF;
309
312
  Snapshot.isConflicting = Utils_1.UNDEF;
310
313
  Snapshot.propagateAllChangesThroughSubscriptions = (snapshot) => { };
311
314
  Snapshot.revokeAllSubscriptions = (snapshot) => { };
312
- Snapshot.enqueueDetectedReactions = (snapshot) => { };
315
+ Snapshot.enqueueReactionsToRun = (reactions) => { };
313
316
  class Dump {
314
317
  static obj(h, m, stamp, op, xop, typeless) {
315
318
  const member = m !== undefined ? `.${m.toString()}` : '';
@@ -228,9 +228,9 @@ class TransactionImpl extends Transaction {
228
228
  finally {
229
229
  this.pending--;
230
230
  if (this.sealed && this.pending === 0) {
231
- this.applyOrDiscard();
231
+ const reactions = this.applyOrDiscard();
232
232
  TransactionImpl.curr = outer;
233
- TransactionImpl.standalone(Snapshot_1.Snapshot.enqueueDetectedReactions, this.snapshot);
233
+ TransactionImpl.standalone(Snapshot_1.Snapshot.enqueueReactionsToRun, reactions);
234
234
  }
235
235
  else
236
236
  TransactionImpl.curr = outer;
@@ -259,10 +259,11 @@ class TransactionImpl extends Transaction {
259
259
  throw (0, Dbg_1.error)(`T${this.id}[${this.hint}] conflicts with: ${Snapshot_1.Dump.conflicts(conflicts)}`, undefined);
260
260
  }
261
261
  applyOrDiscard() {
262
+ let reactions;
262
263
  try {
263
264
  if (Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.change)
264
265
  Dbg_1.Dbg.log('╠═', '', '', undefined, 'changes');
265
- this.snapshot.applyOrDiscard(this.canceled);
266
+ reactions = this.snapshot.applyOrDiscard(this.canceled);
266
267
  this.snapshot.collectGarbage();
267
268
  if (this.promise) {
268
269
  if (this.canceled && !this.after)
@@ -277,6 +278,7 @@ class TransactionImpl extends Transaction {
277
278
  (0, Dbg_1.fatal)(e);
278
279
  throw e;
279
280
  }
281
+ return reactions;
280
282
  }
281
283
  acquirePromise() {
282
284
  if (!this.promise) {
@@ -1,7 +1,7 @@
1
1
  export declare type F<T> = (...args: any[]) => T;
2
2
  export declare class Utils {
3
- static freezeSet<T>(obj?: Set<T>): void;
4
- static freezeMap<K, V>(obj?: Map<K, V>): void;
3
+ static freezeSet<T>(obj?: Set<T>): Set<T> | undefined;
4
+ static freezeMap<K, V>(obj?: Map<K, V>): Map<K, V> | undefined;
5
5
  static copyAllMembers(source: any, target: any): any;
6
6
  }
7
7
  export declare function UNDEF(...args: any[]): never;
@@ -19,6 +19,7 @@ class Utils {
19
19
  Object.defineProperty(obj, 'clear', pd);
20
20
  Object.freeze(obj);
21
21
  }
22
+ return obj;
22
23
  }
23
24
  static freezeMap(obj) {
24
25
  if (obj instanceof Map) {
@@ -28,6 +29,7 @@ class Utils {
28
29
  Object.defineProperty(obj, 'clear', pd);
29
30
  Object.freeze(obj);
30
31
  }
32
+ return obj;
31
33
  }
32
34
  static copyAllMembers(source, target) {
33
35
  for (const m of Object.getOwnPropertyNames(source))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.21.601",
3
+ "version": "0.21.602",
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",