reactronic 0.21.514 → 0.21.518

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,8 +34,3 @@ export declare enum Reentrance {
34
34
  OverwritePrevious = -3,
35
35
  RunSideBySide = -4
36
36
  }
37
- export declare enum Sensitivity {
38
- ReactOnFinalDifferenceOnly = 0,
39
- ReactOnFinalAndIntermediateDifference = 1,
40
- ReactEvenOnSameValueAssignment = 2
41
- }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Sensitivity = exports.Reentrance = exports.Kind = exports.TraceLevel = void 0;
3
+ exports.Reentrance = exports.Kind = exports.TraceLevel = void 0;
4
4
  var Trace_1 = require("./Trace");
5
5
  Object.defineProperty(exports, "TraceLevel", { enumerable: true, get: function () { return Trace_1.TraceLevel; } });
6
6
  var Kind;
@@ -19,9 +19,3 @@ var Reentrance;
19
19
  Reentrance[Reentrance["OverwritePrevious"] = -3] = "OverwritePrevious";
20
20
  Reentrance[Reentrance["RunSideBySide"] = -4] = "RunSideBySide";
21
21
  })(Reentrance = exports.Reentrance || (exports.Reentrance = {}));
22
- var Sensitivity;
23
- (function (Sensitivity) {
24
- Sensitivity[Sensitivity["ReactOnFinalDifferenceOnly"] = 0] = "ReactOnFinalDifferenceOnly";
25
- Sensitivity[Sensitivity["ReactOnFinalAndIntermediateDifference"] = 1] = "ReactOnFinalAndIntermediateDifference";
26
- Sensitivity[Sensitivity["ReactEvenOnSameValueAssignment"] = 2] = "ReactEvenOnSameValueAssignment";
27
- })(Sensitivity = exports.Sensitivity || (exports.Sensitivity = {}));
@@ -1,6 +1,6 @@
1
1
  import { F } from './util/Utils';
2
2
  import { Controller } from './Controller';
