reactronic 0.22.200 → 0.22.201

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.
@@ -41,10 +41,10 @@ export declare class Hooks implements ProxyHandler<ObjectHolder> {
41
41
  static decorateOperation(implicit: boolean, decorator: Function, options: Partial<MemberOptions>, proto: any, member: MemberName, pd: PropertyDescriptor | undefined): any;
42
42
  static decorateOperationParametrized(decorator: Function, options: Partial<MemberOptions>): F<any>;
43
43
  static acquireObjectHolder(obj: any): ObjectHolder;
44
- static createObjectHolder(proto: any, unobservable: any, blank: any, hint: string): ObjectHolder;
44
+ static createObjectHolderForObservableObject(proto: any, unobservable: any, blank: any, hint: string): ObjectHolder;
45
45
  static setProfilingMode(isOn: boolean, options?: Partial<ProfilingOptions>): void;
46
46
  static sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
47
47
  static setHint<T>(obj: T, hint: string | undefined): T;
48
- static createControllerAndGetHook: (h: ObjectHolder, m: MemberName, options: OptionsImpl) => F<any>;
48
+ static createOperation: (h: ObjectHolder, m: MemberName, options: OptionsImpl) => F<any>;
49
49
  static rememberOperationOptions: (proto: any, m: MemberName, getter: Function | undefined, setter: Function | undefined, enumerable: boolean, configurable: boolean, options: Partial<MemberOptions>, implicit: boolean) => OptionsImpl;
50
50
  }
