reactronic 0.22.206 → 0.22.301

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.
@@ -9,10 +9,10 @@ const Snapshot_1 = require("./Snapshot");
9
9
  const Transaction_1 = require("./Transaction");
10
10
  const Monitor_1 = require("./Monitor");
11
11
  const Hooks_1 = require("./Hooks");
12
- const EditJournal_1 = require("./EditJournal");
12
+ const Journal_1 = require("./Journal");
13
13
  const BOOT_ARGS = [];
14
14
  const BOOT_CAUSE = '<boot>';
15
- const ROOT_HOLDER = new Data_1.ObjectHolder(undefined, undefined, Hooks_1.Hooks.proxy, Snapshot_1.ROOT_REV, '<root>');
15
+ const ROOT_HOLDER = new Data_1.DataHolder(undefined, undefined, Hooks_1.Hooks.proxy, Snapshot_1.ROOT_REV, '<root>');
16
16
  class OperationController extends Controller_1.Controller {
17
17
  constructor(ownHolder, memberName) {
18
18
  super();
@@ -21,14 +21,14 @@ class OperationController extends Controller_1.Controller {
21
21
  }
22
22
  configure(options) { return OperationController.configureImpl(this, options); }
23
23
  get options() { return this.peek(undefined).operation.options; }
24
- get nonreactive() { return this.peek(undefined).operation.value; }
24
+ get nonreactive() { return this.peek(undefined).operation.content; }
25
25
  get args() { return this.use().operation.args; }
26
- get result() { return this.useOrRun(true, undefined).value; }
26
+ get result() { return this.useOrRun(true, undefined).content; }
27
27
  get error() { return this.use().operation.error; }
28
28
  get stamp() { return this.use().revision.snapshot.timestamp; }
29
29
  get isUpToDate() { return this.use().isUpToDate; }
30
30
  markObsolete() { Transaction_1.Transaction.run({ hint: Dbg_1.Log.isOn ? `markObsolete(${Snapshot_1.Dump.obj(this.ownHolder, this.memberName)})` : 'markObsolete()' }, OperationController.markObsolete, this); }
31
- pullLastResult(args) { return this.useOrRun(true, args).value; }
31
+ pullLastResult(args) { return this.useOrRun(true, args).content; }
32
32
  useOrRun(weak, args) {
33
33
  var _a;
34
34
  let oc = this.peek(args);
@@ -42,7 +42,7 @@ class OperationController extends Controller_1.Controller {
42
42
  const standalone = weak || opts.standalone || opts.kind === Options_1.Kind.Reaction ||
43
43
  (opts.kind === Options_1.Kind.Transaction && outerOpts && (outerOpts.noSideEffects || outerOpts.kind === Options_1.Kind.Cache)) ||
44
44
  (opts.kind === Options_1.Kind.Cache && (oc.revision.snapshot.sealed ||
45
- oc.revision.prev.revision !== Snapshot_1.ROOT_REV));
45
+ oc.revision.former.revision !== Snapshot_1.ROOT_REV));
46
46
  const token = opts.noSideEffects ? this : undefined;
47
47
  const oc2 = this.run(oc, standalone, opts, token, args);
48
48
  const ctx2 = oc2.operation.snapshot;
@@ -129,7 +129,7 @@ class OperationController extends Controller_1.Controller {
129
129
  if (op.snapshot !== r.snapshot) {
130
130
  const op2 = new Operation(this, r.snapshot, op);
131
131
  r.data[m] = op2.reenterOver(op);
132
- ctx.bumpBy(r.prev.revision.snapshot.timestamp);
132
+ ctx.bumpBy(r.former.revision.snapshot.timestamp);
133
133
  Snapshot_1.Snapshot.markEdited(op, op2, true, r, m, h);
134
134
  op = op2;
135
135
  }
@@ -141,7 +141,7 @@ class OperationController extends Controller_1.Controller {
141
141
  if (op.controller !== this) {
142
142
  if (r.snapshot !== Snapshot_1.ROOT_REV.snapshot) {
143
143
  const hint = Dbg_1.Log.isOn ? `${Snapshot_1.Dump.obj(this.ownHolder, m)}/boot` : 'MethodController/init';
144
- const standalone = r.snapshot.sealed || r.prev.revision !== Snapshot_1.ROOT_REV;
144
+ const standalone = r.snapshot.sealed || r.former.revision !== Snapshot_1.ROOT_REV;
145
145
  op = Transaction_1.Transaction.run({ hint, standalone, token: this }, () => {
146
146
  const h = this.ownHolder;
147
147
  let r2 = Snapshot_1.Snapshot.current().getCurrentRevision(h, m);
@@ -204,21 +204,21 @@ class OperationController extends Controller_1.Controller {
204
204
  }
205
205
  }
206
206
  exports.OperationController = OperationController;
207
- class Operation extends Data_1.Observable {
208
- constructor(controller, snapshot, prev) {
207
+ class Operation extends Data_1.Subscription {
208
+ constructor(controller, snapshot, former) {
209
209
  super(undefined);
210
210
  this.margin = Operation.current ? Operation.current.margin + 1 : 1;
211
211
  this.transaction = Transaction_1.Transaction.current;
212
212
  this.controller = controller;
213
213
  this.snapshot = snapshot;
214
- this.observables = new Map();
215
- if (prev instanceof Operation) {
216
- this.options = prev.options;
217
- this.args = prev.args;
218
- this.cause = prev.obsoleteDueTo;
214
+ this.subscriptions = new Map();
215
+ if (former instanceof Operation) {
216
+ this.options = former.options;
217
+ this.args = former.args;
218
+ this.cause = former.obsoleteDueTo;
219
219
  }
220
220
  else {
221
- this.options = prev;
221
+ this.options = former;
222
222
  this.args = BOOT_ARGS;
223
223
  this.cause = undefined;
224
224
  }
@@ -274,14 +274,14 @@ class Operation extends Data_1.Observable {
274
274
  else
275
275
  this.result = Promise.reject(this.error);
276
276
  }
277
- markObsoleteDueTo(observable, memberName, snapshot, holder, outer, since, reactions) {
277
+ markObsoleteDueTo(subscription, memberName, snapshot, holder, outer, since, reactions) {
278
278
  var _a, _b, _c;
279
- if (this.observables !== undefined) {
280
- const skip = !observable.isOperation &&
279
+ if (this.subscriptions !== undefined) {
280
+ const skip = !subscription.isOperation &&
281
281
  snapshot === this.snapshot;
282
282
  if (!skip) {
283
- const why = `${Snapshot_1.Dump.rev2(holder, snapshot, memberName, observable)} << ${outer}`;
284
- this.unsubscribeFromAllObservables();
283
+ const why = `${Snapshot_1.Dump.rev2(holder, snapshot, memberName, subscription)} << ${outer}`;
284
+ this.unsubscribeFromAllSubscriptions();
285
285
  this.obsoleteDueTo = why;
286
286
  this.obsoleteSince = since;
287
287
  const isReaction = this.options.kind === Options_1.Kind.Reaction;
@@ -292,11 +292,11 @@ class Operation extends Data_1.Observable {
292
292
  if (isReaction)
293
293
  reactions.push(this);
294
294
  else
295
- (_b = this.observers) === null || _b === void 0 ? void 0 : _b.forEach(c => c.markObsoleteDueTo(this, this.controller.memberName, this.snapshot, this.controller.ownHolder, why, since, reactions));
295
+ (_b = this.subscribers) === null || _b === void 0 ? void 0 : _b.forEach(s => s.markObsoleteDueTo(this, this.controller.memberName, this.snapshot, this.controller.ownHolder, why, since, reactions));
296
296
  const tran = this.transaction;
297
297
  if (tran.snapshot === snapshot) {
298
298
  }
299
- else if (!tran.isFinished && this !== observable)
299
+ else if (!tran.isFinished && this !== subscription)
300
300
  tran.cancel(new Error(`T${tran.id}[${tran.hint}] is canceled due to obsolete ${Snapshot_1.Dump.rev2(holder, snapshot, memberName)} changed by T${snapshot.id}[${snapshot.hint}]`), null);
301
301
  }
302
302
  else if (Dbg_1.Log.isOn && (Dbg_1.Log.opt.obsolete || ((_c = this.options.logging) === null || _c === void 0 ? void 0 : _c.obsolete)))
@@ -390,7 +390,7 @@ class Operation extends Data_1.Observable {
390
390
  leaveOrAsync() {
391
391
  if (this.result instanceof Promise) {
392
392
  this.result = this.result.then(value => {
393
- this.value = value;
393
+ this.content = value;
394
394
  this.leave(false, ' ⚐', '- finished ', ' OK ──┘');
395
395
  return value;
396
396
  }, error => {
@@ -406,7 +406,7 @@ class Operation extends Data_1.Observable {
406
406
  }
407
407
  }
408
408
  else {
409
- this.value = this.result;
409
+ this.content = this.result;
410
410
  this.leave(true, '_/', '- leave');
411
411
  }
412
412
  }
@@ -453,7 +453,7 @@ class Operation extends Data_1.Observable {
453
453
  for (const x of reactions)
454
454
  x.runIfNotUpToDate(true, true);
455
455
  }
456
- static markUsed(observable, r, m, h, kind, weak) {
456
+ static markUsed(subscription, r, m, h, kind, weak) {
457
457
  if (kind !== Options_1.Kind.Transaction) {
458
458
  const op = Operation.current;
459
459
  if (op && op.options.kind !== Options_1.Kind.Transaction &&
@@ -462,8 +462,8 @@ class Operation extends Data_1.Observable {
462
462
  if (ctx !== r.snapshot)
463
463
  ctx.bumpBy(r.snapshot.timestamp);
464
464
  const t = weak ? -1 : ctx.timestamp;
465
- if (!op.subscribeTo(observable, r, m, h, t))
466
- op.markObsoleteDueTo(observable, m, r.snapshot, h, BOOT_CAUSE, ctx.timestamp, ctx.reactions);
465
+ if (!op.subscribeTo(subscription, r, m, h, t))
466
+ op.markObsoleteDueTo(subscription, m, r.snapshot, h, BOOT_CAUSE, ctx.timestamp, ctx.reactions);
467
467
  }
468
468
  }
469
469
  }
@@ -486,11 +486,11 @@ class Operation extends Data_1.Observable {
486
486
  if (!r.changes.has(Data_1.Meta.Disposed))
487
487
  r.changes.forEach((o, m) => Operation.propagateMemberChangeThroughSubscriptions(false, since, r, m, h, reactions));
488
488
  else
489
- for (const m in r.prev.revision.data)
489
+ for (const m in r.former.revision.data)
490
490
  Operation.propagateMemberChangeThroughSubscriptions(true, since, r, m, h, reactions);
491
491
  });
492
492
  reactions.sort(compareReactionsByOrder);
493
- (_a = snapshot.options.journal) === null || _a === void 0 ? void 0 : _a.register(EditJournal_1.EditJournalImpl.buildPatch(snapshot.hint, snapshot.changeset));
493
+ (_a = snapshot.options.journal) === null || _a === void 0 ? void 0 : _a.edited(Journal_1.JournalImpl.buildPatch(snapshot.hint, snapshot.changeset));
494
494
  }
495
495
  static revokeAllSubscriptions(snapshot) {
496
496
  snapshot.changeset.forEach((r, h) => r.changes.forEach((o, m) => Operation.propagateMemberChangeThroughSubscriptions(true, snapshot.timestamp, r, m, h, undefined)));
@@ -499,39 +499,39 @@ class Operation extends Data_1.Observable {
499
499
  var _a;
500
500
  const curr = r.data[m];
501
501
  if (reactions) {
502
- const prev = r.prev.revision.data[m];
503
- if (prev !== undefined && prev instanceof Data_1.Observable) {
502
+ const former = r.former.revision.data[m];
503
+ if (former !== undefined && former instanceof Data_1.Subscription) {
504
504
  const why = `T${r.snapshot.id}[${r.snapshot.hint}]`;
505
- if (prev instanceof Operation) {
506
- if ((prev.obsoleteSince === Snapshot_1.MAX_TIMESTAMP || prev.obsoleteSince <= 0)) {
507
- prev.obsoleteDueTo = why;
508
- prev.obsoleteSince = timestamp;
509
- prev.unsubscribeFromAllObservables();
505
+ if (former instanceof Operation) {
506
+ if ((former.obsoleteSince === Snapshot_1.MAX_TIMESTAMP || former.obsoleteSince <= 0)) {
507
+ former.obsoleteDueTo = why;
508
+ former.obsoleteSince = timestamp;
509
+ former.unsubscribeFromAllSubscriptions();
510
510
  }
511
- const prevSuccessor = prev.successor;
512
- if (prevSuccessor !== curr) {
513
- if (prevSuccessor && !prevSuccessor.transaction.isFinished)
514
- prevSuccessor.transaction.cancel(new Error(`T${prevSuccessor.transaction.id}[${prevSuccessor.transaction.hint}] is canceled by T${r.snapshot.id}[${r.snapshot.hint}] and will not run anymore`), null);
511
+ const formerSuccessor = former.successor;
512
+ if (formerSuccessor !== curr) {
513
+ if (formerSuccessor && !formerSuccessor.transaction.isFinished)
514
+ formerSuccessor.transaction.cancel(new Error(`T${formerSuccessor.transaction.id}[${formerSuccessor.transaction.hint}] is canceled by T${r.snapshot.id}[${r.snapshot.hint}] and will not run anymore`), null);
515
515
  }
516
516
  else
517
- prev.successor = undefined;
517
+ former.successor = undefined;
518
518
  }
519
- (_a = prev.observers) === null || _a === void 0 ? void 0 : _a.forEach(c => c.markObsoleteDueTo(prev, m, r.snapshot, h, why, timestamp, reactions));
519
+ (_a = former.subscribers) === null || _a === void 0 ? void 0 : _a.forEach(s => s.markObsoleteDueTo(former, m, r.snapshot, h, why, timestamp, reactions));
520
520
  }
521
521
  }
522
522
  if (curr instanceof Operation) {
523
- if (curr.snapshot === r.snapshot && curr.observables !== undefined) {
523
+ if (curr.snapshot === r.snapshot && curr.subscriptions !== undefined) {
524
524
  if (Hooks_1.Hooks.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
525
- curr.observables.forEach((info, v) => {
525
+ curr.subscriptions.forEach((info, v) => {
526
526
  if (info.usageCount > Hooks_1.Hooks.repetitiveUsageWarningThreshold)
527
527
  Dbg_1.Log.write('', '[!]', `${curr.hint()} uses ${info.memberHint} ${info.usageCount} times (consider remembering it in a local variable)`, 0, ' *** WARNING ***');
528
528
  });
529
529
  }
530
530
  if (unsubscribe)
531
- curr.unsubscribeFromAllObservables();
531
+ curr.unsubscribeFromAllSubscriptions();
532
532
  }
533
533
  }
534
- else if (curr instanceof Data_1.Observable && curr.observers) {
534
+ else if (curr instanceof Data_1.Subscription && curr.subscribers) {
535
535
  }
536
536
  }
537
537
  static enqueueReactionsToRun(reactions) {
@@ -552,31 +552,31 @@ class Operation extends Data_1.Observable {
552
552
  }
553
553
  Operation.queuedReactions = [];
554
554
  }
555
- unsubscribeFromAllObservables() {
555
+ unsubscribeFromAllSubscriptions() {
556
556
  var _a;
557
- (_a = this.observables) === null || _a === void 0 ? void 0 : _a.forEach((info, value) => {
557
+ (_a = this.subscriptions) === null || _a === void 0 ? void 0 : _a.forEach((info, value) => {
558
558
  var _a;
559
- value.observers.delete(this);
559
+ value.subscribers.delete(this);
560
560
  if (Dbg_1.Log.isOn && (Dbg_1.Log.opt.read || ((_a = this.options.logging) === null || _a === void 0 ? void 0 : _a.read)))
561
561
  Dbg_1.Log.write(Dbg_1.Log.opt.transaction && !Snapshot_1.Snapshot.current().sealed ? '║' : ' ', '-', `${this.hint()} is unsubscribed from ${info.memberHint}`);
562
562
  });
563
- this.observables = undefined;
563
+ this.subscriptions = undefined;
564
564
  }
565
- subscribeTo(observable, r, m, h, timestamp) {
565
+ subscribeTo(subscription, r, m, h, timestamp) {
566
566
  var _a, _b, _c;
567
- const ok = Operation.canSubscribe(observable, r, m, h, timestamp);
567
+ const ok = Operation.canSubscribe(subscription, r, m, h, timestamp);
568
568
  if (ok) {
569
569
  let times = 0;
570
570
  if (Hooks_1.Hooks.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
571
- const existing = this.observables.get(observable);
571
+ const existing = this.subscriptions.get(subscription);
572
572
  times = existing ? existing.usageCount + 1 : 1;
573
573
  }
574
- if (this.observables !== undefined) {
575
- if (!observable.observers)
576
- observable.observers = new Set();
574
+ if (this.subscriptions !== undefined) {
575
+ if (!subscription.subscribers)
576
+ subscription.subscribers = new Set();
577
577
  const info = { memberHint: Snapshot_1.Dump.rev2(h, r.snapshot, m), usageCount: times };
578
- observable.observers.add(this);
579
- this.observables.set(observable, info);
578
+ subscription.subscribers.add(this);
579
+ this.subscriptions.set(subscription, info);
580
580
  if (Dbg_1.Log.isOn && (Dbg_1.Log.opt.read || ((_a = this.options.logging) === null || _a === void 0 ? void 0 : _a.read)))
581
581
  Dbg_1.Log.write('║', ' ∞ ', `${this.hint()} is subscribed to ${Snapshot_1.Dump.rev2(h, r.snapshot, m)}${info.usageCount > 1 ? ` (${info.usageCount} times)` : ''}`);
582
582
  }
@@ -589,10 +589,10 @@ class Operation extends Data_1.Observable {
589
589
  }
590
590
  return ok;
591
591
  }
592
- static canSubscribe(observable, r, m, h, timestamp) {
593
- let result = !r.snapshot.sealed || observable === h.head.data[m];
592
+ static canSubscribe(subscription, r, m, h, timestamp) {
593
+ let result = !r.snapshot.sealed || subscription === h.head.data[m];
594
594
  if (result && timestamp !== -1)
595
- result = !(observable instanceof Operation && timestamp >= observable.obsoleteSince);
595
+ result = !(subscription instanceof Operation && timestamp >= subscription.obsoleteSince);
596
596
  return result;
597
597
  }
598
598
  static createOperation(h, m, options) {
@@ -1,5 +1,5 @@
1
1
  import { Kind, SnapshotOptions } from '../Options';
2
- import { AbstractSnapshot, ObjectRevision, MemberName, ObjectHolder, Observable, Observer } from './Data';
2
+ import { AbstractSnapshot, DataRevision, MemberName, DataHolder, Subscription, Subscriber } from './Data';
3
3
  export declare const MAX_TIMESTAMP: number;
4
4
  export declare const UNDEFINED_TIMESTAMP: number;
5
5
  export declare class Snapshot implements AbstractSnapshot {
@@ -9,52 +9,52 @@ export declare class Snapshot implements AbstractSnapshot {
9
9
  private static oldest;
10
10
  static garbageCollectionSummaryInterval: number;
11
11
  static lastGarbageCollectionSummaryTimestamp: number;
12
- static totalObjectHolderCount: number;
13
- static totalObjectRevisionCount: number;
12
+ static totalHolderCount: number;
13
+ static totalRevisionCount: number;
14
14
  readonly id: number;
15
15
  readonly options: SnapshotOptions;
16
16
  get hint(): string;
17
17
  get timestamp(): number;
18
18
  private stamp;
19
19
  private bumper;
20
- changeset: Map<ObjectHolder, ObjectRevision>;
21
- reactions: Observer[];
20
+ changeset: Map<DataHolder, DataRevision>;
21
+ reactions: Subscriber[];
22
22
  sealed: boolean;
23
23
  constructor(options: SnapshotOptions | null);
24
24
  static current: () => Snapshot;
25
25
  static edit: () => Snapshot;
26
- static markUsed: (observable: Observable, r: ObjectRevision, m: MemberName, h: ObjectHolder, kind: Kind, weak: boolean) => void;
27
- static markEdited: (oldValue: any, newValue: any, edited: boolean, r: ObjectRevision, m: MemberName, h: ObjectHolder) => void;
26
+ static markUsed: (subscription: Subscription, r: DataRevision, m: MemberName, h: DataHolder, kind: Kind, weak: boolean) => void;
27
+ static markEdited: (oldValue: any, newValue: any, edited: boolean, r: DataRevision, m: MemberName, h: DataHolder) => void;
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 enqueueReactionsToRun: (reactions: Array<Observer>) => void;
32
- seekRevision(h: ObjectHolder, m: MemberName): ObjectRevision;
33
- getCurrentRevision(h: ObjectHolder, m: MemberName): ObjectRevision;
34
- getEditableRevision(h: ObjectHolder, m: MemberName, value: any, token?: any): ObjectRevision;
31
+ static enqueueReactionsToRun: (reactions: Array<Subscriber>) => void;
32
+ seekRevision(h: DataHolder, m: MemberName): DataRevision;
33
+ getCurrentRevision(h: DataHolder, m: MemberName): DataRevision;
34
+ getEditableRevision(h: DataHolder, m: MemberName, value: any, token?: any): DataRevision;
35
35
  static takeSnapshot<T>(obj: T): T;
36
36
  static dispose(obj: any): void;
37
- static doDispose(ctx: Snapshot, h: ObjectHolder): ObjectRevision;
37
+ static doDispose(ctx: Snapshot, h: DataHolder): DataRevision;
38
38
  private isNewRevisionRequired;
39
39
  acquire(outer: Snapshot): void;
40
40
  bumpBy(timestamp: number): void;
41
- rebase(): ObjectRevision[] | undefined;
41
+ rebase(): DataRevision[] | undefined;
42
42
  private merge;
43
- applyOrDiscard(error?: any): Array<Observer>;
44
- static sealObjectRevision(h: ObjectHolder, r: ObjectRevision): void;
45
- static sealObservable(observable: Observable | symbol, m: MemberName, typeName: string): void;
46
- static freezeObjectRevision(r: ObjectRevision): ObjectRevision;
43
+ applyOrDiscard(error?: any): Array<Subscriber>;
44
+ static sealObjectRevision(h: DataHolder, r: DataRevision): void;
45
+ static sealSubscription(subscription: Subscription | symbol, m: MemberName, typeName: string): void;
46
+ static freezeObjectRevision(r: DataRevision): DataRevision;
47
47
  triggerGarbageCollection(): void;
48
48
  private unlinkHistory;
49
49
  static _init(): void;
50
50
  }
51
51
  export declare class Dump {
52
52
  static valueHint: (value: any, m?: PropertyKey | undefined) => string;
53
- static obj(h: ObjectHolder | undefined, m?: MemberName | undefined, stamp?: number, snapshotId?: number, originSnapshotId?: number, value?: any): string;
54
- static rev2(h: ObjectHolder, s: AbstractSnapshot, m?: MemberName, o?: Observable): string;
55
- static rev(r: ObjectRevision, m?: MemberName): string;
56
- static conflicts(conflicts: ObjectRevision[]): string;
57
- static conflictingMemberHint(m: MemberName, ours: ObjectRevision, theirs: ObjectRevision): string;
53
+ static obj(h: DataHolder | undefined, m?: MemberName | undefined, stamp?: number, snapshotId?: number, originSnapshotId?: number, value?: any): string;
54
+ static rev2(h: DataHolder, s: AbstractSnapshot, m?: MemberName, o?: Subscription): string;
55
+ static rev(r: DataRevision, m?: MemberName): string;
56
+ static conflicts(conflicts: DataRevision[]): string;
57
+ static conflictingMemberHint(m: MemberName, ours: DataRevision, theirs: DataRevision): string;
58
58
  }
59
- export declare const ROOT_REV: ObjectRevision;
59
+ export declare const ROOT_REV: DataRevision;
60
60
  export declare const DefaultSnapshotOptions: SnapshotOptions;
@@ -10,17 +10,17 @@ const SealedSet_1 = require("../util/SealedSet");
10
10
  const Data_1 = require("./Data");
11
11
  exports.MAX_TIMESTAMP = Number.MAX_SAFE_INTEGER;
12
12
  exports.UNDEFINED_TIMESTAMP = exports.MAX_TIMESTAMP - 1;
13
- Object.defineProperty(Data_1.ObjectHolder.prototype, '#this', {
13
+ Object.defineProperty(Data_1.DataHolder.prototype, '#this', {
14
14
  configurable: false, enumerable: false,
15
15
  get() {
16
16
  const result = {};
17
17
  const data = Snapshot.current().getCurrentRevision(this, '#this').data;
18
18
  for (const m in data) {
19
19
  const v = data[m];
20
- if (v instanceof Data_1.Observable)
21
- result[m] = v.value;
22
- else if (v === Data_1.Meta.Unobservable)
23
- result[m] = this.unobservable[m];
20
+ if (v instanceof Data_1.Subscription)
21
+ result[m] = v.content;
22
+ else if (v === Data_1.Meta.Nonreactive)
23
+ result[m] = this.data[m];
24
24
  else
25
25
  result[m] = v;
26
26
  }
@@ -51,7 +51,7 @@ class Snapshot {
51
51
  if (!r) {
52
52
  r = h.head;
53
53
  while (r !== exports.ROOT_REV && r.snapshot.timestamp > this.timestamp)
54
- r = r.prev.revision;
54
+ r = r.former.revision;
55
55
  }
56
56
  return r;
57
57
  }
@@ -64,11 +64,11 @@ class Snapshot {
64
64
  getEditableRevision(h, m, value, token) {
65
65
  let r = this.seekRevision(h, m);
66
66
  const existing = r.data[m];
67
- if (existing !== Data_1.Meta.Unobservable) {
67
+ if (existing !== Data_1.Meta.Nonreactive) {
68
68
  if (this.isNewRevisionRequired(h, r, m, existing, value, token)) {
69
69
  const data = Object.assign({}, m === Data_1.Meta.Holder ? value : r.data);
70
70
  Reflect.set(data, Data_1.Meta.Holder, h);
71
- r = new Data_1.ObjectRevision(this, r, data);
71
+ r = new Data_1.DataRevision(this, r, data);
72
72
  this.changeset.set(h, r);
73
73
  h.editing = r;
74
74
  h.editors++;
@@ -99,9 +99,9 @@ class Snapshot {
99
99
  }
100
100
  isNewRevisionRequired(h, r, m, existing, value, token) {
101
101
  if (this.sealed && r.snapshot !== exports.ROOT_REV.snapshot)
102
- throw (0, Dbg_1.misuse)(`observable property ${Dump.obj(h, m)} can only be modified inside transaction`);
102
+ throw (0, Dbg_1.misuse)(`reactive property ${Dump.obj(h, m)} can only be modified inside transaction`);
103
103
  if (m !== Data_1.Meta.Holder && value !== Data_1.Meta.Holder) {
104
- if (r.snapshot !== this || r.prev.revision !== exports.ROOT_REV) {
104
+ if (r.snapshot !== this || r.former.revision !== exports.ROOT_REV) {
105
105
  if (this.options.token !== undefined && token !== this.options.token)
106
106
  throw (0, Dbg_1.misuse)(`${this.hint} should not have side effects (trying to change ${Dump.rev(r, m)})`);
107
107
  }
@@ -129,7 +129,7 @@ class Snapshot {
129
129
  let conflicts = undefined;
130
130
  if (this.changeset.size > 0) {
131
131
  this.changeset.forEach((r, h) => {
132
- if (r.prev.revision !== h.head) {
132
+ if (r.former.revision !== h.head) {
133
133
  const merged = this.merge(h, r);
134
134
  if (r.conflicts.size > 0) {
135
135
  if (!conflicts)
@@ -172,7 +172,7 @@ class Snapshot {
172
172
  }
173
173
  }
174
174
  else {
175
- const conflict = Snapshot.isConflicting(head.data[m], ours.prev.revision.data[m]);
175
+ const conflict = Snapshot.isConflicting(head.data[m], ours.former.revision.data[m]);
176
176
  if (conflict)
177
177
  ours.conflicts.set(m, head);
178
178
  if (Dbg_1.Log.isOn && Dbg_1.Log.opt.change)
@@ -180,7 +180,7 @@ class Snapshot {
180
180
  }
181
181
  });
182
182
  Utils_1.Utils.copyAllMembers(merged, ours.data);
183
- ours.prev.revision = head;
183
+ ours.former.revision = head;
184
184
  return counter;
185
185
  }
186
186
  applyOrDiscard(error) {
@@ -193,9 +193,9 @@ class Snapshot {
193
193
  if (!error) {
194
194
  h.head = r;
195
195
  if (Snapshot.garbageCollectionSummaryInterval < Number.MAX_SAFE_INTEGER) {
196
- Snapshot.totalObjectRevisionCount++;
197
- if (r.prev.revision === exports.ROOT_REV)
198
- Snapshot.totalObjectHolderCount++;
196
+ Snapshot.totalRevisionCount++;
197
+ if (r.former.revision === exports.ROOT_REV)
198
+ Snapshot.totalHolderCount++;
199
199
  }
200
200
  }
201
201
  });
@@ -205,7 +205,7 @@ class Snapshot {
205
205
  const members = [];
206
206
  r.changes.forEach((o, m) => members.push(m.toString()));
207
207
  const s = members.join(', ');
208
- Dbg_1.Log.write('║', '√', `${Dump.rev2(h, r.snapshot)} (${s}) is ${r.prev.revision === exports.ROOT_REV ? 'constructed' : `applied on top of ${Dump.rev2(h, r.prev.revision.snapshot)}`}`);
208
+ Dbg_1.Log.write('║', '√', `${Dump.rev2(h, r.snapshot)} (${s}) is ${r.former.revision === exports.ROOT_REV ? 'constructed' : `applied on top of ${Dump.rev2(h, r.former.revision.snapshot)}`}`);
209
209
  });
210
210
  }
211
211
  if (Dbg_1.Log.opt.transaction)
@@ -217,20 +217,20 @@ class Snapshot {
217
217
  }
218
218
  static sealObjectRevision(h, r) {
219
219
  if (!r.changes.has(Data_1.Meta.Disposed))
220
- r.changes.forEach((o, m) => Snapshot.sealObservable(r.data[m], m, h.proxy.constructor.name));
220
+ r.changes.forEach((o, m) => Snapshot.sealSubscription(r.data[m], m, h.proxy.constructor.name));
221
221
  else
222
- for (const m in r.prev.revision.data)
222
+ for (const m in r.former.revision.data)
223
223
  r.data[m] = Data_1.Meta.Disposed;
224
224
  if (Dbg_1.Log.isOn)
225
225
  Snapshot.freezeObjectRevision(r);
226
226
  }
227
- static sealObservable(observable, m, typeName) {
228
- if (observable instanceof Data_1.Observable) {
229
- const value = observable.value;
227
+ static sealSubscription(subscription, m, typeName) {
228
+ if (subscription instanceof Data_1.Subscription) {
229
+ const value = subscription.content;
230
230
  if (value !== undefined && value !== null) {
231
231
  const sealedType = Object.getPrototypeOf(value)[Sealant_1.Sealant.SealedType];
232
232
  if (sealedType)
233
- observable.value = Sealant_1.Sealant.seal(value, sealedType, typeName, m);
233
+ subscription.content = Sealant_1.Sealant.seal(value, sealedType, typeName, m);
234
234
  }
235
235
  }
236
236
  }
@@ -254,7 +254,7 @@ class Snapshot {
254
254
  Snapshot.oldest = Snapshot.pending[0];
255
255
  const now = Date.now();
256
256
  if (now - Snapshot.lastGarbageCollectionSummaryTimestamp > Snapshot.garbageCollectionSummaryInterval) {
257
- Dbg_1.Log.write('', '[G]', `Total object/revision count: ${Snapshot.totalObjectHolderCount}/${Snapshot.totalObjectRevisionCount}`);
257
+ Dbg_1.Log.write('', '[G]', `Total object/revision count: ${Snapshot.totalHolderCount}/${Snapshot.totalRevisionCount}`);
258
258
  Snapshot.lastGarbageCollectionSummaryTimestamp = now;
259
259
  }
260
260
  }
@@ -264,15 +264,15 @@ class Snapshot {
264
264
  if (Dbg_1.Log.isOn && Dbg_1.Log.opt.gc)
265
265
  Dbg_1.Log.write('', '[G]', `Dismiss history below v${this.stamp}t${this.id} (${this.hint})`);
266
266
  this.changeset.forEach((r, h) => {
267
- if (Dbg_1.Log.isOn && Dbg_1.Log.opt.gc && r.prev.revision !== exports.ROOT_REV)
268
- Dbg_1.Log.write(' ', ' ', `${Dump.rev2(h, r.prev.revision.snapshot)} is ready for GC because overwritten by ${Dump.rev2(h, r.snapshot)}`);
267
+ if (Dbg_1.Log.isOn && Dbg_1.Log.opt.gc && r.former.revision !== exports.ROOT_REV)
268
+ Dbg_1.Log.write(' ', ' ', `${Dump.rev2(h, r.former.revision.snapshot)} is ready for GC because overwritten by ${Dump.rev2(h, r.snapshot)}`);
269
269
  if (Snapshot.garbageCollectionSummaryInterval < Number.MAX_SAFE_INTEGER) {
270
- if (r.prev.revision !== exports.ROOT_REV)
271
- Snapshot.totalObjectRevisionCount--;
270
+ if (r.former.revision !== exports.ROOT_REV)
271
+ Snapshot.totalRevisionCount--;
272
272
  if (r.changes.has(Data_1.Meta.Disposed))
273
- Snapshot.totalObjectHolderCount--;
273
+ Snapshot.totalHolderCount--;
274
274
  }
275
- r.prev.revision = exports.ROOT_REV;
275
+ r.former.revision = exports.ROOT_REV;
276
276
  });
277
277
  this.changeset = EMPTY_MAP;
278
278
  this.reactions = EMPTY_ARRAY;
@@ -300,8 +300,8 @@ Snapshot.pending = [];
300
300
  Snapshot.oldest = undefined;
301
301
  Snapshot.garbageCollectionSummaryInterval = Number.MAX_SAFE_INTEGER;
302
302
  Snapshot.lastGarbageCollectionSummaryTimestamp = Date.now();
303
- Snapshot.totalObjectHolderCount = 0;
304
- Snapshot.totalObjectRevisionCount = 0;
303
+ Snapshot.totalHolderCount = 0;
304
+ Snapshot.totalRevisionCount = 0;
305
305
  Snapshot.current = Utils_1.UNDEF;
306
306
  Snapshot.edit = Utils_1.UNDEF;
307
307
  Snapshot.markUsed = Utils_1.UNDEF;
@@ -321,7 +321,7 @@ class Dump {
321
321
  }
322
322
  static rev2(h, s, m, o) {
323
323
  var _a;
324
- return Dump.obj(h, m, s.timestamp, s.id, o === null || o === void 0 ? void 0 : o.originSnapshotId, (_a = o === null || o === void 0 ? void 0 : o.value) !== null && _a !== void 0 ? _a : Data_1.Meta.Undefined);
324
+ return Dump.obj(h, m, s.timestamp, s.id, o === null || o === void 0 ? void 0 : o.originSnapshotId, (_a = o === null || o === void 0 ? void 0 : o.content) !== null && _a !== void 0 ? _a : Data_1.Meta.Undefined);
325
325
  }
326
326
  static rev(r, m) {
327
327
  const h = Data_1.Meta.get(r.data, Data_1.Meta.Holder);
@@ -343,7 +343,7 @@ class Dump {
343
343
  }
344
344
  exports.Dump = Dump;
345
345
  Dump.valueHint = (value, m) => '???';
346
- exports.ROOT_REV = new Data_1.ObjectRevision(new Snapshot({ hint: '<root>' }), undefined, {});
346
+ exports.ROOT_REV = new Data_1.DataRevision(new Snapshot({ hint: '<root>' }), undefined, {});
347
347
  exports.DefaultSnapshotOptions = Object.freeze({
348
348
  hint: 'noname',
349
349
  standalone: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.22.206",
3
+ "version": "0.22.301",
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",
@@ -1,40 +0,0 @@
1
- import { ObservableObject } from './Hooks';
2
- import { ObjectHolder, ObjectRevision, Patch } from './Data';
3
- export declare abstract class EditJournal extends ObservableObject {
4
- abstract capacity: number;
5
- abstract autoSave: boolean;
6
- abstract readonly isSaving: boolean;
7
- abstract readonly edits: ReadonlyArray<Patch>;
8
- abstract readonly canUndo: boolean;
9
- abstract readonly canRedo: boolean;
10
- abstract undo(count?: number): void;
11
- abstract redo(count?: number): void;
12
- abstract save(): void;
13
- abstract register(patch: Patch): void;
14
- static create(): EditJournal;
15
- }
16
- export declare class EditJournalImpl extends EditJournal {
17
- private _capacity;
18
- private _autoSave;
19
- private _isSaving;
20
- private _edits;
21
- private _position;
22
- private _saved;
23
- get capacity(): number;
24
- set capacity(value: number);
25
- get autoSave(): boolean;
26
- set autoSave(value: boolean);
27
- get isSaving(): boolean;
28
- get edits(): ReadonlyArray<Patch>;
29
- get canUndo(): boolean;
30
- get canRedo(): boolean;
31
- undo(count?: number): void;
32
- redo(count?: number): void;
33
- save(): void;
34
- getUnsaved(): Patch | undefined;
35
- beginSave(): void;
36
- endSave(success: boolean): void;
37
- register(p: Patch): void;
38
- static buildPatch(hint: string, changeset: Map<ObjectHolder, ObjectRevision>): Patch;
39
- static applyPatch(patch: Patch, undo: boolean): void;
40
- }