reactronic 0.21.604 → 0.22.104

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.
package/README.md CHANGED
@@ -196,7 +196,7 @@ class Component<P> extends React.Component<P> {
196
196
  @reaction // called immediately in response to changes
197
197
  ensureUpToDate(): void {
198
198
  if (this.shouldComponentUpdate())
199
- standalone(() => this.setState({})) // ask React to re-render
199
+ Transaction.off(() => this.setState({})) // ask React to re-render
200
200
  } // ensureUpToDate is subscribed to render
201
201
 
202
202
  shouldComponentUpdate(): boolean {
@@ -208,7 +208,7 @@ class Component<P> extends React.Component<P> {
208
208
  }
209
209
 
210
210
  componentWillUnmount(): void {
211
- standalone(Rx.dispose, this)
211
+ Transaction.run(null, Rx.dispose, this)
212
212
  }
213
213
  }
214
214
  ```
@@ -310,7 +310,6 @@ function monitor(value: Monitor | null)
310
310
  function trace(value: Partial<TraceOptions>)
311
311
 
312
312
  function nonreactive<T>(func: F<T>, ...args: any[]): T
313
- function standalone<T>(func: F<T>, ...args: any[]): T
314
313
  function sensitive<T>(sensitivity: Sensitivity, func: F<T>, ...args: any[]): T
315
314
 
316
315
  // Options, ObjectOptions, Kind, Reentrance, Monitor, TraceOptions, ProfilingOptions
@@ -417,11 +416,13 @@ class Transaction implements Worker {
417
416
  whenFinished(): Promise<void>
418
417
  join<T>(p: Promise<T>): Promise<T>
419
418
 
420
- static create(hint: string): Transaction
421
- static run<T>(hint: string, func: F<T>, ...args: any[]): T
422
- static runEx<T>(hint: string, standalone: boolean, sidebyside: boolean,
423
- trace: Partial<TraceOptions | undefined>, func: F<T>, ...args: any[]): T
424
- static standalone<T>(func: F<T>, ...args: any[]): T
419
+ static create(options: SnapshotOptions | null): Transaction
420
+ static run<T>(options: SnapshotOptions | null, func: F<T>, ...args: any[]): T
421
+ static off<T>(func: F<T>, ...args: any[]): T
422
+
423
+ static isFrameOver(everyN: number, timeLimit: number): boolean
424
+ static requestNextFrame(sleepTime: number): Promise<void>
425
+ static isCanceled: boolean
425
426
  }
426
427
 
427
428
  // Controller
@@ -57,7 +57,7 @@ class ToggleRef extends Ref {
57
57
  toggle() {
58
58
  const o = this.owner;
59
59
  const p = this.name;
60
- Transaction_1.Transaction.runAs({ hint: `toggle ${o.constructor.name}.${p}` }, () => {
60
+ Transaction_1.Transaction.run({ hint: `toggle ${o.constructor.name}.${p}` }, () => {
61
61
  const v = o[p];
62
62
  const isOn = v === this.valueOn || (v instanceof Ref && this.valueOn instanceof Ref &&
63
63
  Ref.sameRefs(v, this.valueOn));
@@ -18,7 +18,6 @@ export declare class Rx {
18
18
  static setProfilingMode(enabled: boolean, options?: Partial<ProfilingOptions>): void;
19
19
  }
20
20
  export declare function nonreactive<T>(func: F<T>, ...args: any[]): T;
21
- export declare function standalone<T>(func: F<T>, ...args: any[]): T;
22
21
  export declare function sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
23
22
  export declare function unobservable(proto: object, prop: PropertyKey): any;
24
23
  export declare function transaction(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
@@ -1,13 +1,12 @@
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.Rx = void 0;
3
+ exports.options = exports.cached = exports.reaction = exports.transaction = exports.unobservable = exports.sensitive = exports.nonreactive = exports.Rx = void 0;
4
4
  const Dbg_1 = require("./util/Dbg");
5
5
  const Options_1 = require("./Options");
6
6
  const Data_1 = require("./impl/Data");
7
7
  const Snapshot_1 = require("./impl/Snapshot");
8
8
  const Hooks_1 = require("./impl/Hooks");
9
9
  const Operation_1 = require("./impl/Operation");
10
- const Transaction_1 = require("./impl/Transaction");
11
10
  class Rx {
12
11
  static why(brief = false) { return brief ? Operation_1.OperationController.briefWhy() : Operation_1.OperationController.why(); }
13
12
  static getController(method) { return Operation_1.OperationController.of(method); }
@@ -29,10 +28,6 @@ function nonreactive(func, ...args) {
29
28
  return Operation_1.OperationController.runWithin(undefined, func, ...args);
30
29
  }
31
30
  exports.nonreactive = nonreactive;
32
- function standalone(func, ...args) {
33
- return Operation_1.OperationController.runWithin(undefined, Transaction_1.Transaction.standalone, func, ...args);
34
- }
35
- exports.standalone = standalone;
36
31
  function sensitive(sensitivity, func, ...args) {
37
32
  return Hooks_1.Hooks.sensitive(sensitivity, func, ...args);
38
33
  }
@@ -11,4 +11,4 @@ export { Snapshot } from './impl/Snapshot';
11
11
  export { Transaction } from './impl/Transaction';
12
12
  export { Monitor } from './impl/Monitor';
13
13
  export { TransactionJournal } from './impl/TransactionJournal';
14
- export { Rx, nonreactive, standalone, sensitive, unobservable, transaction, reaction, cached, options } from './Rx';
14
+ export { Rx, nonreactive, sensitive, unobservable, transaction, reaction, cached, options } from './Rx';
@@ -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.Rx = 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.pause = exports.all = void 0;
3
+ exports.options = exports.cached = exports.reaction = exports.transaction = exports.unobservable = exports.sensitive = exports.nonreactive = exports.Rx = 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.pause = 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, "pause", { enumerable: true, get: function () { return Utils_1.pause; } });
@@ -32,7 +32,6 @@ Object.defineProperty(exports, "TransactionJournal", { enumerable: true, get: fu
32
32
  var Rx_1 = require("./Rx");
33
33
  Object.defineProperty(exports, "Rx", { enumerable: true, get: function () { return Rx_1.Rx; } });
34
34
  Object.defineProperty(exports, "nonreactive", { enumerable: true, get: function () { return Rx_1.nonreactive; } });
35
- Object.defineProperty(exports, "standalone", { enumerable: true, get: function () { return Rx_1.standalone; } });
36
35
  Object.defineProperty(exports, "sensitive", { enumerable: true, get: function () { return Rx_1.sensitive; } });
37
36
  Object.defineProperty(exports, "unobservable", { enumerable: true, get: function () { return Rx_1.unobservable; } });
38
37
  Object.defineProperty(exports, "transaction", { enumerable: true, get: function () { return Rx_1.transaction; } });
@@ -35,7 +35,7 @@ class MonitorImpl extends Monitor {
35
35
  MonitorImpl.deactivate(this, this.internals.deactivationDelay);
36
36
  }
37
37
  static create(hint, activationDelay, deactivationDelay) {
38
- return Transaction_1.Transaction.runAs({ hint: 'Monitor.create' }, MonitorImpl.doCreate, hint, activationDelay, deactivationDelay);
38
+ return Transaction_1.Transaction.run({ hint: 'Monitor.create' }, MonitorImpl.doCreate, hint, activationDelay, deactivationDelay);
39
39
  }
40
40
  static enter(mon, worker) {
41
41
  mon.enter(worker);
@@ -53,7 +53,7 @@ class MonitorImpl extends Monitor {
53
53
  static activate(mon, delay) {
54
54
  if (delay >= 0) {
55
55
  if (mon.internals.activationTimeout === undefined)
56
- mon.internals.activationTimeout = setTimeout(() => Transaction_1.Transaction.runAs({ hint: 'Monitor.activate', standalone: 'isolated' }, MonitorImpl.activate, mon, -1), delay);
56
+ mon.internals.activationTimeout = setTimeout(() => Transaction_1.Transaction.run({ hint: 'Monitor.activate', standalone: 'isolated' }, MonitorImpl.activate, mon, -1), delay);
57
57
  }
58
58
  else if (mon.counter > 0)
59
59
  mon.isActive = true;
@@ -61,7 +61,7 @@ class MonitorImpl extends Monitor {
61
61
  static deactivate(mon, delay) {
62
62
  if (delay >= 0) {
63
63
  clearTimeout(mon.internals.deactivationTimeout);
64
- mon.internals.deactivationTimeout = setTimeout(() => Transaction_1.Transaction.runAs({ hint: 'Monitor.deactivate', standalone: 'isolated' }, MonitorImpl.deactivate, mon, -1), delay);
64
+ mon.internals.deactivationTimeout = setTimeout(() => Transaction_1.Transaction.run({ hint: 'Monitor.deactivate', standalone: 'isolated' }, MonitorImpl.deactivate, mon, -1), delay);
65
65
  }
66
66
  else if (mon.counter <= 0) {
67
67
  mon.isActive = false;
@@ -27,7 +27,7 @@ class OperationController extends Controller_1.Controller {
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
- markObsolete() { Transaction_1.Transaction.runAs({ hint: Dbg_1.Dbg.isOn ? `markObsolete(${Snapshot_1.Dump.obj(this.ownHolder, this.memberName)})` : 'markObsolete()' }, OperationController.markObsolete, this); }
30
+ markObsolete() { Transaction_1.Transaction.run({ hint: Dbg_1.Dbg.isOn ? `markObsolete(${Snapshot_1.Dump.obj(this.ownHolder, this.memberName)})` : 'markObsolete()' }, OperationController.markObsolete, this); }
31
31
  pullLastResult(args) { return this.useOrRun(true, args).value; }
32
32
  useOrRun(weak, args) {
33
33
  var _a;
@@ -141,7 +141,7 @@ class OperationController extends Controller_1.Controller {
141
141
  if (op.controller !== this) {
142
142
  const hint = Dbg_1.Dbg.isOn ? `${Snapshot_1.Dump.obj(this.ownHolder, m)}/boot` : 'MethodController/init';
143
143
  const standalone = r.snapshot.sealed || r.prev.revision !== Snapshot_1.ROOT_REV;
144
- op = Transaction_1.Transaction.runAs({ hint, standalone, token: this }, () => {
144
+ op = Transaction_1.Transaction.run({ hint, standalone, token: this }, () => {
145
145
  const h = this.ownHolder;
146
146
  let r2 = Snapshot_1.Snapshot.current().getCurrentRevision(h, m);
147
147
  let op2 = r2.data[m];
@@ -164,7 +164,7 @@ class OperationController extends Controller_1.Controller {
164
164
  const hint = Dbg_1.Dbg.isOn ? `${Snapshot_1.Dump.obj(this.ownHolder, this.memberName)}${args && args.length > 0 && (typeof args[0] === 'number' || typeof args[0] === 'string') ? ` - ${args[0]}` : ''}` : `${Snapshot_1.Dump.obj(this.ownHolder, this.memberName)}`;
165
165
  let oc = existing;
166
166
  const opts = { hint, standalone, journal: options.journal, trace: options.trace, token };
167
- const result = Transaction_1.Transaction.runAs(opts, (argsx) => {
167
+ const result = Transaction_1.Transaction.run(opts, (argsx) => {
168
168
  if (!oc.operation.transaction.isCanceled) {
169
169
  oc = this.edit();
170
170
  if (Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.operation)
@@ -415,17 +415,17 @@ class Operation extends Data_1.Observable {
415
415
  standalone: 'isolated',
416
416
  trace: Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.monitor ? undefined : Dbg_1.Dbg.global
417
417
  };
418
- OperationController.runWithin(undefined, Transaction_1.Transaction.runAs, options, Monitor_1.MonitorImpl.enter, mon, this.transaction);
418
+ OperationController.runWithin(undefined, Transaction_1.Transaction.run, options, Monitor_1.MonitorImpl.enter, mon, this.transaction);
419
419
  }
420
420
  monitorLeave(mon) {
421
- Transaction_1.Transaction.standalone(() => {
421
+ Transaction_1.Transaction.off(() => {
422
422
  const leave = () => {
423
423
  const options = {
424
424
  hint: 'Monitor.leave',
425
425
  standalone: 'isolated',
426
426
  trace: Dbg_1.Dbg.isOn && Dbg_1.Dbg.trace.monitor ? undefined : Dbg_1.Dbg.DefaultLevel
427
427
  };
428
- OperationController.runWithin(undefined, Transaction_1.Transaction.runAs, options, Monitor_1.MonitorImpl.leave, mon, this.transaction);
428
+ OperationController.runWithin(undefined, Transaction_1.Transaction.run, options, Monitor_1.MonitorImpl.leave, mon, this.transaction);
429
429
  };
430
430
  this.transaction.whenFinished().then(leave, leave);
431
431
  });
@@ -444,7 +444,8 @@ class Operation extends Data_1.Observable {
444
444
  static markUsed(observable, r, m, h, kind, weak) {
445
445
  if (kind !== Options_1.Kind.Transaction) {
446
446
  const op = Operation.current;
447
- if (op && op.options.kind !== Options_1.Kind.Transaction && m !== Data_1.Meta.Holder) {
447
+ if (op && op.options.kind !== Options_1.Kind.Transaction &&
448
+ op.transaction === Transaction_1.Transaction.current && m !== Data_1.Meta.Holder) {
448
449
  const ctx = Snapshot_1.Snapshot.current();
449
450
  if (ctx !== r.snapshot)
450
451
  ctx.bumpBy(r.snapshot.timestamp);
@@ -21,9 +21,9 @@ export declare abstract class Transaction implements Worker {
21
21
  abstract readonly isFinished: boolean;
22
22
  whenFinished(): Promise<void>;
23
23
  static create(options: SnapshotOptions | null): Transaction;
24
- static run<T>(func: F<T>, ...args: any[]): T;
25
- static runAs<T>(options: SnapshotOptions | null, func: F<T>, ...args: any[]): T;
24
+ static run<T>(options: SnapshotOptions | null, func: F<T>, ...args: any[]): T;
26
25
  static standalone<T>(func: F<T>, ...args: any[]): T;
26
+ static off<T>(func: F<T>, ...args: any[]): T;
27
27
  static isFrameOver(everyN?: number, timeLimit?: number): boolean;
28
28
  static requestNextFrame(sleepTime?: number): Promise<void>;
29
29
  static get isCanceled(): boolean;
@@ -19,9 +19,9 @@ class Transaction {
19
19
  return __awaiter(this, void 0, void 0, function* () { });
20
20
  }
21
21
  static create(options) { return new TransactionImpl(options); }
22
- static run(func, ...args) { return TransactionImpl.run(func, ...args); }
23
- static runAs(options, func, ...args) { return TransactionImpl.runAs(options, func, ...args); }
22
+ static run(options, func, ...args) { return TransactionImpl.run(options, func, ...args); }
24
23
  static standalone(func, ...args) { return TransactionImpl.standalone(func, ...args); }
24
+ static off(func, ...args) { return TransactionImpl.off(func, ...args); }
25
25
  static isFrameOver(everyN = 1, timeLimit = 14) { return TransactionImpl.isFrameOver(everyN, timeLimit); }
26
26
  static requestNextFrame(sleepTime = 0) { return TransactionImpl.requestNextFrame(sleepTime); }
27
27
  static get isCanceled() { return TransactionImpl.current.isCanceled; }
@@ -115,17 +115,14 @@ class TransactionImpl extends Transaction {
115
115
  yield this.acquirePromise();
116
116
  });
117
117
  }
118
- static run(func, ...args) {
119
- return TransactionImpl.runAs(null, func, ...args);
120
- }
121
- static runAs(options, func, ...args) {
118
+ static run(options, func, ...args) {
122
119
  const t = TransactionImpl.acquire(options);
123
120
  const root = t !== TransactionImpl.curr;
124
121
  t.guard();
125
122
  let result = t.runImpl(options === null || options === void 0 ? void 0 : options.trace, func, ...args);
126
123
  if (root) {
127
124
  if (result instanceof Promise) {
128
- result = TransactionImpl.standalone(() => {
125
+ result = TransactionImpl.off(() => {
129
126
  return t.wrapToRetry(t.wrapToWaitUntilFinish(result), func, ...args);
130
127
  });
131
128
  }
@@ -134,6 +131,9 @@ class TransactionImpl extends Transaction {
134
131
  return result;
135
132
  }
136
133
  static standalone(func, ...args) {
134
+ return TransactionImpl.run({ standalone: true }, func, ...args);
135
+ }
136
+ static off(func, ...args) {
137
137
  const outer = TransactionImpl.curr;
138
138
  try {
139
139
  TransactionImpl.curr = TransactionImpl.none;
@@ -184,7 +184,7 @@ class TransactionImpl extends Transaction {
184
184
  trace: this.snapshot.options.trace,
185
185
  token: this.snapshot.options.token,
186
186
  };
187
- return TransactionImpl.runAs(options, func, ...args);
187
+ return TransactionImpl.run(options, func, ...args);
188
188
  }
189
189
  else
190
190
  throw error;
@@ -230,7 +230,7 @@ class TransactionImpl extends Transaction {
230
230
  if (this.sealed && this.pending === 0) {
231
231
  const reactions = this.applyOrDiscard();
232
232
  TransactionImpl.curr = outer;
233
- TransactionImpl.standalone(Snapshot_1.Snapshot.enqueueReactionsToRun, reactions);
233
+ TransactionImpl.off(Snapshot_1.Snapshot.enqueueReactionsToRun, reactions);
234
234
  }
235
235
  else
236
236
  TransactionImpl.curr = outer;
@@ -24,7 +24,7 @@ class TransactionJournalImpl extends TransactionJournal {
24
24
  get canUndo() { return this._items.length > 0 && this._position > 0; }
25
25
  get canRedo() { return this._position < this._items.length; }
26
26
  remember(p) {
27
- Transaction_1.Transaction.runAs({ hint: 'TransactionJournal.remember', standalone: 'isolated' }, () => {
27
+ Transaction_1.Transaction.run({ hint: 'TransactionJournal.remember', standalone: 'isolated' }, () => {
28
28
  const items = this._items = this._items.toMutable();
29
29
  if (items.length >= this._capacity)
30
30
  items.shift();
@@ -35,7 +35,7 @@ class TransactionJournalImpl extends TransactionJournal {
35
35
  });
36
36
  }
37
37
  undo(count = 1) {
38
- Transaction_1.Transaction.runAs({ hint: 'TransactionJournal.undo', standalone: 'isolated' }, () => {
38
+ Transaction_1.Transaction.run({ hint: 'TransactionJournal.undo', standalone: 'isolated' }, () => {
39
39
  let i = this._position - 1;
40
40
  while (i >= 0 && count > 0) {
41
41
  const patch = this._items[i];
@@ -46,7 +46,7 @@ class TransactionJournalImpl extends TransactionJournal {
46
46
  });
47
47
  }
48
48
  redo(count = 1) {
49
- Transaction_1.Transaction.runAs({ hint: 'TransactionJournal.redo', standalone: 'isolated' }, () => {
49
+ Transaction_1.Transaction.run({ hint: 'TransactionJournal.redo', standalone: 'isolated' }, () => {
50
50
  let i = this._position;
51
51
  while (i < this._items.length && count > 0) {
52
52
  const patch = this._items[i];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.21.604",
3
+ "version": "0.22.104",
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",