@@ -10,7 +10,7 @@ class ObservableObject {
10
10
  constructor() {
11
11
  const proto = new.target.prototype;
12
12
  const initial = Data_1.Meta.getFrom(proto, Data_1.Meta.Initial);
13
- const h = Hooks.createObjectHolder(proto, this, initial, new.target.name);
13
+ const h = Hooks.createObjectHolderForObservableObject(proto, this, initial, new.target.name);
14
14
  return h.proxy;
15
15
  }
16
16
  [Symbol.toStringTag]() {
@@ -144,18 +144,18 @@ class Hooks {
144
144
  if (opts.getter === opts.setter) {
145
145
  const bootstrap = function () {
146
146
  const h = Hooks.acquireObjectHolder(this);
147
- const hook = Hooks.createControllerAndGetHook(h, member, opts);
148
- Object.defineProperty(h.unobservable, member, { value: hook, enumerable, configurable });
149
- return hook;
147
+ const operation = Hooks.createOperation(h, member, opts);
148
+ Object.defineProperty(h.unobservable, member, { value: operation, enumerable, configurable });
149
+ return operation;
150
150
  };
151
151
  return Object.defineProperty(proto, member, { get: bootstrap, enumerable, configurable: true });
152
152
  }
153
153
  else if (opts.setter === Utils_1.UNDEF) {
154
154
  const bootstrap = function () {
155
155
  const h = Hooks.acquireObjectHolder(this);
156
- const hook = Hooks.createControllerAndGetHook(h, member, opts);
157
- Object.defineProperty(h.unobservable, member, { get: hook, enumerable, configurable });
158
- return hook.call(this);
156
+ const operation = Hooks.createOperation(h, member, opts);
157
+ Object.defineProperty(h.unobservable, member, { get: operation, enumerable, configurable });
158
+ return operation.call(this);
159
159
  };
160
160
  return Object.defineProperty(proto, member, { get: bootstrap, enumerable, configurable: true });
161
161
  }
@@ -175,14 +175,12 @@ class Hooks {
175
175
  const initial = Data_1.Meta.getFrom(Object.getPrototypeOf(obj), Data_1.Meta.Initial);
176
176
  const rev = new Data_1.ObjectRevision(Snapshot_1.ROOT_REV.snapshot, Snapshot_1.ROOT_REV, Object.assign({}, initial));
177
177
  Data_1.Meta.set(rev.data, Data_1.Meta.Holder, h);
178
- if (Dbg_1.Log.isOn)
179
- Snapshot_1.Snapshot.freezeObjectRevision(rev);
180
178
  h = new Data_1.ObjectHolder(obj, obj, Hooks.proxy, rev, obj.constructor.name);
181
179
  Data_1.Meta.set(obj, Data_1.Meta.Holder, h);
182
180
  }
183
181
  return h;
184
182
  }
185
- static createObjectHolder(proto, unobservable, blank, hint) {
183
+ static createObjectHolderForObservableObject(proto, unobservable, blank, hint) {
186
184
  const ctx = Snapshot_1.Snapshot.edit();
187
185
  const h = new Data_1.ObjectHolder(unobservable, undefined, Hooks.proxy, Snapshot_1.ROOT_REV, hint);
188
186
  ctx.getEditableRevision(h, Data_1.Meta.Holder, blank);
@@ -230,8 +228,8 @@ Hooks.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
230
228
  Hooks.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
231
229
  Hooks.sensitivity = false;
232
230
  Hooks.proxy = new Hooks();
233
- Hooks.createControllerAndGetHook = function (h, m, options) {
234
- throw (0, Dbg_1.misuse)('createControllerAndGetHook should never be called');
231
+ Hooks.createOperation = function (h, m, options) {
232
+ throw (0, Dbg_1.misuse)('createOperation should never be called');
235
233
  };
236
234
  Hooks.rememberOperationOptions = function (proto, m, getter, setter, enumerable, configurable, options, implicit) {
237
235
  throw (0, Dbg_1.misuse)('rememberOperationOptions should never be called');
@@ -28,7 +28,7 @@ export declare class OperationController extends Controller<any> {
28
28
  private peek;
29
29
  private use;
30
30
  private edit;
31
- private peekFromRevision;
31
+ private acquireFromRevision;
32
32
  private run;
33
33
  private static markObsolete;
34
34
  }
@@ -84,7 +84,7 @@ declare class Operation extends Observable implements Observer {
84
84
  private unsubscribeFromAllObservables;
85
85
  private subscribeTo;
86
86
  private static canSubscribe;
87
- private static createControllerAndGetHook;
87
+ private static createOperation;
88
88
  private static rememberOperationOptions;
89
89
  static init(): void;
90
90
  }
@@ -10,9 +10,9 @@ const Transaction_1 = require("./Transaction");
10
10
  const Monitor_1 = require("./Monitor");
11
11
  const Hooks_1 = require("./Hooks");
12
12
  const TransactionJournal_1 = require("./TransactionJournal");
13
- const ROOT_ARGS = [];
14
- const ROOT_HOLDER = new Data_1.ObjectHolder(undefined, undefined, Hooks_1.Hooks.proxy, Snapshot_1.ROOT_REV, 'root-holder');
15
- const INITIAL_CAUSE = 'initial';
13
+ const BOOT_ARGS = [];
14
+ const BOOT_CAUSE = '<boot>';
15
+ const ROOT_HOLDER = new Data_1.ObjectHolder(undefined, undefined, Hooks_1.Hooks.proxy, Snapshot_1.ROOT_REV, '<root>');
16
16
  class OperationController extends Controller_1.Controller {
17
17
  constructor(ownHolder, memberName) {
18
18
  super();
@@ -36,7 +36,7 @@ class OperationController extends Controller_1.Controller {
36
36
  const op = oc.operation;
37
37
  const opts = op.options;
38
38
  if (!oc.isUpToDate && oc.revision.data[Data_1.Meta.Disposed] === undefined
39
- && (!weak || op.cause === INITIAL_CAUSE || !op.successor ||
39
+ && (!weak || op.cause === BOOT_CAUSE || !op.successor ||
40
40
  op.successor.transaction.isFinished)) {
41
41
  const outerOpts = (_a = Operation.current) === null || _a === void 0 ? void 0 : _a.options;
42
42
  const standalone = weak || opts.standalone || opts.kind === Options_1.Kind.Reaction ||
@@ -68,8 +68,8 @@ class OperationController extends Controller_1.Controller {
68
68
  op = self.edit().operation;
69
69
  else
70
70
  op = Operation.current;
71
- if (!op || op.transaction.isFinished)
72
- throw (0, Dbg_1.misuse)('a method is expected with reactronic decorator');
71
+ if (!op)
72
+ throw (0, Dbg_1.misuse)('reactronic decorator is only applicable to methods');
73
73
  op.options = new Hooks_1.OptionsImpl(op.options.getter, op.options.setter, op.options, options, false);
74
74
  if (Dbg_1.Log.isOn && Dbg_1.Log.opt.write)
75
75
  Dbg_1.Log.write('║', ' ✎', `${op.hint()}.options are changed`);
@@ -93,12 +93,12 @@ class OperationController extends Controller_1.Controller {
93
93
  return result;
94
94
  }
95
95
  static why() {
96
- const op = Operation.current;
97
- return op ? op.why() : ROOT_HOLDER.hint;
96
+ var _a, _b;
97
+ return (_b = (_a = Operation.current) === null || _a === void 0 ? void 0 : _a.why()) !== null && _b !== void 0 ? _b : BOOT_CAUSE;
98
98
  }
99
99
  static briefWhy() {
100
- const op = Operation.current;
101
- return op ? op.briefWhy() : ROOT_HOLDER.hint;
100
+ var _a, _b;
101
+ return (_b = (_a = Operation.current) === null || _a === void 0 ? void 0 : _a.briefWhy()) !== null && _b !== void 0 ? _b : BOOT_CAUSE;
102
102
  }
103
103
  static dependencies() {
104
104
  const op = Operation.current;
@@ -107,8 +107,8 @@ class OperationController extends Controller_1.Controller {
107
107
  peek(args) {
108
108
  const ctx = Snapshot_1.Snapshot.current();
109
109
  const r = ctx.seekRevision(this.ownHolder, this.memberName);
110
- const op = this.peekFromRevision(r, args);
111
- const isValid = op.options.kind !== Options_1.Kind.Transaction && op.cause !== INITIAL_CAUSE &&
110
+ const op = this.acquireFromRevision(r, args);
111
+ const isValid = op.options.kind !== Options_1.Kind.Transaction && op.cause !== BOOT_CAUSE &&
112
112
  (ctx === op.snapshot || ctx.timestamp < op.obsoleteSince) &&
113
113
  (!op.options.sensitiveArgs || args === undefined ||
114
114
  op.args.length === args.length && op.args.every((t, i) => t === args[i])) ||
@@ -125,7 +125,7 @@ class OperationController extends Controller_1.Controller {
125
125
  const m = this.memberName;
126
126
  const ctx = Snapshot_1.Snapshot.edit();
127
127
  const r = ctx.getEditableRevision(h, m, Data_1.Meta.Holder, this);
128
- let op = this.peekFromRevision(r, undefined);
128
+ let op = this.acquireFromRevision(r, undefined);
129
129
  if (op.snapshot !== r.snapshot) {
130
130
  const op2 = new Operation(this, r.snapshot, op);
131
131
  r.data[m] = op2.reenterOver(op);
@@ -135,28 +135,40 @@ class OperationController extends Controller_1.Controller {
135
135
  }
136
136
  return { operation: op, isUpToDate: true, snapshot: ctx, revision: r };
137
137
  }
138
- peekFromRevision(r, args) {
138
+ acquireFromRevision(r, args) {
139
139
  const m = this.memberName;
140
140
  let op = r.data[m];
141
141
  if (op.controller !== this) {
142
- const hint = Dbg_1.Log.isOn ? `${Snapshot_1.Dump.obj(this.ownHolder, m)}/boot` : 'MethodController/init';
143
- const standalone = r.snapshot.sealed || r.prev.revision !== Snapshot_1.ROOT_REV;
144
- op = Transaction_1.Transaction.run({ hint, standalone, token: this }, () => {
145
- const h = this.ownHolder;
146
- let r2 = Snapshot_1.Snapshot.current().getCurrentRevision(h, m);
147
- let op2 = r2.data[m];
148
- if (op2.controller !== this) {
149
- r2 = Snapshot_1.Snapshot.edit().getEditableRevision(h, m, Data_1.Meta.Holder, this);
150
- const t = new Operation(this, r2.snapshot, op2);
151
- if (args)
152
- t.args = args;
153
- t.cause = INITIAL_CAUSE;
154
- r2.data[m] = t;
155
- Snapshot_1.Snapshot.markEdited(op2, t, true, r2, m, h);
156
- op2 = t;
157
- }
158
- return op2;
159
- });
142
+ if (r.snapshot !== Snapshot_1.ROOT_REV.snapshot) {
143
+ const hint = Dbg_1.Log.isOn ? `${Snapshot_1.Dump.obj(this.ownHolder, m)}/boot` : 'MethodController/init';
144
+ const standalone = r.snapshot.sealed || r.prev.revision !== Snapshot_1.ROOT_REV;
145
+ op = Transaction_1.Transaction.run({ hint, standalone, token: this }, () => {
146
+ const h = this.ownHolder;
147
+ let r2 = Snapshot_1.Snapshot.current().getCurrentRevision(h, m);
148
+ let op2 = r2.data[m];
149
+ if (op2.controller !== this) {
150
+ r2 = Snapshot_1.Snapshot.edit().getEditableRevision(h, m, Data_1.Meta.Holder, this);
151
+ const t = new Operation(this, r2.snapshot, op2);
152
+ if (args)
153
+ t.args = args;
154
+ t.cause = BOOT_CAUSE;
155
+ r2.data[m] = t;
156
+ Snapshot_1.Snapshot.markEdited(op2, t, true, r2, m, h);
157
+ op2 = t;
158
+ }
159
+ return op2;
160
+ });
161
+ }
162
+ else {
163
+ const t = new Operation(this, r.snapshot, op);
164
+ if (args)
165
+ t.args = args;
166
+ t.cause = BOOT_CAUSE;
167
+ r.data[m] = t;
168
+ op = t;
169
+ if (Dbg_1.Log.isOn && Dbg_1.Log.opt.write)
170
+ Dbg_1.Log.write('║', ' ⎘', `${Snapshot_1.Dump.obj(this.ownHolder, m)} is cloned outside of transaction`);
171
+ }
160
172
  }
161
173
  return op;
162
174
  }
@@ -188,7 +200,7 @@ class OperationController extends Controller_1.Controller {
188
200
  static markObsolete(self) {
189
201
  const oc = self.peek(undefined);
190
202
  const ctx = oc.snapshot;
191
- oc.operation.markObsoleteDueTo(oc.operation, self.memberName, Snapshot_1.ROOT_REV.snapshot, ROOT_HOLDER, INITIAL_CAUSE, ctx.timestamp, ctx.reactions);
203
+ oc.operation.markObsoleteDueTo(oc.operation, self.memberName, Snapshot_1.ROOT_REV.snapshot, ROOT_HOLDER, BOOT_CAUSE, ctx.timestamp, ctx.reactions);
192
204
  }
193
205
  }
194
206
  exports.OperationController = OperationController;
@@ -207,7 +219,7 @@ class Operation extends Data_1.Observable {
207
219
  }
208
220
  else {
209
221
  this.options = prev;
210
- this.args = ROOT_ARGS;
222
+ this.args = BOOT_ARGS;
211
223
  this.cause = undefined;
212
224
  }
213
225
  this.started = 0;
@@ -451,7 +463,7 @@ class Operation extends Data_1.Observable {
451
463
  ctx.bumpBy(r.snapshot.timestamp);
452
464
  const t = weak ? -1 : ctx.timestamp;
453
465
  if (!op.subscribeTo(observable, r, m, h, t))
454
- op.markObsoleteDueTo(observable, m, r.snapshot, h, INITIAL_CAUSE, ctx.timestamp, ctx.reactions);
466
+ op.markObsoleteDueTo(observable, m, r.snapshot, h, BOOT_CAUSE, ctx.timestamp, ctx.reactions);
455
467
  }
456
468
  }
457
469
  }
@@ -463,7 +475,7 @@ class Operation extends Data_1.Observable {
463
475
  static isConflicting(oldValue, newValue) {
464
476
  let result = oldValue !== newValue;
465
477
  if (result)
466
- result = oldValue instanceof Operation && oldValue.cause !== INITIAL_CAUSE;
478
+ result = oldValue instanceof Operation && oldValue.cause !== BOOT_CAUSE;
467
479
  return result;
468
480
  }
469
481
  static propagateAllChangesThroughSubscriptions(snapshot) {
@@ -589,13 +601,13 @@ class Operation extends Data_1.Observable {
589
601
  result = !(observable instanceof Operation && timestamp >= observable.obsoleteSince);
590
602
  return result;
591
603
  }
592
- static createControllerAndGetHook(h, m, options) {
604
+ static createOperation(h, m, options) {
593
605
  const ctl = new OperationController(h, m);
594
- const hook = (...args) => {
606
+ const operation = (...args) => {
595
607
  return ctl.useOrRun(false, args).result;
596
608
  };
597
- Data_1.Meta.set(hook, Data_1.Meta.Controller, ctl);
598
- return hook;
609
+ Data_1.Meta.set(operation, Data_1.Meta.Controller, ctl);
610
+ return operation;
599
611
  }
600
612
  static rememberOperationOptions(proto, m, getter, setter, enumerable, configurable, options, implicit) {
601
613
  const initial = Data_1.Meta.acquire(proto, Data_1.Meta.Initial);
@@ -614,7 +626,7 @@ class Operation extends Data_1.Observable {
614
626
  return op.options;
615
627
  }
616
628
  static init() {
617
- Object.freeze(ROOT_ARGS);
629
+ Object.freeze(BOOT_ARGS);
618
630
  Dbg_1.Log.getMergedLoggingOptions = getMergedLoggingOptions;
619
631
  Snapshot_1.Snapshot.markUsed = Operation.markUsed;
620
632
  Snapshot_1.Snapshot.markEdited = Operation.markEdited;
@@ -622,7 +634,7 @@ class Operation extends Data_1.Observable {
622
634
  Snapshot_1.Snapshot.propagateAllChangesThroughSubscriptions = Operation.propagateAllChangesThroughSubscriptions;
623
635
  Snapshot_1.Snapshot.revokeAllSubscriptions = Operation.revokeAllSubscriptions;
624
636
  Snapshot_1.Snapshot.enqueueReactionsToRun = Operation.enqueueReactionsToRun;
625
- Hooks_1.Hooks.createControllerAndGetHook = Operation.createControllerAndGetHook;
637
+ Hooks_1.Hooks.createOperation = Operation.createOperation;
626
638
  Hooks_1.Hooks.rememberOperationOptions = Operation.rememberOperationOptions;
627
639
  Promise.prototype.then = reactronicHookedThen;
628
640
  try {
@@ -35,7 +35,7 @@ export declare class Snapshot implements AbstractSnapshot {
35
35
  static takeSnapshot<T>(obj: T): T;
36
36
  static dispose(obj: any): void;
37
37
  static doDispose(ctx: Snapshot, h: ObjectHolder): ObjectRevision;
38
- private checkIfEditable;
38
+ private isNewRevisionRequired;
39
39
  acquire(outer: Snapshot): void;
40
40
  bumpBy(timestamp: number): void;
41
41
  rebase(): ObjectRevision[] | undefined;
@@ -65,8 +65,7 @@ class Snapshot {
65
65
  let r = this.seekRevision(h, m);
66
66
  const existing = r.data[m];
67
67
  if (existing !== Data_1.Meta.Unobservable) {
68
- this.checkIfEditable(h, r, m, existing, value, token);
69
- if (r.snapshot !== this) {
68
+ if (this.isNewRevisionRequired(h, r, m, existing, value, token)) {
70
69
  const data = Object.assign({}, m === Data_1.Meta.Holder ? value : r.data);
71
70
  Reflect.set(data, Data_1.Meta.Holder, h);
72
71
  r = new Data_1.ObjectRevision(this, r, data);
@@ -98,8 +97,8 @@ class Snapshot {
98
97
  }
99
98
  return r;
100
99
  }
101
- checkIfEditable(h, r, m, existing, value, token) {
102
- if (this.sealed)
100
+ isNewRevisionRequired(h, r, m, existing, value, token) {
101
+ if (this.sealed && r.snapshot !== exports.ROOT_REV.snapshot)
103
102
  throw (0, Dbg_1.misuse)(`observable property ${Dump.obj(h, m)} can only be modified inside transaction`);
104
103
  if (m !== Data_1.Meta.Holder && value !== Data_1.Meta.Holder) {
105
104
  if (r.snapshot !== this || r.prev.revision !== exports.ROOT_REV) {
@@ -109,6 +108,7 @@ class Snapshot {
109
108
  if (r === exports.ROOT_REV)
110
109
  throw (0, Dbg_1.misuse)(`member ${Dump.rev(r, m)} doesn't exist in snapshot v${this.stamp} (${this.hint})`);
111
110
  }
111
+ return r.snapshot !== this && !this.sealed;
112
112
  }
113
113
  acquire(outer) {
114
114
  if (!this.sealed && this.stamp === exports.UNDEFINED_TIMESTAMP) {
@@ -280,10 +280,10 @@ class Snapshot {
280
280
  Object.freeze(this);
281
281
  }
282
282
  static _init() {
283
- const root = exports.ROOT_REV.snapshot;
284
- root.acquire(root);
285
- root.applyOrDiscard();
286
- root.triggerGarbageCollection();
283
+ const boot = exports.ROOT_REV.snapshot;
284
+ boot.acquire(boot);
285
+ boot.applyOrDiscard();
286
+ boot.triggerGarbageCollection();
287
287
  Snapshot.freezeObjectRevision(exports.ROOT_REV);
288
288
  Snapshot.idGen = 100;
289
289
  Snapshot.stampGen = 101;
@@ -314,7 +314,7 @@ class Dump {
314
314
  static obj(h, m, stamp, snapshotId, originSnapshotId, typeless) {
315
315
  const member = m !== undefined ? `.${m.toString()}` : '';
316
316
  return h === undefined
317
- ? `root${member}`
317
+ ? `boot${member}`
318
318
  : stamp === undefined ? `${h.hint}${member} #${h.id}` : `${h.hint}${member} #${h.id}t${snapshotId}v${stamp}${originSnapshotId !== undefined && originSnapshotId !== 0 ? `t${originSnapshotId}` : ''}`;
319
319
  }
320
320
  static rev2(h, s, m, value) {
@@ -339,7 +339,7 @@ class Dump {
339
339
  }
340
340
  }
341
341
  exports.Dump = Dump;
342
- exports.ROOT_REV = new Data_1.ObjectRevision(new Snapshot({ hint: 'root-rev' }), undefined, {});
342
+ exports.ROOT_REV = new Data_1.ObjectRevision(new Snapshot({ hint: '<root>' }), undefined, {});
343
343
  exports.DefaultSnapshotOptions = Object.freeze({
344
344
  hint: 'noname',
345
345
  standalone: false,
@@ -305,7 +305,7 @@ class TransactionImpl extends Transaction {
305
305
  Snapshot_1.Snapshot._init();
306
306
  }
307
307
  }
308
- TransactionImpl.none = new TransactionImpl({ hint: '<none>' });
308
+ TransactionImpl.none = new TransactionImpl({ hint: 'Transaction.off' });
309
309
  TransactionImpl.curr = TransactionImpl.none;
310
310
  TransactionImpl.inspection = false;
311
311
  TransactionImpl.frameStartTime = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.22.200",
3
+ "version": "0.22.201",
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",