reactronic 0.23.106 → 0.23.108

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.
@@ -0,0 +1,18 @@
1
+ import { F } from 'util/Utils.js';
2
+ import { MemberOptions } from './Options.js';
3
+ export interface AbstractReaction<T> {
4
+ readonly options: MemberOptions;
5
+ readonly args: ReadonlyArray<any>;
6
+ readonly result: T;
7
+ readonly error: any;
8
+ readonly stamp: number;
9
+ readonly isUpToDate: boolean;
10
+ configure(options: Partial<MemberOptions>): MemberOptions;
11
+ markObsolete(): void;
12
+ pullLastResult(args?: any[]): T | undefined;
13
+ }
14
+ export declare class Reaction<T> {
15
+ protected action: F<T>;
16
+ constructor(action: F<T>);
17
+ protected launch(): T;
18
+ }
@@ -0,0 +1,24 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { reactive } from 'Rx.js';
11
+ export class Reaction {
12
+ constructor(action) {
13
+ this.action = action;
14
+ }
15
+ launch() {
16
+ return this.action();
17
+ }
18
+ }
19
+ __decorate([
20
+ reactive,
21
+ __metadata("design:type", Function),
22
+ __metadata("design:paramtypes", []),
23
+ __metadata("design:returntype", Object)
24
+ ], Reaction.prototype, "launch", null);
@@ -1,9 +1,9 @@
1
1
  import { F } from './util/Utils.js';
2
- import { Controller } from './Controller.js';
2
+ import { AbstractReaction } from './Reaction.js';
3
3
  import { MemberOptions, LoggingOptions, ProfilingOptions } from './Options.js';