3
- import { MemberOptions, TraceOptions, ProfilingOptions, Sensitivity } from './Options';
3
+ import { MemberOptions, TraceOptions, ProfilingOptions } from './Options';
4
4
  export declare class Reactronic {
5
5
  static why(brief?: boolean): string;
6
6
  static getController<T>(method: F<T>): Controller<T>;
@@ -19,7 +19,7 @@ export declare class Reactronic {
19
19
  }
20
20
  export declare function nonreactive<T>(func: F<T>, ...args: any[]): T;
21
21
  export declare function standalone<T>(func: F<T>, ...args: any[]): T;
22
- export declare function sensitive<T>(sensitivity: Sensitivity, func: F<T>, ...args: any[]): T;
22
+ export declare function sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
23
23
  export declare function unobservable(proto: object, prop: PropertyKey): any;
24
24
  export declare function transaction(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
25
25
  export declare function reaction(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
@@ -24,10 +24,10 @@ export interface ProfilingOptions {
24
24
  }
25
25
  export declare const TraceLevel: {
26
26
  Error: TraceOptions;
27
- Minimal: TraceOptions;
28
- Info: TraceOptions;
27
+ Transactions: TraceOptions;
28
+ Operations: TraceOptions;
29
29
  Debug: TraceOptions;
30
- Suppress: TraceOptions;
30
+ Silent: TraceOptions;
31
31
  };
32
32
  declare global {
33
33
  interface Window {
@@ -20,7 +20,7 @@ exports.TraceLevel = {
20
20
  margin1: 0,
21
21
  margin2: 0,
22
22
  },
23
- Minimal: {
23
+ Transactions: {
24
24
  silent: false,
25
25
  transaction: true,
26
26
  operation: false,
@@ -38,7 +38,7 @@ exports.TraceLevel = {
38
38
  margin1: 0,
39
39
  margin2: 0,
40
40
  },
41
- Info: {
41
+ Operations: {
42
42
  silent: false,
43
43
  transaction: true,
44
44
  operation: true,
@@ -74,7 +74,7 @@ exports.TraceLevel = {
74
74
  margin1: 0,
75
75
  margin2: 0,
76
76
  },
77
- Suppress: {
77
+ Silent: {
78
78
  silent: true,
79
79
  transaction: false,
80
80
  operation: false,
@@ -2,7 +2,7 @@ export { all, sleep } from './util/Utils';
2
2
  export { SealedArray } from './util/SealedArray';
3
3
  export { SealedMap } from './util/SealedMap';
4
4
  export { SealedSet } from './util/SealedSet';
5
- export { MemberOptions, Kind, Reentrance, Sensitivity, TraceOptions, ProfilingOptions, TraceLevel } from './Options';
5
+ export { MemberOptions, Kind, Reentrance, TraceOptions, ProfilingOptions, TraceLevel } from './Options';
6
6
  export { Worker } from './Worker';
7
7
  export { Controller } from './Controller';
8
8
  export { Ref, ToggleRef, BoolOnly, GivenTypeOnly } from './Ref';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.options = exports.cached = exports.reaction = exports.transaction = exports.unobservable = exports.sensitive = exports.standalone = exports.nonreactive = exports.Reactronic = exports.TransactionJournal = exports.Monitor = exports.Transaction = exports.Snapshot = exports.ObservableObject = exports.ToggleRef = exports.Ref = exports.Controller = exports.TraceLevel = exports.Sensitivity = exports.Reentrance = exports.Kind = exports.SealedSet = exports.SealedMap = exports.SealedArray = exports.sleep = exports.all = void 0;
3
+ exports.options = exports.cached = exports.reaction = exports.transaction = exports.unobservable = exports.sensitive = exports.standalone = exports.nonreactive = exports.Reactronic = exports.TransactionJournal = exports.Monitor = exports.Transaction = exports.Snapshot = exports.ObservableObject = exports.ToggleRef = exports.Ref = exports.Controller = exports.TraceLevel = exports.Reentrance = exports.Kind = exports.SealedSet = exports.SealedMap = exports.SealedArray = exports.sleep = exports.all = void 0;
4
4
  var Utils_1 = require("./util/Utils");
5
5
  Object.defineProperty(exports, "all", { enumerable: true, get: function () { return Utils_1.all; } });
6
6
  Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return Utils_1.sleep; } });
@@ -13,7 +13,6 @@ Object.defineProperty(exports, "SealedSet", { enumerable: true, get: function ()
13
13
  var Options_1 = require("./Options");
14
14
  Object.defineProperty(exports, "Kind", { enumerable: true, get: function () { return Options_1.Kind; } });
15
15
  Object.defineProperty(exports, "Reentrance", { enumerable: true, get: function () { return Options_1.Reentrance; } });
16
- Object.defineProperty(exports, "Sensitivity", { enumerable: true, get: function () { return Options_1.Sensitivity; } });
17
16
  Object.defineProperty(exports, "TraceLevel", { enumerable: true, get: function () { return Options_1.TraceLevel; } });
18
17
  var Controller_1 = require("./Controller");
19
18
  Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return Controller_1.Controller; } });
@@ -1,5 +1,5 @@
1
1
  import { F } from '../util/Utils';
2
- import { MemberOptions, Kind, Reentrance, Sensitivity } from '../Options';
2
+ import { MemberOptions, Kind, Reentrance } from '../Options';
3
3
  import { TraceOptions, ProfilingOptions } from '../Trace';
4
4
  import { MemberName, ObjectHolder } from './Data';
5
5
  import { TransactionJournal } from './TransactionJournal';
@@ -28,7 +28,7 @@ export declare class Hooks implements ProxyHandler<ObjectHolder> {
28
28
  static repetitiveUsageWarningThreshold: number;
29
29
  static mainThreadBlockingWarningThreshold: number;
30
30
  static asyncActionDurationWarningThreshold: number;
31
- static sensitivity: Sensitivity;
31
+ static sensitivity: boolean;
32
32
  static readonly proxy: Hooks;
33
33
  getPrototypeOf(h: ObjectHolder): object | null;
34
34
  get(h: ObjectHolder, m: MemberName, receiver: any): any;
@@ -42,7 +42,7 @@ export declare class Hooks implements ProxyHandler<ObjectHolder> {
42
42
  static acquireObjectHolder(obj: any): ObjectHolder;
43
43
  static createObjectHolder(unobservable: any, blank: any, hint: string): ObjectHolder;
44
44
  static setProfilingMode(enabled: boolean, options?: Partial<ProfilingOptions>): void;
45
- static sensitive<T>(sensitivity: Sensitivity, func: F<T>, ...args: any[]): T;
45
+ static sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
46
46
  static setHint<T>(obj: T, hint: string | undefined): T;
47
47
  static createControllerAndGetHook: (h: ObjectHolder, m: MemberName, options: OptionsImpl) => F<any>;
48
48
  static rememberOperationOptions: (proto: any, m: MemberName, getter: Function | undefined, setter: Function | undefined, enumerable: boolean, configurable: boolean, options: Partial<MemberOptions>, implicit: boolean) => OptionsImpl;
@@ -78,24 +78,18 @@ class Hooks {
78
78
  set(h, m, value, receiver) {
79
79
  const r = Snapshot_1.Snapshot.edit().getEditableRevision(h, m, value);
80
80
  if (r !== Snapshot_1.ROOT_REV) {
81
- const curr = r.data[m];
82
- if (curr !== undefined || (r.prev.revision.snapshot === Snapshot_1.ROOT_REV.snapshot && m in h.unobservable === false)) {
83
- const prev = r.prev.revision.data[m];
84
- let edited = prev === undefined || prev.value !== value ||
85
- Hooks.sensitivity === Options_1.Sensitivity.ReactEvenOnSameValueAssignment;
86
- if (edited) {
87
- if (prev === curr)
88
- r.data[m] = new Data_1.Observable(value);
89
- else
81
+ let curr = r.data[m];
82
+ if (curr !== undefined || (r.prev.revision.snapshot === Snapshot_1.ROOT_REV.snapshot && (m in h.unobservable) === false)) {
83
+ if (curr === undefined || curr.value !== value || Hooks.sensitivity) {
84
+ if (r.prev.revision.data[m] === curr) {
85
+ curr = r.data[m] = new Data_1.Observable(value);
86
+ Snapshot_1.Snapshot.markEdited(value, true, r, m, h);
87
+ }
88
+ else {
90
89
  curr.value = value;
90
+ Snapshot_1.Snapshot.markEdited(value, true, r, m, h);
91
+ }
91
92
  }
92
- else if (prev !== curr) {
93
- if (Hooks.sensitivity === Options_1.Sensitivity.ReactOnFinalDifferenceOnly)
94
- r.data[m] = prev;
95
- else
96
- edited = true;
97
- }
98
- Snapshot_1.Snapshot.markEdited(value, edited, r, m, h);
99
93
  }
100
94
  else
101
95
  Reflect.set(h.unobservable, m, value, receiver);
@@ -233,7 +227,7 @@ Hooks.reactionsAutoStartDisabled = false;
233
227
  Hooks.repetitiveUsageWarningThreshold = Number.MAX_SAFE_INTEGER;
234
228
  Hooks.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
235
229
  Hooks.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
236
- Hooks.sensitivity = Options_1.Sensitivity.ReactOnFinalDifferenceOnly;
230
+ Hooks.sensitivity = false;
237
231
  Hooks.proxy = new Hooks();
238
232
  Hooks.createControllerAndGetHook = function (h, m, options) {
239
233
  throw (0, Dbg_1.misuse)('createControllerAndGetHook should never be called');
@@ -12,7 +12,7 @@ const Hooks_1 = require("./Hooks");
12
12
  const TransactionJournal_1 = require("./TransactionJournal");
13
13
  const ROOT_ARGS = [];
14
14
  const ROOT_HOLDER = new Data_1.ObjectHolder(undefined, undefined, Hooks_1.Hooks.proxy, Snapshot_1.ROOT_REV, 'root-holder');
15
- const ROOT_CAUSE = { revision: Snapshot_1.ROOT_REV, memberName: 'root-cause', usageCount: 0 };
15
+ const ROOT_TRIGGER = { revision: Snapshot_1.ROOT_REV, memberName: 'root-trigger', usageCount: 0 };
16
16
  class OperationController extends Controller_1.Controller {
17
17
  constructor(ownHolder, memberName) {
18
18
  super();
@@ -35,7 +35,7 @@ class OperationController extends Controller_1.Controller {
35
35
  const op = oc.operation;
36
36
  const opts = op.options;
37
37
  if (!oc.isUpToDate && oc.revision.data[Data_1.Meta.Disposed] === undefined
38
- && (!weak || op.cause === ROOT_CAUSE || !op.successor ||
38
+ && (!weak || op.cause === ROOT_TRIGGER || !op.successor ||
39
39
  op.successor.transaction.isFinished)) {
40
40
  const standalone = weak || opts.kind === Options_1.Kind.Reaction ||
41
41
  (opts.kind === Options_1.Kind.Cache && (oc.revision.snapshot.sealed ||
@@ -69,7 +69,7 @@ class OperationController extends Controller_1.Controller {
69
69
  throw (0, Dbg_1.misuse)('a method is expected with reactronic decorator');
70
70
  op.options = new Hooks_1.OptionsImpl(op.options.getter, op.options.setter, op.options, options, false);
71
71
  if (Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.write)
72
- Dbg_1.Dbg.log('║', ' ', `${op.hint()}.options = ...`);
72
+ Dbg_1.Dbg.log('║', ' ', `${op.hint()}.options = ...`);
73
73
  return op.options;
74
74
  }
75
75
  static runWithin(op, func, ...args) {
@@ -105,7 +105,7 @@ class OperationController extends Controller_1.Controller {
105
105
  const ctx = Snapshot_1.Snapshot.current();
106
106
  const r = ctx.seekRevision(this.ownHolder, this.memberName);
107
107
  const op = this.peekFromRevision(r);
108
- const isValid = op.options.kind !== Options_1.Kind.Transaction && op.cause !== ROOT_CAUSE &&
108
+ const isValid = op.options.kind !== Options_1.Kind.Transaction && op.cause !== ROOT_TRIGGER &&
109
109
  (ctx === op.revision.snapshot || ctx.timestamp < op.obsoleteSince) &&
110
110
  (!op.options.sensitiveArgs || args === undefined ||
111
111
  op.args.length === args.length && op.args.every((t, i) => t === args[i])) ||
@@ -144,7 +144,7 @@ class OperationController extends Controller_1.Controller {
144
144
  if (op2.controller !== this) {
145
145
  r2 = Snapshot_1.Snapshot.edit().getEditableRevision(h, m, Data_1.Meta.Holder, this);
146
146
  op2 = r2.data[m] = new Operation(this, r2, op2);
147
- op2.cause = ROOT_CAUSE;
147
+ op2.cause = ROOT_TRIGGER;
148
148
  Snapshot_1.Snapshot.markEdited(op2, true, r2, m, h);
149
149
  }
150
150
  return op2;
@@ -160,7 +160,7 @@ class OperationController extends Controller_1.Controller {
160
160
  if (!oc.operation.transaction.isCanceled) {
161
161
  oc = this.edit();
162
162
  if (Dbg_1.Dbg.isOn && (Dbg_1.Dbg.trace.transaction || Dbg_1.Dbg.trace.operation || Dbg_1.Dbg.trace.obsolete))
163
- Dbg_1.Dbg.log('║', ' (f)', `${oc.operation.why()}`);
163
+ Dbg_1.Dbg.log('║', ' 𝑓', `${oc.operation.why()}`);
164
164
  oc.operation.run(this.ownHolder.proxy, argsx);
165
165
  }
166
166
  else {
@@ -168,7 +168,7 @@ class OperationController extends Controller_1.Controller {
168
168
  if (oc.operation.options.kind === Options_1.Kind.Transaction || !oc.isUpToDate) {
169
169
  oc = this.edit();
170
170
  if (Dbg_1.Dbg.isOn && (Dbg_1.Dbg.trace.transaction || Dbg_1.Dbg.trace.operation || Dbg_1.Dbg.trace.obsolete))
171
- Dbg_1.Dbg.log('║', ' (f)', `${oc.operation.why()}`);
171
+ Dbg_1.Dbg.log('║', ' 𝑓', `${oc.operation.why()}`);
172
172
  oc.operation.run(this.ownHolder.proxy, argsx);
173
173
  }
174
174
  }
@@ -215,14 +215,14 @@ class Operation extends Data_1.Observable {
215
215
  const prev = this.revision.prev.revision.data[this.controller.memberName];
216
216
  if (prev instanceof Operation)
217
217
  ms = prev.started !== 0 ? Math.abs(this.started || ms) - Math.abs(prev.started) : Infinity;
218
- let cause;
218
+ let trigger;
219
219
  if (this.cause)
220
- cause = ` << ${propagationHint(this.cause, true).join(' << ')}`;
220
+ trigger = ` << ${propagationHint(this.cause, true).join(' << ')}`;
221
221
  else if (this.controller.options.kind === Options_1.Kind.Transaction)
222
- cause = ' << operation';
222
+ trigger = ' << operation';
223
223
  else
224
- cause = ` << called within ${this.revision.snapshot.hint}`;
225
- return `${this.hint()}${cause} (${ms !== Infinity ? `${ms}ms since previous run` : 'initial run'})`;
224
+ trigger = ` << called within ${this.revision.snapshot.hint}`;
225
+ return `${this.hint()}${trigger} (${ms !== Infinity ? `${ms}ms since previous run` : 'initial run'})`;
226
226
  }
227
227
  briefWhy() {
228
228
  return this.cause ? propagationHint(this.cause, false)[0] : ROOT_HOLDER.hint;
@@ -443,12 +443,12 @@ class Operation extends Data_1.Observable {
443
443
  static markEdited(value, edited, r, m, h) {
444
444
  edited ? r.changes.set(m, Operation.current) : r.changes.delete(m);
445
445
  if (Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.write)
446
- edited ? Dbg_1.Dbg.log('║', ' ', `${Snapshot_1.Dump.rev(r, m)} = ${valueHint(value)}`) : Dbg_1.Dbg.log('║', ' ', `${Snapshot_1.Dump.rev(r, m)} = ${valueHint(value)}`, undefined, ' (same as previous)');
446
+ edited ? Dbg_1.Dbg.log('║', ' ', `${Snapshot_1.Dump.rev(r, m)} = ${valueHint(value)}`) : Dbg_1.Dbg.log('║', ' ', `${Snapshot_1.Dump.rev(r, m)} = ${valueHint(value)}`, undefined, ' (same as previous)');
447
447
  }
448
448
  static isConflicting(oldValue, newValue) {
449
449
  let result = oldValue !== newValue;
450
450
  if (result)
451
- result = oldValue instanceof Operation && oldValue.cause !== ROOT_CAUSE;
451
+ result = oldValue instanceof Operation && oldValue.cause !== ROOT_TRIGGER;
452
452
  return result;
453
453
  }
454
454
  static propagateAllChangesThroughSubscriptions(snapshot) {
@@ -569,7 +569,7 @@ class Operation extends Data_1.Observable {
569
569
  }
570
570
  static init() {
571
571
  Object.freeze(ROOT_ARGS);
572
- Object.freeze(ROOT_CAUSE);
572
+ Object.freeze(ROOT_TRIGGER);
573
573
  Dbg_1.Dbg.getMergedTraceOptions = getMergedTraceOptions;
574
574
  Snapshot_1.Snapshot.markUsed = Operation.markUsed;
575
575
  Snapshot_1.Snapshot.markEdited = Operation.markEdited;
@@ -27,7 +27,7 @@ class Dbg {
27
27
  const t = Dbg.global;
28
28
  const o = Object.keys(Dbg.global).filter(x => t[x] === true).join(', ');
29
29
  Dbg.log('', '', `Reactronic trace is enabled: ${o}`);
30
- Dbg.log('', '', 'Method-level trace can be configured with @trace decorator');
30
+ Dbg.log('', '', 'Method-level trace can be configured with @options({ trace: ... }) decorator');
31
31
  }
32
32
  else
33
33
  Dbg.log('', '', 'Reactronic trace is disabled');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.21.514",
3
+ "version": "0.21.518",
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",