reactronic 0.22.311 → 0.22.312

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
@@ -4,7 +4,7 @@
4
4
  [![NPM Version](https://img.shields.io/npm/v/reactronic.svg?style=flat&colorB=success)](https://www.npmjs.com/package/reactronic)
5
5
  [![Package Size](https://img.shields.io/bundlephobia/minzip/reactronic.svg?colorB=success)](https://bundlephobia.com/result?p=reactronic)
6
6
  ![Coverage](https://img.shields.io/badge/coverage-97%25-success.svg)
7
- ![Lines](https://img.shields.io/badge/lines-1811-success.svg)
7
+ ![Lines](https://img.shields.io/badge/lines-2722-success.svg)
8
8
  [![Demo](https://img.shields.io/badge/demo-live-success.svg)](https://gitlab.com/nezaboodka/nevod.website/-/blob/master/README.md)
9
9
 
10
10
  # **Reactronic** - Transactional Reactive State Management
@@ -29,9 +29,9 @@ export declare class Changeset implements AbstractChangeset {
29
29
  static propagateAllChangesThroughSubscriptions: (changeset: Changeset) => void;
30
30
  static revokeAllSubscriptions: (changeset: Changeset) => void;
31
31
  static enqueueReactionsToRun: (reactions: Array<Subscriber>) => void;
32
- seekSnapshot(h: ObjectHandle, m: MemberName): ObjectSnapshot;
33
- getRelevantSnapshot(h: ObjectHandle, m: MemberName): ObjectSnapshot;
34
- getEditableSnapshot(h: ObjectHandle, m: MemberName, value: any, token?: any): ObjectSnapshot;
32
+ lookupObjectSnapshot(h: ObjectHandle, m: MemberName): ObjectSnapshot;
33
+ getObjectSnapshot(h: ObjectHandle, m: MemberName): ObjectSnapshot;
34
+ getEditableObjectSnapshot(h: ObjectHandle, m: MemberName, value: any, token?: any): ObjectSnapshot;
35
35
  static takeSnapshot<T>(obj: T): T;
36
36
  static dispose(obj: any): void;
37
37
  static doDispose(ctx: Changeset, h: ObjectHandle): ObjectSnapshot;
@@ -11,7 +11,7 @@ Object.defineProperty(ObjectHandle.prototype, '#this', {
11
11
  configurable: false, enumerable: false,
12
12
  get() {
13
13
  const result = {};
14
- const data = Changeset.current().getRelevantSnapshot(this, '#this').data;
14
+ const data = Changeset.current().getObjectSnapshot(this, '#this').data;
15
15
  for (const m in data) {
16
16
  const v = data[m];
17
17
  if (v instanceof Subscription)
@@ -38,7 +38,7 @@ export class Changeset {
38
38
  }
39
39
  get hint() { var _a; return (_a = this.options.hint) !== null && _a !== void 0 ? _a : 'noname'; }
40
40
  get timestamp() { return this.revision; }
41
- seekSnapshot(h, m) {
41
+ lookupObjectSnapshot(h, m) {
42
42
  let os = h.editing;
43
43
  if (os && os.changeset !== this) {
44
44
  os = this.items.get(h);
@@ -52,14 +52,14 @@ export class Changeset {
52
52
  }
53
53
  return os;
54
54
  }
55
- getRelevantSnapshot(h, m) {
56
- const r = this.seekSnapshot(h, m);
55
+ getObjectSnapshot(h, m) {
56
+ const r = this.lookupObjectSnapshot(h, m);
57
57
  if (r === EMPTY_SNAPSHOT)
58
- throw misuse(`object ${Dump.obj(h)} doesn't exist in snapshot v${this.revision} (${this.hint})`);
58
+ throw misuse(`cannot use data from a transaction started after the current one T${this.id}[${this.hint}]: ${Dump.obj(h, m)} (head is T${h.head.changeset.id}[${h.head.changeset.hint}]${h.editing ? `, uncommitted T${h.editing.changeset.id}[${h.editing.changeset.hint}]` : ''})`);
59
59
  return r;
60
60
  }
61
- getEditableSnapshot(h, m, value, token) {
62
- let os = this.seekSnapshot(h, m);
61
+ getEditableObjectSnapshot(h, m, value, token) {
62
+ let os = this.lookupObjectSnapshot(h, m);
63
63
  const existing = os.data[m];
64
64
  if (existing !== Meta.Nonreactive) {
65
65
  if (this.isNewSnapshotRequired(h, os, m, existing, value, token)) {
@@ -90,7 +90,7 @@ export class Changeset {
90
90
  Changeset.doDispose(ctx, h);
91
91
  }
92
92
  static doDispose(ctx, h) {
93
- const os = ctx.getEditableSnapshot(h, Meta.Revision, Meta.Undefined);
93
+ const os = ctx.getEditableObjectSnapshot(h, Meta.Revision, Meta.Undefined);
94
94
  if (os !== EMPTY_SNAPSHOT)
95
95
  os.disposed = true;
96
96
  return os;
@@ -98,13 +98,15 @@ export class Changeset {
98
98
  isNewSnapshotRequired(h, os, m, existing, value, token) {
99
99
  if (this.sealed && os.changeset !== EMPTY_SNAPSHOT.changeset)
100
100
  throw misuse(`reactive property ${Dump.obj(h, m)} can only be modified inside transaction`);
101
- if (m !== Meta.Handle && value !== Meta.Handle) {
102
- if (os.changeset !== this || os.former.snapshot !== EMPTY_SNAPSHOT) {
103
- if (this.options.token !== undefined && token !== this.options.token)
104
- throw misuse(`${this.hint} should not have side effects (trying to change ${Dump.snapshot(os, m)})`);
101
+ if (m !== Meta.Handle) {
102
+ if (value !== Meta.Handle) {
103
+ if (os.changeset !== this || os.former.snapshot !== EMPTY_SNAPSHOT) {
104
+ if (this.options.token !== undefined && token !== this.options.token)
105
+ throw misuse(`${this.hint} should not have side effects (trying to change ${Dump.snapshot(os, m)})`);
106
+ }
105
107
  }
106
108
  if (os === EMPTY_SNAPSHOT)
107
- throw misuse(`member ${Dump.snapshot(os, m)} doesn't exist in snapshot v${this.revision} (${this.hint})`);
109
+ throw misuse(`cannot use data from a transaction started after the current one T${this.id}[${this.hint}]: ${Dump.snapshot(os, m)} (head is T${h.head.changeset.id}[${h.head.changeset.hint}]${h.editing ? `, uncommitted T${h.editing.changeset.id}[${h.editing.changeset.hint}]` : ''})`);
108
110
  }
109
111
  return os.changeset !== this && !this.sealed;
110
112
  }
@@ -120,7 +120,7 @@ export class Hooks {
120
120
  let result;
121
121
  if (m !== Meta.Handle) {
122
122
  const cs = Changeset.current();
123
- const os = cs.getRelevantSnapshot(h, m);
123
+ const os = cs.getObjectSnapshot(h, m);
124
124
  result = os.data[m];
125
125
  if (result instanceof Subscription && !result.isOperation) {
126
126
  Changeset.markUsed(result, os, m, h, Kind.Plain, false);
@@ -134,7 +134,7 @@ export class Hooks {
134
134
  return result;
135
135
  }
136
136
  set(h, m, value, receiver) {
137
- const os = Changeset.edit().getEditableSnapshot(h, m, value);
137
+ const os = Changeset.edit().getEditableObjectSnapshot(h, m, value);
138
138
  if (os !== EMPTY_SNAPSHOT) {
139
139
  let curr = os.data[m];
140
140
  if (curr !== undefined || (os.former.snapshot.changeset === EMPTY_SNAPSHOT.changeset && (m in h.data) === false)) {
@@ -158,18 +158,18 @@ export class Hooks {
158
158
  return true;
159
159
  }
160
160
  has(h, m) {
161
- const os = Changeset.current().getRelevantSnapshot(h, m);
161
+ const os = Changeset.current().getObjectSnapshot(h, m);
162
162
  return m in os.data || m in h.data;
163
163
  }
164
164
  getOwnPropertyDescriptor(h, m) {
165
- const os = Changeset.current().getRelevantSnapshot(h, m);
165
+ const os = Changeset.current().getObjectSnapshot(h, m);
166
166
  const pd = Reflect.getOwnPropertyDescriptor(os.data, m);
167
167
  if (pd)
168
168
  pd.configurable = pd.writable = true;
169
169
  return pd;
170
170
  }
171
171
  ownKeys(h) {
172
- const os = Changeset.current().getRelevantSnapshot(h, Meta.Handle);
172
+ const os = Changeset.current().getObjectSnapshot(h, Meta.Handle);
173
173
  const result = [];
174
174
  for (const m of Object.getOwnPropertyNames(os.data)) {
175
175
  const value = os.data[m];
@@ -245,7 +245,7 @@ export class Hooks {
245
245
  static createHandleForReactiveObject(proto, data, blank, hint) {
246
246
  const ctx = Changeset.edit();
247
247
  const h = new ObjectHandle(data, undefined, Hooks.handler, EMPTY_SNAPSHOT, hint);
248
- ctx.getEditableSnapshot(h, Meta.Handle, blank);
248
+ ctx.getEditableObjectSnapshot(h, Meta.Handle, blank);
249
249
  if (!Hooks.reactionsAutoStartDisabled)
250
250
  for (const m in Meta.getFrom(proto, Meta.Reactions))
251
251
  h.proxy[m][Meta.Controller].markObsolete();
@@ -97,7 +97,7 @@ export class JournalImpl extends Journal {
97
97
  if (!disposed) {
98
98
  op.forEach((vp, m) => {
99
99
  const value = undoing ? vp.formerValue : vp.freshValue;
100
- const os = ctx.getEditableSnapshot(h, m, value);
100
+ const os = ctx.getEditableObjectSnapshot(h, m, value);
101
101
  if (os.changeset === ctx) {
102
102
  os.data[m] = new Subscription(value);
103
103
  const existing = os.former.snapshot.data[m];
@@ -103,7 +103,7 @@ export class OperationController extends Controller {
103
103
  }
104
104
  peek(args) {
105
105
  const ctx = Changeset.current();
106
- const os = ctx.seekSnapshot(this.objectHandle, this.memberName);
106
+ const os = ctx.lookupObjectSnapshot(this.objectHandle, this.memberName);
107
107
  const op = this.acquireFromSnapshot(os, args);
108
108
  const isValid = op.options.kind !== Kind.Transaction && op.cause !== BOOT_CAUSE &&
109
109
  (ctx === op.changeset || ctx.timestamp < op.obsoleteSince) &&
@@ -120,7 +120,7 @@ export class OperationController extends Controller {
120
120
  const h = this.objectHandle;
121
121
  const m = this.memberName;
122
122
  const ctx = Changeset.edit();
123
- const os = ctx.getEditableSnapshot(h, m, Meta.Handle, this);
123
+ const os = ctx.getEditableObjectSnapshot(h, m, Meta.Handle, this);
124
124
  let op = this.acquireFromSnapshot(os, undefined);
125
125
  if (op.changeset !== os.changeset) {
126
126
  const op2 = new Operation(this, os.changeset, op);
@@ -140,10 +140,10 @@ export class OperationController extends Controller {
140
140
  const standalone = os.changeset.sealed || os.former.snapshot !== EMPTY_SNAPSHOT;
141
141
  op = Transaction.run({ hint, standalone, token: this }, () => {
142
142
  const h = this.objectHandle;
143
- let r2 = Changeset.current().getRelevantSnapshot(h, m);
143
+ let r2 = Changeset.current().getObjectSnapshot(h, m);
144
144
  let op2 = r2.data[m];
145
145
  if (op2.controller !== this) {
146
- r2 = Changeset.edit().getEditableSnapshot(h, m, Meta.Handle, this);
146
+ r2 = Changeset.edit().getEditableObjectSnapshot(h, m, Meta.Handle, this);
147
147
  const t = new Operation(this, r2.changeset, op2);
148
148
  if (args)
149
149
  t.args = args;
@@ -301,7 +301,7 @@ class TransactionImpl extends Transaction {
301
301
  Changeset._init();
302
302
  }
303
303
  }
304
- TransactionImpl.none = new TransactionImpl({ hint: 'Transaction.off' });
304
+ TransactionImpl.none = new TransactionImpl({ hint: '<none>' });
305
305
  TransactionImpl.curr = TransactionImpl.none;
306
306
  TransactionImpl.inspection = false;
307
307
  TransactionImpl.frameStartTime = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.22.311",
3
+ "version": "0.22.312",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
5
  "type": "module",
6
6
  "main": "build/dist/source/api.js",