4
4
  export declare class Rx {
5
5
  static why(brief?: boolean): string;
6
- static getController<T>(method: F<T>): Controller<T>;
6
+ static getReaction<T>(method: F<T>): AbstractReaction<T>;
7
7
  static pullLastResult<T>(method: F<Promise<T>>, args?: any[]): T | undefined;
8
8
  static configureCurrentOperation(options: Partial<MemberOptions>): MemberOptions;
9
9
  static getRevisionOf(obj: any): number;
@@ -18,6 +18,7 @@ export declare class Rx {
18
18
  static getLoggingHint<T extends object>(obj: T, full?: boolean): string | undefined;
19
19
  static setProfilingMode(isOn: boolean, options?: Partial<ProfilingOptions>): void;
20
20
  }
21
+ export declare function transaction<T>(action: F<T>, ...args: any[]): T;
21
22
  export declare function nonreactive<T>(func: F<T>, ...args: any[]): T;
22
23
  export declare function sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
23
24
  export declare function raw(proto: object, prop: PropertyKey): any;
@@ -3,12 +3,13 @@ import { Kind } from './Options.js';
3
3
  import { Meta, ObjectHandle } from './impl/Data.js';
4
4
  import { Changeset } from './impl/Changeset.js';
5
5
  import { Mvcc } from './impl/Mvcc.js';
6
- import { OperationController } from './impl/Operation.js';
6
+ import { Transaction } from './impl/Transaction.js';
7
+ import { ReactionImpl } from './impl/Reaction.js';
7
8
  export class Rx {
8
- static why(brief = false) { return brief ? OperationController.briefWhy() : OperationController.why(); }
9
- static getController(method) { return OperationController.getControllerOf(method); }
10
- static pullLastResult(method, args) { return Rx.getController(method).pullLastResult(args); }
11
- static configureCurrentOperation(options) { return OperationController.configureImpl(undefined, options); }
9
+ static why(brief = false) { return brief ? ReactionImpl.briefWhy() : ReactionImpl.why(); }
10
+ static getReaction(method) { return ReactionImpl.getControllerOf(method); }
11
+ static pullLastResult(method, args) { return Rx.getReaction(method).pullLastResult(args); }
12
+ static configureCurrentOperation(options) { return ReactionImpl.configureImpl(undefined, options); }
12
13
  static getRevisionOf(obj) { return obj[Meta.Revision]; }
13
14
  static takeSnapshot(obj) { return Changeset.takeSnapshot(obj); }
14
15
  static dispose(obj) { Changeset.dispose(obj); }
@@ -21,8 +22,11 @@ export class Rx {
21
22
  static getLoggingHint(obj, full = false) { return ObjectHandle.getHint(obj, full); }
22
23
  static setProfilingMode(isOn, options) { Mvcc.setProfilingMode(isOn, options); }
23
24
  }
25
+ export function transaction(action, ...args) {
26
+ return Transaction.run(null, action, ...args);
27
+ }
24
28
  export function nonreactive(func, ...args) {
25
- return OperationController.runWithin(undefined, func, ...args);
29
+ return ReactionImpl.proceedWithinGivenLaunch(undefined, func, ...args);
26
30
  }
27
31
  export function sensitive(sensitivity, func, ...args) {
28
32
  return Mvcc.sensitive(sensitivity, func, ...args);
@@ -1,13 +1,13 @@
1
1
  export { all, pause } from './util/Utils.js';
2
2
  export { MergeList } from './util/MergeList.js';
3
- export type { MergeItem as Item, MergeListReader } from './util/MergeList.js';
3
+ export type { MergeItem, MergeListReader } from './util/MergeList.js';
4
4
  export { SealedArray } from './util/SealedArray.js';
5
5
  export { SealedMap } from './util/SealedMap.js';
6
6
  export { SealedSet } from './util/SealedSet.js';
7
7
  export { Kind, Reentrance, LoggingLevel } from './Options.js';
8
8
  export type { MemberOptions, SnapshotOptions, LoggingOptions, ProfilingOptions } from './Options.js';
9
9
  export type { Worker } from './Worker.js';
10
- export { Controller } from './Controller.js';
10
+ export type { AbstractReaction } from './Reaction.js';
11
11
  export { Ref, ToggleRef, refs, toggleRefs, customToggleRefs } from './Ref.js';
12
12
  export type { BoolOnly, GivenTypeOnly } from './Ref.js';
13
13
  export { TransactionalObject, ObservableObject } from './impl/Mvcc.js';
@@ -17,5 +17,5 @@ export { Changeset } from './impl/Changeset.js';
17
17
  export { Transaction } from './impl/Transaction.js';
18
18
  export { Monitor } from './impl/Monitor.js';
19
19
  export { Journal } from './impl/Journal.js';
20
- export { Rx, raw, observable, transactional, reactive, cached, nonreactive, sensitive, options } from './Rx.js';
20
+ export { Rx, raw, observable, transactional, reactive, cached, transaction, nonreactive, sensitive, options } from './Rx.js';
21
21
  export { Clock } from './Clock.js';
@@ -4,7 +4,6 @@ export { SealedArray } from './util/SealedArray.js';
4
4
  export { SealedMap } from './util/SealedMap.js';
5
5
  export { SealedSet } from './util/SealedSet.js';
6
6
  export { Kind, Reentrance, LoggingLevel } from './Options.js';
7
- export { Controller } from './Controller.js';
8
7
  export { Ref, ToggleRef, refs, toggleRefs, customToggleRefs } from './Ref.js';
9
8
  export { TransactionalObject, ObservableObject } from './impl/Mvcc.js';
10
9
  export { TransactionalArray, ObservableArray } from './impl/MvccArray.js';
@@ -13,5 +12,5 @@ export { Changeset } from './impl/Changeset.js';
13
12
  export { Transaction } from './impl/Transaction.js';
14
13
  export { Monitor } from './impl/Monitor.js';
15
14
  export { Journal } from './impl/Journal.js';
16
- export { Rx, raw, observable, transactional, reactive, cached, nonreactive, sensitive, options } from './Rx.js';
15
+ export { Rx, raw, observable, transactional, reactive, cached, transaction, nonreactive, sensitive, options } from './Rx.js';
17
16
  export { Clock } from './Clock.js';
@@ -1,5 +1,5 @@
1
1
  import { Kind, SnapshotOptions } from '../Options.js';
2
- import { AbstractChangeset, ObjectSnapshot, MemberName, ObjectHandle, ObservableValue, Observer } from './Data.js';
2
+ import { AbstractChangeset, ObjectSnapshot, MemberName, ObjectHandle, MvccValue, Observer } from './Data.js';
3
3
  export declare const MAX_REVISION: number;
4
4
  export declare const UNDEFINED_REVISION: number;
5
5
  export declare class Changeset implements AbstractChangeset {
@@ -18,12 +18,12 @@ export declare class Changeset implements AbstractChangeset {
18
18
  private revision;
19
19
  private bumper;
20
20
  items: Map<ObjectHandle, ObjectSnapshot>;
21
- reactive: Observer[];
21
+ obsolete: Observer[];
22
22
  sealed: boolean;
23
23
  constructor(options: SnapshotOptions | null);
24
24
  static current: () => Changeset;
25
25
  static edit: () => Changeset;
26
- static markUsed: (observable: ObservableValue, os: ObjectSnapshot, m: MemberName, h: ObjectHandle, kind: Kind, weak: boolean) => void;
26
+ static markUsed: (observable: MvccValue, os: ObjectSnapshot, m: MemberName, h: ObjectHandle, kind: Kind, weak: boolean) => void;
27
27
  static markEdited: (oldValue: any, newValue: any, edited: boolean, os: ObjectSnapshot, m: MemberName, h: ObjectHandle) => void;
28
28
  static isConflicting: (oldValue: any, newValue: any) => boolean;
29
29
  static propagateAllChangesThroughSubscriptions: (changeset: Changeset) => void;
@@ -42,7 +42,7 @@ export declare class Changeset implements AbstractChangeset {
42
42
  private merge;
43
43
  applyOrDiscard(error?: any): Array<Observer>;
44
44
  static sealObjectSnapshot(h: ObjectHandle, os: ObjectSnapshot): void;
45
- static sealObservableValue(o: ObservableValue | symbol, m: MemberName, typeName: string): void;
45
+ static sealMvccValue(o: MvccValue | symbol, m: MemberName, typeName: string): void;
46
46
  static freezeObjectSnapshot(os: ObjectSnapshot): ObjectSnapshot;
47
47
  triggerGarbageCollection(): void;
48
48
  private unlinkHistory;
@@ -51,7 +51,7 @@ export declare class Changeset implements AbstractChangeset {
51
51
  export declare class Dump {
52
52
  static valueHint: (value: any) => string;
53
53
  static obj(h: ObjectHandle | undefined, m?: MemberName | undefined, stamp?: number, snapshotId?: number, originSnapshotId?: number, value?: any): string;
54
- static snapshot2(h: ObjectHandle, s: AbstractChangeset, m?: MemberName, o?: ObservableValue): string;
54
+ static snapshot2(h: ObjectHandle, s: AbstractChangeset, m?: MemberName, o?: MvccValue): string;
55
55
  static snapshot(os: ObjectSnapshot, m?: MemberName): string;
56
56
  static conflicts(conflicts: ObjectSnapshot[]): string;
57
57
  static conflictingMemberHint(m: MemberName, ours: ObjectSnapshot, theirs: ObjectSnapshot): string;
@@ -4,7 +4,7 @@ import { Sealant } from '../util/Sealant.js';
4
4
  import { SealedArray } from '../util/SealedArray.js';
5
5
  import { SealedMap } from '../util/SealedMap.js';
6
6
  import { SealedSet } from '../util/SealedSet.js';
7
- import { ObjectSnapshot, ObjectHandle, ObservableValue, Meta } from './Data.js';
7
+ import { ObjectSnapshot, ObjectHandle, MvccValue, Meta } from './Data.js';
8
8
  export const MAX_REVISION = Number.MAX_SAFE_INTEGER;
9
9
  export const UNDEFINED_REVISION = MAX_REVISION - 1;
10
10
  Object.defineProperty(ObjectHandle.prototype, '#this#', {
@@ -14,7 +14,7 @@ Object.defineProperty(ObjectHandle.prototype, '#this#', {
14
14
  const data = Changeset.current().getObjectSnapshot(this, '#this#').data;
15
15
  for (const m in data) {
16
16
  const v = data[m];
17
- if (v instanceof ObservableValue)
17
+ if (v instanceof MvccValue)
18
18
  result[m] = v.content;
19
19
  else if (v === Meta.Raw)
20
20
  result[m] = this.data[m];
@@ -35,7 +35,7 @@ export class Changeset {
35
35
  this.revision = UNDEFINED_REVISION;
36
36
  this.bumper = 100;
37
37
  this.items = new Map();
38
- this.reactive = [];
38
+ this.obsolete = [];
39
39
  this.sealed = false;
40
40
  }
41
41
  lookupObjectSnapshot(h, m) {
@@ -67,7 +67,7 @@ export class Changeset {
67
67
  const revision = m === Meta.Handle ? 1 : os.revision + 1;
68
68
  const data = Object.assign({}, m === Meta.Handle ? value : os.data);
69
69
  Meta.set(data, Meta.Handle, h);
70
- Meta.set(data, Meta.Revision, new ObservableValue(revision));
70
+ Meta.set(data, Meta.Revision, new MvccValue(revision));
71
71
  os = new ObjectSnapshot(this, os, data);
72
72
  this.items.set(h, os);
73
73
  h.editing = os;
@@ -214,19 +214,19 @@ export class Changeset {
214
214
  }
215
215
  if (!error)
216
216
  Changeset.propagateAllChangesThroughSubscriptions(this);
217
- return this.reactive;
217
+ return this.obsolete;
218
218
  }
219
219
  static sealObjectSnapshot(h, os) {
220
220
  if (!os.disposed)
221
- os.changes.forEach((o, m) => Changeset.sealObservableValue(os.data[m], m, h.proxy.constructor.name));
221
+ os.changes.forEach((o, m) => Changeset.sealMvccValue(os.data[m], m, h.proxy.constructor.name));
222
222
  else
223
223
  for (const m in os.former.snapshot.data)
224
224
  os.data[m] = Meta.Undefined;
225
225
  if (Log.isOn)
226
226
  Changeset.freezeObjectSnapshot(os);
227
227
  }
228
- static sealObservableValue(o, m, typeName) {
229
- if (o instanceof ObservableValue) {
228
+ static sealMvccValue(o, m, typeName) {
229
+ if (o instanceof MvccValue) {
230
230
  const value = o.content;
231
231
  if (value !== undefined && value !== null) {
232
232
  const sealedType = Object.getPrototypeOf(value)[Sealant.SealedType];
@@ -276,7 +276,7 @@ export class Changeset {
276
276
  os.former.snapshot = EMPTY_SNAPSHOT;
277
277
  });
278
278
  this.items = EMPTY_MAP;
279
- this.reactive = EMPTY_ARRAY;
279
+ this.obsolete = EMPTY_ARRAY;
280
280
  if (Log.isOn)
281
281
  Object.freeze(this);
282
282
  }
@@ -5,7 +5,7 @@ export interface AbstractChangeset {
5
5
  readonly timestamp: number;
6
6
  readonly sealed: boolean;
7
7
  }
8
- export declare class ObservableValue {
8
+ export declare class MvccValue {
9
9
  content: any;
10
10
  observers?: Set<Observer>;
11
11
  get isOperation(): boolean;
@@ -15,11 +15,11 @@ export declare class ObservableValue {
15
15
  export type SeparationMode = boolean | 'isolated' | 'disposal';
16
16
  export interface Observer {
17
17
  readonly order: number;
18
- readonly observables: Map<ObservableValue, Subscription> | undefined;
18
+ readonly observables: Map<MvccValue, Subscription> | undefined;
19
19
  readonly obsoleteSince: number;
20
20
  hint(nop?: boolean): string;
21
- markObsoleteDueTo(observable: ObservableValue, m: MemberName, changeset: AbstractChangeset, h: ObjectHandle, outer: string, since: number, reactive: Array<Observer>): void;
22
- runIfNotUpToDate(now: boolean, nothrow: boolean): void;
21
+ markObsoleteDueTo(observable: MvccValue, m: MemberName, changeset: AbstractChangeset, h: ObjectHandle, outer: string, since: number, reactive: Array<Observer>): void;
22
+ relaunchIfNotUpToDate(now: boolean, nothrow: boolean): void;
23
23
  }
24
24
  export type MemberName = PropertyKey;
25
25
  export interface Subscription {
@@ -1,7 +1,7 @@
1
1
  import { Log } from '../util/Dbg.js';
2
2
  import { Meta } from './Meta.js';
3
3
  export { Meta } from './Meta.js';
4
- export class ObservableValue {
4
+ export class MvccValue {
5
5
  get isOperation() { return false; }
6
6
  get originSnapshotId() { return 0; }
7
7
  constructor(content) { this.content = content; }
@@ -1,5 +1,5 @@
1
1
  import { ObservableObject } from './Mvcc.js';
2
- import { Meta, ObservableValue } from './Data.js';
2
+ import { Meta, MvccValue } from './Data.js';
3
3
  import { Changeset, EMPTY_SNAPSHOT } from './Changeset.js';
4
4
  import { Transaction } from './Transaction.js';
5
5
  import { Sealant } from '../util/Sealant.js';
@@ -99,7 +99,7 @@ export class JournalImpl extends Journal {
99
99
  const value = undoing ? vp.formerValue : vp.freshValue;
100
100
  const os = ctx.getEditableObjectSnapshot(h, m, value);
101
101
  if (os.changeset === ctx) {
102
- os.data[m] = new ObservableValue(value);
102
+ os.data[m] = new MvccValue(value);
103
103
  const existing = os.former.snapshot.data[m];
104
104
  Changeset.markEdited(existing, value, existing !== value, os, m, h);
105
105
  }
@@ -1,7 +1,7 @@
1
1
  import { UNDEF } from '../util/Utils.js';
2
2
  import { Log, misuse } from '../util/Dbg.js';
3
3
  import { Kind, Reentrance } from '../Options.js';
4
- import { ObjectSnapshot, ObjectHandle, ObservableValue, Meta } from './Data.js';
4
+ import { ObjectSnapshot, ObjectHandle, MvccValue, Meta } from './Data.js';
5
5
  import { Changeset, Dump, EMPTY_SNAPSHOT } from './Changeset.js';
6
6
  export class MvccObject {
7
7
  constructor(observable) {
@@ -72,7 +72,7 @@ export class Mvcc {
72
72
  const cs = Changeset.current();
73
73
  const os = cs.getObjectSnapshot(h, m);
74
74
  result = os.data[m];
75
- if (result instanceof ObservableValue && !result.isOperation) {
75
+ if (result instanceof MvccValue && !result.isOperation) {
76
76
  if (this.isObservable)
77
77
  Changeset.markUsed(result, os, m, h, Kind.Plain, false);
78
78
  result = result.content;
@@ -92,7 +92,7 @@ export class Mvcc {
92
92
  if (curr === undefined || curr.content !== value || Mvcc.sensitivity) {
93
93
  const existing = curr === null || curr === void 0 ? void 0 : curr.content;
94
94
  if (os.former.snapshot.data[m] === curr) {
95
- curr = os.data[m] = new ObservableValue(value);
95
+ curr = os.data[m] = new MvccValue(value);
96
96
  Changeset.markEdited(existing, value, true, os, m, h);
97
97
  }
98
98
  else {
@@ -130,14 +130,14 @@ export class Mvcc {
130
130
  const result = [];
131
131
  for (const m of Object.getOwnPropertyNames(os.data)) {
132
132
  const value = os.data[m];
133
- if (!(value instanceof ObservableValue) || !value.isOperation)
133
+ if (!(value instanceof MvccValue) || !value.isOperation)
134
134
  result.push(m);
135
135
  }
136
136
  return result;
137
137
  }
138
138
  static decorateData(isObservable, proto, member) {
139
139
  if (isObservable) {
140
- Meta.acquire(proto, Meta.Initial)[member] = new ObservableValue(undefined);
140
+ Meta.acquire(proto, Meta.Initial)[member] = new MvccValue(undefined);
141
141
  const get = function () {
142
142
  const h = Mvcc.acquireHandle(this);
143
143
  return Mvcc.observable.get(h, member, this);
@@ -196,7 +196,7 @@ export class Mvcc {
196
196
  h = new ObjectHandle(obj, obj, Mvcc.observable, os, obj.constructor.name);
197
197
  Meta.set(os.data, Meta.Handle, h);
198
198
  Meta.set(obj, Meta.Handle, h);
199
- Meta.set(os.data, Meta.Revision, new ObservableValue(1));
199
+ Meta.set(os.data, Meta.Revision, new MvccValue(1));
200
200
  }
201
201
  return h;
202
202
  }
@@ -1,10 +1,10 @@
1
1
  import { F } from '../util/Utils.js';
2
2
  import { MemberOptions } from '../Options.js';
3
- import { Controller } from '../Controller.js';
4
- import { MemberName, ObjectHandle, ObservableValue, Observer, Subscription, AbstractChangeset } from './Data.js';
3
+ import { AbstractReaction } from '../Reaction.js';
4
+ import { MemberName, ObjectHandle, MvccValue, Observer, Subscription, AbstractChangeset } from './Data.js';
5
5
  import { Transaction } from './Transaction.js';
6
6
  import { OptionsImpl } from './Mvcc.js';
7
- export declare class OperationController extends Controller<any> {
7
+ export declare class ReactionImpl implements AbstractReaction<any> {
8
8
  readonly objectHandle: ObjectHandle;
9
9
  readonly memberName: MemberName;
10
10
  configure(options: Partial<MemberOptions>): MemberOptions;
@@ -18,10 +18,10 @@ export declare class OperationController extends Controller<any> {
18
18
  markObsolete(): void;
19
19
  pullLastResult(args?: any[]): any;
20
20
  constructor(h: ObjectHandle, m: MemberName);
21
- useOrRun(weak: boolean, args: any[] | undefined): Operation;
22
- static getControllerOf(method: F<any>): Controller<any>;
23
- static configureImpl(self: OperationController | undefined, options: Partial<MemberOptions>): MemberOptions;
24
- static runWithin<T>(op: Operation | undefined, func: F<T>, ...args: any[]): T;
21
+ reuseOrRelaunch(weak: boolean, args: any[] | undefined): Launch;
22
+ static getControllerOf(method: F<any>): AbstractReaction<any>;
23
+ static configureImpl(self: ReactionImpl | undefined, options: Partial<MemberOptions>): MemberOptions;
24
+ static proceedWithinGivenLaunch<T>(launch: Launch | undefined, func: F<T>, ...args: any[]): T;
25
25
  static why(): string;
26
26
  static briefWhy(): string;
27
27
  static dependencies(): string[];
@@ -29,18 +29,18 @@ export declare class OperationController extends Controller<any> {
29
29
  private use;
30
30
  private edit;
31
31
  private acquireFromSnapshot;
32
- private run;
32
+ private relaunch;
33
33
  private static markObsolete;
34
34
  }
35
- declare class Operation extends ObservableValue implements Observer {
36
- static current?: Operation;
35
+ declare class Launch extends MvccValue implements Observer {
36
+ static current?: Launch;
37
37
  static queuedReactiveFunctions: Array<Observer>;
38
- static deferredReactiveFunctions: Array<Operation>;
38
+ static deferredReactiveFunctions: Array<Launch>;
39
39
  readonly margin: number;
40
40
  readonly transaction: Transaction;
41
- readonly controller: OperationController;
41
+ readonly reaction: ReactionImpl;
42
42
  readonly changeset: AbstractChangeset;
43
- observables: Map<ObservableValue, Subscription> | undefined;
43
+ observables: Map<MvccValue, Subscription> | undefined;
44
44
  options: OptionsImpl;
45
45
  cause: string | undefined;
46
46
  args: any[];
@@ -49,8 +49,8 @@ declare class Operation extends ObservableValue implements Observer {
49
49
  started: number;
50
50
  obsoleteDueTo: string | undefined;
51
51
  obsoleteSince: number;
52
- successor: Operation | undefined;
53
- constructor(controller: OperationController, changeset: AbstractChangeset, former: Operation | OptionsImpl);
52
+ successor: Launch | undefined;
53
+ constructor(reaction: ReactionImpl, changeset: AbstractChangeset, former: Launch | OptionsImpl);
54
54
  get isOperation(): boolean;
55
55
  get originSnapshotId(): number;
56
56
  hint(): string;
@@ -60,12 +60,12 @@ declare class Operation extends ObservableValue implements Observer {
60
60
  briefWhy(): string;
61
61
  dependencies(): string[];
62
62
  wrap<T>(func: F<T>): F<T>;
63
- run(proxy: any, args: any[] | undefined): void;
64
- markObsoleteDueTo(observable: ObservableValue, m: MemberName, changeset: AbstractChangeset, h: ObjectHandle, outer: string, since: number, reactive: Observer[]): void;
65
- runIfNotUpToDate(now: boolean, nothrow: boolean): void;
63
+ proceed(proxy: any, args: any[] | undefined): void;
64
+ markObsoleteDueTo(observable: MvccValue, m: MemberName, changeset: AbstractChangeset, h: ObjectHandle, outer: string, since: number, obsolete: Observer[]): void;
65
+ relaunchIfNotUpToDate(now: boolean, nothrow: boolean): void;
66
66
  isNotUpToDate(): boolean;
67
- reenterOver(head: Operation): this;
68
- private static run;
67
+ reenterOver(head: Launch): this;
68
+ private static proceed;
69
69
  private enter;
70
70
  private leaveOrAsync;
71
71
  private leave;
@@ -80,7 +80,7 @@ declare class Operation extends ObservableValue implements Observer {
80
80
  private static revokeAllSubscriptions;
81
81
  private static propagateMemberChangeThroughSubscriptions;
82
82
  private static enqueueReactiveFunctionsToRun;
83
- private static runQueuedReactiveLoop;
83
+ private static runQueuedReactiveFunctions;
84
84
  private unsubscribeFromAllObservables;
85
85
  private subscribeTo;
86
86
  private static canSubscribeTo;
@@ -1,7 +1,6 @@
1
1
  import { Log, misuse } from '../util/Dbg.js';
2
2
  import { Kind, Reentrance } from '../Options.js';
3
- import { Controller } from '../Controller.js';
4
- import { ObjectHandle, ObservableValue, Meta } from './Data.js';
3
+ import { ObjectHandle, MvccValue, Meta } from './Data.js';
5
4
  import { Changeset, Dump, EMPTY_SNAPSHOT, MAX_REVISION } from './Changeset.js';
6
5
  import { Transaction } from './Transaction.js';
7
6
  import { MonitorImpl } from './Monitor.js';
@@ -10,47 +9,46 @@ import { JournalImpl } from './Journal.js';
10
9
  const BOOT_ARGS = [];
11
10
  const BOOT_CAUSE = '<boot>';
12
11
  const EMPTY_HANDLE = new ObjectHandle(undefined, undefined, Mvcc.observable, EMPTY_SNAPSHOT, '<boot>');
13
- export class OperationController extends Controller {
14
- configure(options) { return OperationController.configureImpl(this, options); }
15
- get options() { return this.peek(undefined).operation.options; }
16
- get unobservable() { return this.peek(undefined).operation.content; }
17
- get args() { return this.use().operation.args; }
18
- get result() { return this.useOrRun(true, undefined).content; }
19
- get error() { return this.use().operation.error; }
12
+ export class ReactionImpl {
13
+ configure(options) { return ReactionImpl.configureImpl(this, options); }
14
+ get options() { return this.peek(undefined).launch.options; }
15
+ get unobservable() { return this.peek(undefined).launch.content; }
16
+ get args() { return this.use().launch.args; }
17
+ get result() { return this.reuseOrRelaunch(true, undefined).content; }
18
+ get error() { return this.use().launch.error; }
20
19
  get stamp() { return this.use().snapshot.changeset.timestamp; }
21
20
  get isUpToDate() { return this.use().isUpToDate; }
22
- markObsolete() { Transaction.run({ hint: Log.isOn ? `markObsolete(${Dump.obj(this.objectHandle, this.memberName)})` : 'markObsolete()' }, OperationController.markObsolete, this); }
23
- pullLastResult(args) { return this.useOrRun(true, args).content; }
21
+ markObsolete() { Transaction.run({ hint: Log.isOn ? `markObsolete(${Dump.obj(this.objectHandle, this.memberName)})` : 'markObsolete()' }, ReactionImpl.markObsolete, this); }
22
+ pullLastResult(args) { return this.reuseOrRelaunch(true, args).content; }
24
23
  constructor(h, m) {
25
- super();
26
24
  this.objectHandle = h;
27
25
  this.memberName = m;
28
26
  }
29
- useOrRun(weak, args) {
27
+ reuseOrRelaunch(weak, args) {
30
28
  var _a;
31
- let oc = this.peek(args);
32
- const ctx = oc.changeset;
33
- const op = oc.operation;
34
- const opts = op.options;
35
- if (!oc.isUpToDate && !oc.snapshot.disposed
36
- && (!weak || op.cause === BOOT_CAUSE || !op.successor ||
37
- op.successor.transaction.isFinished)) {
38
- const outerOpts = (_a = Operation.current) === null || _a === void 0 ? void 0 : _a.options;
29
+ let ror = this.peek(args);
30
+ const ctx = ror.changeset;
31
+ const launch = ror.launch;
32
+ const opts = launch.options;
33
+ if (!ror.isUpToDate && !ror.snapshot.disposed
34
+ && (!weak || launch.cause === BOOT_CAUSE || !launch.successor ||
35
+ launch.successor.transaction.isFinished)) {
36
+ const outerOpts = (_a = Launch.current) === null || _a === void 0 ? void 0 : _a.options;
39
37
  const separation = weak || opts.separation !== false || opts.kind === Kind.Reactive ||
40
38
  (opts.kind === Kind.Transactional && outerOpts && (outerOpts.noSideEffects || outerOpts.kind === Kind.Cached)) ||
41
- (opts.kind === Kind.Cached && (oc.snapshot.changeset.sealed ||
42
- oc.snapshot.former.snapshot !== EMPTY_SNAPSHOT));
39
+ (opts.kind === Kind.Cached && (ror.snapshot.changeset.sealed ||
40
+ ror.snapshot.former.snapshot !== EMPTY_SNAPSHOT));
43
41
  const token = opts.noSideEffects ? this : undefined;
44
- const oc2 = this.run(oc, separation, opts, token, args);
45
- const ctx2 = oc2.operation.changeset;
42
+ const ror2 = this.relaunch(ror, separation, opts, token, args);
43
+ const ctx2 = ror2.launch.changeset;
46
44
  if (!weak || ctx === ctx2 || (ctx2.sealed && ctx.timestamp >= ctx2.timestamp))
47
- oc = oc2;
45
+ ror = ror2;
48
46
  }
49
47
  else if (Log.isOn && Log.opt.operation && (opts.logging === undefined ||
50
48
  opts.logging.operation === undefined || opts.logging.operation === true))
51
- Log.write(Transaction.current.isFinished ? '' : '║', ' (=)', `${Dump.snapshot2(oc.operation.controller.objectHandle, oc.changeset, this.memberName)} result is reused from T${oc.operation.transaction.id}[${oc.operation.transaction.hint}]`);
52
- const t = oc.operation;
53
- Changeset.markUsed(t, oc.snapshot, this.memberName, this.objectHandle, t.options.kind, weak);
49
+ Log.write(Transaction.current.isFinished ? '' : '║', ' (=)', `${Dump.snapshot2(ror.launch.reaction.objectHandle, ror.changeset, this.memberName)} result is reused from T${ror.launch.transaction.id}[${ror.launch.transaction.hint}]`);
50
+ const t = ror.launch;
51
+ Changeset.markUsed(t, ror.snapshot, this.memberName, this.objectHandle, t.options.kind, weak);
54
52
  return t;
55
53
  }
56
54
  static getControllerOf(method) {
@@ -60,154 +58,154 @@ export class OperationController extends Controller {
60
58
  return ctl;
61
59
  }
62
60
  static configureImpl(self, options) {
63
- let op;
61
+ let launch;
64
62
  if (self)
65
- op = self.edit().operation;
63
+ launch = self.edit().launch;
66
64
  else
67
- op = Operation.current;
68
- if (!op)
65
+ launch = Launch.current;
66
+ if (!launch)
69
67
  throw misuse('reactronic decorator is only applicable to methods');
70
- op.options = new OptionsImpl(op.options.getter, op.options.setter, op.options, options, false);
68
+ launch.options = new OptionsImpl(launch.options.getter, launch.options.setter, launch.options, options, false);
71
69
  if (Log.isOn && Log.opt.write)
72
- Log.write('║', ' =', `${op.hint()}.options are changed`);
73
- return op.options;
70
+ Log.write('║', ' =', `${launch.hint()}.options are changed`);
71
+ return launch.options;
74
72
  }
75
- static runWithin(op, func, ...args) {
73
+ static proceedWithinGivenLaunch(launch, func, ...args) {
76
74
  let result = undefined;
77
- const outer = Operation.current;
75
+ const outer = Launch.current;
78
76
  try {
79
- Operation.current = op;
77
+ Launch.current = launch;
80
78
  result = func(...args);
81
79
  }
82
80
  catch (e) {
83
- if (op)
84
- op.error = e;
81
+ if (launch)
82
+ launch.error = e;
85
83
  throw e;
86
84
  }
87
85
  finally {
88
- Operation.current = outer;
86
+ Launch.current = outer;
89
87
  }
90
88
  return result;
91
89
  }
92
90
  static why() {
93
91
  var _a, _b;
94
- return (_b = (_a = Operation.current) === null || _a === void 0 ? void 0 : _a.why()) !== null && _b !== void 0 ? _b : BOOT_CAUSE;
92
+ return (_b = (_a = Launch.current) === null || _a === void 0 ? void 0 : _a.why()) !== null && _b !== void 0 ? _b : BOOT_CAUSE;
95
93
  }
96
94
  static briefWhy() {
97
95
  var _a, _b;
98
- return (_b = (_a = Operation.current) === null || _a === void 0 ? void 0 : _a.briefWhy()) !== null && _b !== void 0 ? _b : BOOT_CAUSE;
96
+ return (_b = (_a = Launch.current) === null || _a === void 0 ? void 0 : _a.briefWhy()) !== null && _b !== void 0 ? _b : BOOT_CAUSE;
99
97
  }
100
98
  static dependencies() {
101
- const op = Operation.current;
102
- return op ? op.dependencies() : ['Rx.dependencies should be called from inside of reactive method'];
99
+ const l = Launch.current;
100
+ return l ? l.dependencies() : ['Rx.dependencies should be called from inside of reactive method'];
103
101
  }
104
102
  peek(args) {
105
103
  const ctx = Changeset.current();
106
104
  const os = ctx.lookupObjectSnapshot(this.objectHandle, this.memberName);
107
- const op = this.acquireFromSnapshot(os, args);
108
- const isValid = op.options.kind !== Kind.Transactional && op.cause !== BOOT_CAUSE &&
109
- (ctx === op.changeset || ctx.timestamp < op.obsoleteSince) &&
110
- (!op.options.triggeringArgs || args === undefined ||
111
- op.args.length === args.length && op.args.every((t, i) => t === args[i])) || os.disposed;
112
- return { operation: op, isUpToDate: isValid, changeset: ctx, snapshot: os };
105
+ const launch = this.acquireFromSnapshot(os, args);
106
+ const isValid = launch.options.kind !== Kind.Transactional && launch.cause !== BOOT_CAUSE &&
107
+ (ctx === launch.changeset || ctx.timestamp < launch.obsoleteSince) &&
108
+ (!launch.options.triggeringArgs || args === undefined ||
109
+ launch.args.length === args.length && launch.args.every((t, i) => t === args[i])) || os.disposed;
110
+ return { launch, isUpToDate: isValid, changeset: ctx, snapshot: os };
113
111
  }
114
112
  use() {
115
- const oc = this.peek(undefined);
116
- Changeset.markUsed(oc.operation, oc.snapshot, this.memberName, this.objectHandle, oc.operation.options.kind, true);
117
- return oc;
113
+ const ror = this.peek(undefined);
114
+ Changeset.markUsed(ror.launch, ror.snapshot, this.memberName, this.objectHandle, ror.launch.options.kind, true);
115
+ return ror;
118
116
  }
119
117
  edit() {
120
118
  const h = this.objectHandle;
121
119
  const m = this.memberName;
122
120
  const ctx = Changeset.edit();
123
121
  const os = ctx.getEditableObjectSnapshot(h, m, Meta.Handle, this);
124
- let op = this.acquireFromSnapshot(os, undefined);
125
- if (op.changeset !== os.changeset) {
126
- const op2 = new Operation(this, os.changeset, op);
127
- os.data[m] = op2.reenterOver(op);
122
+ let launch = this.acquireFromSnapshot(os, undefined);
123
+ if (launch.changeset !== os.changeset) {
124
+ const relaunch = new Launch(this, os.changeset, launch);
125
+ os.data[m] = relaunch.reenterOver(launch);
128
126
  ctx.bumpBy(os.former.snapshot.changeset.timestamp);
129
- Changeset.markEdited(op, op2, true, os, m, h);
130
- op = op2;
127
+ Changeset.markEdited(launch, relaunch, true, os, m, h);
128
+ launch = relaunch;
131
129
  }
132
- return { operation: op, isUpToDate: true, changeset: ctx, snapshot: os };
130
+ return { launch, isUpToDate: true, changeset: ctx, snapshot: os };
133
131
  }
134
132
  acquireFromSnapshot(os, args) {
135
133
  const m = this.memberName;
136
- let op = os.data[m];
137
- if (op.controller !== this) {
134
+ let launch = os.data[m];
135
+ if (launch.reaction !== this) {
138
136
  if (os.changeset !== EMPTY_SNAPSHOT.changeset) {
139
137
  const hint = Log.isOn ? `${Dump.obj(this.objectHandle, m)}/init` : 'MethodController/init';
140
138
  const separation = os.changeset.sealed || os.former.snapshot !== EMPTY_SNAPSHOT;
141
- op = Transaction.run({ hint, separation, token: this }, () => {
139
+ launch = Transaction.run({ hint, separation, token: this }, () => {
142
140
  const h = this.objectHandle;
143
- let r2 = Changeset.current().getObjectSnapshot(h, m);
144
- let op2 = r2.data[m];
145
- if (op2.controller !== this) {
146
- r2 = Changeset.edit().getEditableObjectSnapshot(h, m, Meta.Handle, this);
147
- const t = new Operation(this, r2.changeset, op2);
141
+ let r = Changeset.current().getObjectSnapshot(h, m);
142
+ let relaunch = r.data[m];
143
+ if (relaunch.reaction !== this) {
144
+ r = Changeset.edit().getEditableObjectSnapshot(h, m, Meta.Handle, this);
145
+ const t = new Launch(this, r.changeset, relaunch);
148
146
  if (args)
149
147
  t.args = args;
150
148
  t.cause = BOOT_CAUSE;
151
- r2.data[m] = t;
152
- Changeset.markEdited(op2, t, true, r2, m, h);
153
- op2 = t;
149
+ r.data[m] = t;
150
+ Changeset.markEdited(relaunch, t, true, r, m, h);
151
+ relaunch = t;
154
152
  }
155
- return op2;
153
+ return relaunch;
156
154
  });
157
155
  }
158
156
  else {
159
- const t = new Operation(this, os.changeset, op);
157
+ const initialLaunch = new Launch(this, os.changeset, launch);
160
158
  if (args)
161
- t.args = args;
162
- t.cause = BOOT_CAUSE;
163
- os.data[m] = t;
164
- op = t;
159
+ initialLaunch.args = args;
160
+ initialLaunch.cause = BOOT_CAUSE;
161
+ os.data[m] = initialLaunch;
162
+ launch = initialLaunch;
165
163
  if (Log.isOn && Log.opt.write)
166
164
  Log.write('║', ' ++', `${Dump.obj(this.objectHandle, m)} is initialized (revision ${os.revision})`);
167
165
  }
168
166
  }
169
- return op;
167
+ return launch;
170
168
  }
171
- run(existing, separation, options, token, args) {
169
+ relaunch(existing, separation, options, token, args) {
172
170
  const hint = Log.isOn ? `${Dump.obj(this.objectHandle, this.memberName)}${args && args.length > 0 && (typeof args[0] === 'number' || typeof args[0] === 'string') ? ` - ${args[0]}` : ''}` : `${Dump.obj(this.objectHandle, this.memberName)}`;
173
- let oc = existing;
171
+ let ror = existing;
174
172
  const opts = { hint, separation, journal: options.journal, logging: options.logging, token };
175
173
  const result = Transaction.run(opts, (argsx) => {
176
- if (!oc.operation.transaction.isCanceled) {
177
- oc = this.edit();
174
+ if (!ror.launch.transaction.isCanceled) {
175
+ ror = this.edit();
178
176
  if (Log.isOn && Log.opt.operation)
179
- Log.write('║', ' o', `${oc.operation.why()}`);
180
- oc.operation.run(this.objectHandle.proxy, argsx);
177
+ Log.write('║', ' o', `${ror.launch.why()}`);
178
+ ror.launch.proceed(this.objectHandle.proxy, argsx);
181
179
  }
182
180
  else {
183
- oc = this.peek(argsx);
184
- if (oc.operation.options.kind === Kind.Transactional || !oc.isUpToDate) {
185
- oc = this.edit();
181
+ ror = this.peek(argsx);
182
+ if (ror.launch.options.kind === Kind.Transactional || !ror.isUpToDate) {
183
+ ror = this.edit();
186
184
  if (Log.isOn && Log.opt.operation)
187
- Log.write('║', ' o', `${oc.operation.why()}`);
188
- oc.operation.run(this.objectHandle.proxy, argsx);
185
+ Log.write('║', ' o', `${ror.launch.why()}`);
186
+ ror.launch.proceed(this.objectHandle.proxy, argsx);
189
187
  }
190
188
  }
191
- return oc.operation.result;
189
+ return ror.launch.result;
192
190
  }, args);
193
- oc.operation.result = result;
194
- return oc;
191
+ ror.launch.result = result;
192
+ return ror;
195
193
  }
196
194
  static markObsolete(self) {
197
- const oc = self.peek(undefined);
198
- const ctx = oc.changeset;
199
- oc.operation.markObsoleteDueTo(oc.operation, self.memberName, EMPTY_SNAPSHOT.changeset, EMPTY_HANDLE, BOOT_CAUSE, ctx.timestamp, ctx.reactive);
195
+ const ror = self.peek(undefined);
196
+ const ctx = ror.changeset;
197
+ ror.launch.markObsoleteDueTo(ror.launch, self.memberName, EMPTY_SNAPSHOT.changeset, EMPTY_HANDLE, BOOT_CAUSE, ctx.timestamp, ctx.obsolete);
200
198
  }
201
199
  }
202
- class Operation extends ObservableValue {
203
- constructor(controller, changeset, former) {
200
+ class Launch extends MvccValue {
201
+ constructor(reaction, changeset, former) {
204
202
  super(undefined);
205
- this.margin = Operation.current ? Operation.current.margin + 1 : 1;
203
+ this.margin = Launch.current ? Launch.current.margin + 1 : 1;
206
204
  this.transaction = Transaction.current;
207
- this.controller = controller;
205
+ this.reaction = reaction;
208
206
  this.changeset = changeset;
209
207
  this.observables = new Map();
210
- if (former instanceof Operation) {
208
+ if (former instanceof Launch) {
211
209
  this.options = former.options;
212
210
  this.args = former.args;
213
211
  this.cause = former.obsoleteDueTo;
@@ -224,7 +222,7 @@ class Operation extends ObservableValue {
224
222
  }
225
223
  get isOperation() { return true; }
226
224
  get originSnapshotId() { return this.changeset.id; }
227
- hint() { return `${Dump.snapshot2(this.controller.objectHandle, this.changeset, this.controller.memberName)}`; }
225
+ hint() { return `${Dump.snapshot2(this.reaction.objectHandle, this.changeset, this.reaction.memberName)}`; }
228
226
  get order() { return this.options.order; }
229
227
  get ['#this#']() {
230
228
  return `Operation: ${this.why()}`;
@@ -233,7 +231,7 @@ class Operation extends ObservableValue {
233
231
  let cause;
234
232
  if (this.cause)
235
233
  cause = ` ◀◀ ${this.cause}`;
236
- else if (this.controller.options.kind === Kind.Transactional)
234
+ else if (this.reaction.options.kind === Kind.Transactional)
237
235
  cause = ' ◀◀ operation';
238
236
  else
239
237
  cause = ` ◀◀ T${this.changeset.id}[${this.changeset.hint}]`;
@@ -250,7 +248,7 @@ class Operation extends ObservableValue {
250
248
  if (Log.isOn && Log.opt.step && this.result)
251
249
  Log.writeAs({ margin2: this.margin }, '║', '‾\\', `${this.hint()} - step in `, 0, ' │');
252
250
  const started = Date.now();
253
- const result = OperationController.runWithin(this, func, ...args);
251
+ const result = ReactionImpl.proceedWithinGivenLaunch(this, func, ...args);
254
252
  const ms = Date.now() - started;
255
253
  if (Log.isOn && Log.opt.step && this.result)
256
254
  Log.writeAs({ margin2: this.margin }, '║', '_/', `${this.hint()} - step out `, 0, this.started > 0 ? ' │' : '');
@@ -260,16 +258,16 @@ class Operation extends ObservableValue {
260
258
  };
261
259
  return wrappedForOperation;
262
260
  }
263
- run(proxy, args) {
261
+ proceed(proxy, args) {
264
262
  if (args)
265
263
  this.args = args;
266
264
  this.obsoleteSince = MAX_REVISION;
267
265
  if (!this.error)
268
- OperationController.runWithin(this, Operation.run, this, proxy);
266
+ ReactionImpl.proceedWithinGivenLaunch(this, Launch.proceed, this, proxy);
269
267
  else
270
268
  this.result = Promise.reject(this.error);
271
269
  }
272
- markObsoleteDueTo(observable, m, changeset, h, outer, since, reactive) {
270
+ markObsoleteDueTo(observable, m, changeset, h, outer, since, obsolete) {
273
271
  var _a, _b, _c;
274
272
  if (this.observables !== undefined) {
275
273
  const skip = !observable.isOperation &&
@@ -285,9 +283,9 @@ class Operation extends ObservableValue {
285
283
  : `${this.hint()} is obsolete due to ${Dump.snapshot2(h, changeset, m)} since s${since}${isReactive ? ` and will run automatically (order ${this.options.order})` : ''}`);
286
284
  this.unsubscribeFromAllObservables();
287
285
  if (isReactive)
288
- reactive.push(this);
286
+ obsolete.push(this);
289
287
  else
290
- (_b = this.observers) === null || _b === void 0 ? void 0 : _b.forEach(s => s.markObsoleteDueTo(this, this.controller.memberName, this.changeset, this.controller.objectHandle, why, since, reactive));
288
+ (_b = this.observers) === null || _b === void 0 ? void 0 : _b.forEach(s => s.markObsoleteDueTo(this, this.reaction.memberName, this.changeset, this.reaction.objectHandle, why, since, obsolete));
291
289
  const tran = this.transaction;
292
290
  if (tran.changeset === changeset) {
293
291
  }
@@ -298,18 +296,18 @@ class Operation extends ObservableValue {
298
296
  Log.write(' ', 'x', `${this.hint()} is not obsolete due to its own change to ${Dump.snapshot2(h, changeset, m)}`);
299
297
  }
300
298
  }
301
- runIfNotUpToDate(now, nothrow) {
299
+ relaunchIfNotUpToDate(now, nothrow) {
302
300
  const t = this.options.throttling;
303
301
  const interval = Date.now() + this.started;
304
302
  const hold = t ? t - interval : 0;
305
303
  if (now || hold < 0) {
306
304
  if (this.isNotUpToDate()) {
307
305
  try {
308
- const op = this.controller.useOrRun(false, undefined);
309
- if (op.result instanceof Promise)
310
- op.result.catch(error => {
311
- if (op.options.kind === Kind.Reactive)
312
- misuse(`reactive function ${op.hint()} failed and will not run anymore: ${error}`, error);
306
+ const launch = this.reaction.reuseOrRelaunch(false, undefined);
307
+ if (launch.result instanceof Promise)
308
+ launch.result.catch(error => {
309
+ if (launch.options.kind === Kind.Reactive)
310
+ misuse(`reactive function ${launch.hint()} failed and will not run anymore: ${error}`, error);
313
311
  });
314
312
  }
315
313
  catch (e) {
@@ -322,7 +320,7 @@ class Operation extends ObservableValue {
322
320
  }
323
321
  else if (t < Number.MAX_SAFE_INTEGER) {
324
322
  if (hold > 0)
325
- setTimeout(() => this.runIfNotUpToDate(true, true), hold);
323
+ setTimeout(() => this.relaunchIfNotUpToDate(true, true), hold);
326
324
  else
327
325
  this.addToDeferredReactiveFunctions();
328
326
  }
@@ -366,20 +364,20 @@ class Operation extends ObservableValue {
366
364
  this.error = error;
367
365
  return this;
368
366
  }
369
- static run(op, proxy) {
370
- op.enter();
367
+ static proceed(launch, proxy) {
368
+ launch.enter();
371
369
  try {
372
- op.result = op.options.getter.call(proxy, ...op.args);
370
+ launch.result = launch.options.getter.call(proxy, ...launch.args);
373
371
  }
374
372
  finally {
375
- op.leaveOrAsync();
373
+ launch.leaveOrAsync();
376
374
  }
377
375
  }
378
376
  enter() {
379
377
  if (this.options.monitor)
380
378
  this.monitorEnter(this.options.monitor);
381
379
  if (Log.isOn && Log.opt.operation)
382
- Log.write('║', '‾\\', `${this.hint()} - enter`, undefined, ` [ ${Dump.obj(this.controller.objectHandle, this.controller.memberName)} ]`);
380
+ Log.write('║', '‾\\', `${this.hint()} - enter`, undefined, ` [ ${Dump.obj(this.reaction.objectHandle, this.reaction.memberName)} ]`);
383
381
  this.started = Date.now();
384
382
  }
385
383
  leaveOrAsync() {
@@ -422,7 +420,7 @@ class Operation extends ObservableValue {
422
420
  separation: 'isolated',
423
421
  logging: Log.isOn && Log.opt.monitor ? undefined : Log.global
424
422
  };
425
- OperationController.runWithin(undefined, Transaction.run, options, MonitorImpl.enter, mon, this.transaction);
423
+ ReactionImpl.proceedWithinGivenLaunch(undefined, Transaction.run, options, MonitorImpl.enter, mon, this.transaction);
426
424
  }
427
425
  monitorLeave(mon) {
428
426
  Transaction.outside(() => {
@@ -432,33 +430,33 @@ class Operation extends ObservableValue {
432
430
  separation: 'isolated',
433
431
  logging: Log.isOn && Log.opt.monitor ? undefined : Log.DefaultLevel
434
432
  };
435
- OperationController.runWithin(undefined, Transaction.run, options, MonitorImpl.leave, mon, this.transaction);
433
+ ReactionImpl.proceedWithinGivenLaunch(undefined, Transaction.run, options, MonitorImpl.leave, mon, this.transaction);
436
434
  };
437
435
  this.transaction.whenFinished().then(leave, leave);
438
436
  });
439
437
  }
440
438
  addToDeferredReactiveFunctions() {
441
- Operation.deferredReactiveFunctions.push(this);
442
- if (Operation.deferredReactiveFunctions.length === 1)
443
- setTimeout(Operation.processDeferredReactiveFunctions, 0);
439
+ Launch.deferredReactiveFunctions.push(this);
440
+ if (Launch.deferredReactiveFunctions.length === 1)
441
+ setTimeout(Launch.processDeferredReactiveFunctions, 0);
444
442
  }
445
443
  static processDeferredReactiveFunctions() {
446
- const deferred = Operation.deferredReactiveFunctions;
447
- Operation.deferredReactiveFunctions = [];
444
+ const deferred = Launch.deferredReactiveFunctions;
445
+ Launch.deferredReactiveFunctions = [];
448
446
  for (const x of deferred)
449
- x.runIfNotUpToDate(true, true);
447
+ x.relaunchIfNotUpToDate(true, true);
450
448
  }
451
449
  static markUsed(observable, os, m, h, kind, weak) {
452
450
  if (kind !== Kind.Transactional) {
453
- const op = Operation.current;
454
- if (op && op.options.kind !== Kind.Transactional &&
455
- op.transaction === Transaction.current && m !== Meta.Handle) {
451
+ const launch = Launch.current;
452
+ if (launch && launch.options.kind !== Kind.Transactional &&
453
+ launch.transaction === Transaction.current && m !== Meta.Handle) {
456
454
  const ctx = Changeset.current();
457
455
  if (ctx !== os.changeset)
458
456
  ctx.bumpBy(os.changeset.timestamp);
459
457
  const t = weak ? -1 : ctx.timestamp;
460
- if (!op.subscribeTo(observable, os, m, h, t))
461
- op.markObsoleteDueTo(observable, m, h.head.changeset, h, BOOT_CAUSE, ctx.timestamp, ctx.reactive);
458
+ if (!launch.subscribeTo(observable, os, m, h, t))
459
+ launch.markObsoleteDueTo(observable, m, h.head.changeset, h, BOOT_CAUSE, ctx.timestamp, ctx.obsolete);
462
460
  }
463
461
  }
464
462
  }
@@ -470,38 +468,38 @@ class Operation extends ObservableValue {
470
468
  static isConflicting(oldValue, newValue) {
471
469
  let result = oldValue !== newValue;
472
470
  if (result)
473
- result = oldValue instanceof Operation && oldValue.cause !== BOOT_CAUSE;
471
+ result = oldValue instanceof Launch && oldValue.cause !== BOOT_CAUSE;
474
472
  return result;
475
473
  }
476
474
  static propagateAllChangesThroughSubscriptions(changeset) {
477
475
  var _a;
478
476
  const since = changeset.timestamp;
479
- const reactive = changeset.reactive;
477
+ const obsolete = changeset.obsolete;
480
478
  changeset.items.forEach((os, h) => {
481
- Operation.propagateMemberChangeThroughSubscriptions(false, since, os, Meta.Revision, h, reactive);
479
+ Launch.propagateMemberChangeThroughSubscriptions(false, since, os, Meta.Revision, h, obsolete);
482
480
  if (!os.disposed)
483
- os.changes.forEach((o, m) => Operation.propagateMemberChangeThroughSubscriptions(false, since, os, m, h, reactive));
481
+ os.changes.forEach((o, m) => Launch.propagateMemberChangeThroughSubscriptions(false, since, os, m, h, obsolete));
484
482
  else
485
483
  for (const m in os.former.snapshot.data)
486
- Operation.propagateMemberChangeThroughSubscriptions(true, since, os, m, h, reactive);
484
+ Launch.propagateMemberChangeThroughSubscriptions(true, since, os, m, h, obsolete);
487
485
  });
488
- reactive.sort(compareReactiveFunctionsByOrder);
486
+ obsolete.sort(compareObserversByOrder);
489
487
  (_a = changeset.options.journal) === null || _a === void 0 ? void 0 : _a.edited(JournalImpl.buildPatch(changeset.hint, changeset.items));
490
488
  }
491
489
  static revokeAllSubscriptions(changeset) {
492
490
  changeset.items.forEach((os, h) => {
493
- Operation.propagateMemberChangeThroughSubscriptions(true, changeset.timestamp, os, Meta.Revision, h, undefined);
494
- os.changes.forEach((o, m) => Operation.propagateMemberChangeThroughSubscriptions(true, changeset.timestamp, os, m, h, undefined));
491
+ Launch.propagateMemberChangeThroughSubscriptions(true, changeset.timestamp, os, Meta.Revision, h, undefined);
492
+ os.changes.forEach((o, m) => Launch.propagateMemberChangeThroughSubscriptions(true, changeset.timestamp, os, m, h, undefined));
495
493
  });
496
494
  }
497
- static propagateMemberChangeThroughSubscriptions(unsubscribe, timestamp, os, m, h, reactive) {
495
+ static propagateMemberChangeThroughSubscriptions(unsubscribe, timestamp, os, m, h, obsolete) {
498
496
  var _a;
499
497
  const curr = os.data[m];
500
- if (reactive) {
498
+ if (obsolete !== undefined) {
501
499
  const former = os.former.snapshot.data[m];
502
- if (former !== undefined && former instanceof ObservableValue) {
500
+ if (former !== undefined && former instanceof MvccValue) {
503
501
  const why = `T${os.changeset.id}[${os.changeset.hint}]`;
504
- if (former instanceof Operation) {
502
+ if (former instanceof Launch) {
505
503
  if ((former.obsoleteSince === MAX_REVISION || former.obsoleteSince <= 0)) {
506
504
  former.obsoleteDueTo = why;
507
505
  former.obsoleteSince = timestamp;
@@ -515,10 +513,10 @@ class Operation extends ObservableValue {
515
513
  else
516
514
  former.successor = undefined;
517
515
  }
518
- (_a = former.observers) === null || _a === void 0 ? void 0 : _a.forEach(s => s.markObsoleteDueTo(former, m, os.changeset, h, why, timestamp, reactive));
516
+ (_a = former.observers) === null || _a === void 0 ? void 0 : _a.forEach(s => s.markObsoleteDueTo(former, m, os.changeset, h, why, timestamp, obsolete));
519
517
  }
520
518
  }
521
- if (curr instanceof Operation) {
519
+ if (curr instanceof Launch) {
522
520
  if (curr.changeset === os.changeset && curr.observables !== undefined) {
523
521
  if (Mvcc.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
524
522
  curr.observables.forEach((info, v) => {
@@ -530,26 +528,26 @@ class Operation extends ObservableValue {
530
528
  curr.unsubscribeFromAllObservables();
531
529
  }
532
530
  }
533
- else if (curr instanceof ObservableValue && curr.observers) {
531
+ else if (curr instanceof MvccValue && curr.observers) {
534
532
  }
535
533
  }
536
534
  static enqueueReactiveFunctionsToRun(reactive) {
537
- const queue = Operation.queuedReactiveFunctions;
535
+ const queue = Launch.queuedReactiveFunctions;
538
536
  const isReactiveLoopRequired = queue.length === 0;
539
537
  for (const r of reactive)
540
538
  queue.push(r);
541
539
  if (isReactiveLoopRequired)
542
- OperationController.runWithin(undefined, Operation.runQueuedReactiveLoop);
540
+ ReactionImpl.proceedWithinGivenLaunch(undefined, Launch.runQueuedReactiveFunctions);
543
541
  }
544
- static runQueuedReactiveLoop() {
545
- const queue = Operation.queuedReactiveFunctions;
542
+ static runQueuedReactiveFunctions() {
543
+ const queue = Launch.queuedReactiveFunctions;
546
544
  let i = 0;
547
545
  while (i < queue.length) {
548
546
  const reactive = queue[i];
549
- reactive.runIfNotUpToDate(false, true);
547
+ reactive.relaunchIfNotUpToDate(false, true);
550
548
  i++;
551
549
  }
552
- Operation.queuedReactiveFunctions = [];
550
+ Launch.queuedReactiveFunctions = [];
553
551
  }
554
552
  unsubscribeFromAllObservables() {
555
553
  var _a;
@@ -563,7 +561,7 @@ class Operation extends ObservableValue {
563
561
  }
564
562
  subscribeTo(observable, os, m, h, timestamp) {
565
563
  var _a, _b, _c;
566
- const ok = Operation.canSubscribeTo(observable, os, m, h, timestamp);
564
+ const ok = Launch.canSubscribeTo(observable, os, m, h, timestamp);
567
565
  if (ok) {
568
566
  let times = 0;
569
567
  if (Mvcc.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
@@ -592,71 +590,71 @@ class Operation extends ObservableValue {
592
590
  const observableHead = h.head.data[m];
593
591
  let result = observable === observableHead || (!os.changeset.sealed && os.former.snapshot.data[m] === observableHead);
594
592
  if (result && timestamp !== -1)
595
- result = !(observable instanceof Operation && timestamp >= observable.obsoleteSince);
593
+ result = !(observable instanceof Launch && timestamp >= observable.obsoleteSince);
596
594
  return result;
597
595
  }
598
596
  static createOperation(h, m, options) {
599
- const ctl = new OperationController(h, m);
597
+ const rx = new ReactionImpl(h, m);
600
598
  const operation = (...args) => {
601
- return ctl.useOrRun(false, args).result;
599
+ return rx.reuseOrRelaunch(false, args).result;
602
600
  };
603
- Meta.set(operation, Meta.Controller, ctl);
601
+ Meta.set(operation, Meta.Controller, rx);
604
602
  return operation;
605
603
  }
606
604
  static rememberOperationOptions(proto, m, getter, setter, enumerable, configurable, options, implicit) {
607
605
  const initial = Meta.acquire(proto, Meta.Initial);
608
- let op = initial[m];
609
- const ctl = op ? op.controller : new OperationController(EMPTY_HANDLE, m);
610
- const opts = op ? op.options : OptionsImpl.INITIAL;
611
- initial[m] = op = new Operation(ctl, EMPTY_SNAPSHOT.changeset, new OptionsImpl(getter, setter, opts, options, implicit));
612
- if (op.options.kind === Kind.Reactive && op.options.throttling < Number.MAX_SAFE_INTEGER) {
606
+ let launch = initial[m];
607
+ const rx = launch ? launch.reaction : new ReactionImpl(EMPTY_HANDLE, m);
608
+ const opts = launch ? launch.options : OptionsImpl.INITIAL;
609
+ initial[m] = launch = new Launch(rx, EMPTY_SNAPSHOT.changeset, new OptionsImpl(getter, setter, opts, options, implicit));
610
+ if (launch.options.kind === Kind.Reactive && launch.options.throttling < Number.MAX_SAFE_INTEGER) {
613
611
  const reactive = Meta.acquire(proto, Meta.Reactive);
614
- reactive[m] = op;
612
+ reactive[m] = launch;
615
613
  }
616
- else if (op.options.kind === Kind.Reactive && op.options.throttling >= Number.MAX_SAFE_INTEGER) {
614
+ else if (launch.options.kind === Kind.Reactive && launch.options.throttling >= Number.MAX_SAFE_INTEGER) {
617
615
  const reactive = Meta.getFrom(proto, Meta.Reactive);
618
616
  delete reactive[m];
619
617
  }
620
- return op.options;
618
+ return launch.options;
621
619
  }
622
620
  static init() {
623
621
  Object.freeze(BOOT_ARGS);
624
622
  Log.getMergedLoggingOptions = getMergedLoggingOptions;
625
623
  Dump.valueHint = valueHint;
626
- Changeset.markUsed = Operation.markUsed;
627
- Changeset.markEdited = Operation.markEdited;
628
- Changeset.isConflicting = Operation.isConflicting;
629
- Changeset.propagateAllChangesThroughSubscriptions = Operation.propagateAllChangesThroughSubscriptions;
630
- Changeset.revokeAllSubscriptions = Operation.revokeAllSubscriptions;
631
- Changeset.enqueueReactiveFunctionsToRun = Operation.enqueueReactiveFunctionsToRun;
632
- Mvcc.createOperation = Operation.createOperation;
633
- Mvcc.rememberOperationOptions = Operation.rememberOperationOptions;
624
+ Changeset.markUsed = Launch.markUsed;
625
+ Changeset.markEdited = Launch.markEdited;
626
+ Changeset.isConflicting = Launch.isConflicting;
627
+ Changeset.propagateAllChangesThroughSubscriptions = Launch.propagateAllChangesThroughSubscriptions;
628
+ Changeset.revokeAllSubscriptions = Launch.revokeAllSubscriptions;
629
+ Changeset.enqueueReactiveFunctionsToRun = Launch.enqueueReactiveFunctionsToRun;
630
+ Mvcc.createOperation = Launch.createOperation;
631
+ Mvcc.rememberOperationOptions = Launch.rememberOperationOptions;
634
632
  Promise.prototype.then = reactronicHookedThen;
635
633
  try {
636
634
  Object.defineProperty(globalThis, 'rWhy', {
637
- get: OperationController.why, configurable: false, enumerable: false,
635
+ get: ReactionImpl.why, configurable: false, enumerable: false,
638
636
  });
639
637
  Object.defineProperty(globalThis, 'rBriefWhy', {
640
- get: OperationController.briefWhy, configurable: false, enumerable: false,
638
+ get: ReactionImpl.briefWhy, configurable: false, enumerable: false,
641
639
  });
642
640
  }
643
641
  catch (e) {
644
642
  }
645
643
  try {
646
644
  Object.defineProperty(global, 'rWhy', {
647
- get: OperationController.why, configurable: false, enumerable: false,
645
+ get: ReactionImpl.why, configurable: false, enumerable: false,
648
646
  });
649
647
  Object.defineProperty(global, 'rBriefWhy', {
650
- get: OperationController.briefWhy, configurable: false, enumerable: false,
648
+ get: ReactionImpl.briefWhy, configurable: false, enumerable: false,
651
649
  });
652
650
  }
653
651
  catch (e) {
654
652
  }
655
653
  }
656
654
  }
657
- Operation.current = undefined;
658
- Operation.queuedReactiveFunctions = [];
659
- Operation.deferredReactiveFunctions = [];
655
+ Launch.current = undefined;
656
+ Launch.queuedReactiveFunctions = [];
657
+ Launch.deferredReactiveFunctions = [];
660
658
  function valueHint(value) {
661
659
  let result = '';
662
660
  if (Array.isArray(value))
@@ -665,8 +663,8 @@ function valueHint(value) {
665
663
  result = `Set(${value.size})`;
666
664
  else if (value instanceof Map)
667
665
  result = `Map(${value.size})`;
668
- else if (value instanceof Operation)
669
- result = `#${value.controller.objectHandle.id}t${value.changeset.id}s${value.changeset.timestamp}${value.originSnapshotId !== undefined && value.originSnapshotId !== 0 ? `t${value.originSnapshotId}` : ''}`;
666
+ else if (value instanceof Launch)
667
+ result = `#${value.reaction.objectHandle.id}t${value.changeset.id}s${value.changeset.timestamp}${value.originSnapshotId !== undefined && value.originSnapshotId !== 0 ? `t${value.originSnapshotId}` : ''}`;
670
668
  else if (value === Meta.Undefined)
671
669
  result = 'undefined';
672
670
  else if (typeof (value) === 'string')
@@ -681,8 +679,8 @@ function getMergedLoggingOptions(local) {
681
679
  const t = Transaction.current;
682
680
  let res = Log.merge(t.options.logging, t.id > 1 ? 31 + t.id % 6 : 37, t.id > 1 ? `T${t.id}` : `-${Changeset.idGen.toString().replace(/[0-9]/g, '-')}`, Log.global);
683
681
  res = Log.merge({ margin1: t.margin }, undefined, undefined, res);
684
- if (Operation.current)
685
- res = Log.merge({ margin2: Operation.current.margin }, undefined, undefined, res);
682
+ if (Launch.current)
683
+ res = Log.merge({ margin2: Launch.current.margin }, undefined, undefined, res);
686
684
  if (local)
687
685
  res = Log.merge(local, undefined, undefined, res);
688
686
  return res;
@@ -695,17 +693,17 @@ function reactronicHookedThen(resolve, reject) {
695
693
  resolve = resolveReturn;
696
694
  if (!reject)
697
695
  reject = rejectRethrow;
698
- const op = Operation.current;
699
- if (op) {
700
- resolve = op.wrap(resolve);
701
- reject = op.wrap(reject);
696
+ const launch = Launch.current;
697
+ if (launch) {
698
+ resolve = launch.wrap(resolve);
699
+ reject = launch.wrap(reject);
702
700
  }
703
701
  resolve = tran.wrap(resolve, false);
704
702
  reject = tran.wrap(reject, true);
705
703
  }
706
704
  return ORIGINAL_PROMISE_THEN.call(this, resolve, reject);
707
705
  }
708
- function compareReactiveFunctionsByOrder(a, b) {
706
+ function compareObserversByOrder(a, b) {
709
707
  return a.order - b.order;
710
708
  }
711
709
  export function resolveReturn(value) {
@@ -714,4 +712,4 @@ export function resolveReturn(value) {
714
712
  export function rejectRethrow(error) {
715
713
  throw error;
716
714
  }
717
- Operation.init();
715
+ Launch.init();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.23.106",
3
+ "version": "0.23.108",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
5
  "publisher": "Nezaboodka Software",
6
6
  "license": "Apache-2.0",
@@ -1,12 +0,0 @@
1
- import { MemberOptions } from './Options.js';
2
- export declare abstract class Controller<T> {
3
- abstract readonly options: MemberOptions;
4
- abstract readonly args: ReadonlyArray<any>;
5
- abstract readonly result: T;
6
- abstract readonly error: any;
7
- abstract readonly stamp: number;
8
- abstract readonly isUpToDate: boolean;
9
- abstract configure(options: Partial<MemberOptions>): MemberOptions;
10
- abstract markObsolete(): void;
11
- abstract pullLastResult(args?: any[]): T | undefined;
12
- }
@@ -1,2 +0,0 @@
1
- export class Controller {
2
- }