reactronic 0.22.310 → 0.22.313

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.
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,12 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Transaction = void 0;
13
- const Utils_1 = require("../util/Utils");
14
- const Dbg_1 = require("../util/Dbg");
15
- const Changeset_1 = require("./Changeset");
16
- class Transaction {
10
+ import { UNDEF, pause } from '../util/Utils';
11
+ import { Log, misuse, error, fatal } from '../util/Dbg';
12
+ import { Changeset, Dump } from './Changeset';
13
+ export class Transaction {
17
14
  static get current() { return TransactionImpl.current; }
18
15
  whenFinished() {
19
16
  return __awaiter(this, void 0, void 0, function* () { });
@@ -26,19 +23,18 @@ class Transaction {
26
23
  static requestNextFrame(sleepTime = 0) { return TransactionImpl.requestNextFrame(sleepTime); }
27
24
  static get isCanceled() { return TransactionImpl.current.isCanceled; }
28
25
  }
29
- exports.Transaction = Transaction;
30
26
  class TransactionImpl extends Transaction {
31
27
  constructor(options) {
32
28
  super();
33
29
  this.margin = TransactionImpl.curr !== undefined ? TransactionImpl.curr.margin + 1 : -1;
34
- this.changeset = new Changeset_1.Changeset(options);
30
+ this.changeset = new Changeset(options);
35
31
  this.pending = 0;
36
32
  this.sealed = false;
37
33
  this.canceled = undefined;
38
34
  this.after = undefined;
39
35
  this.promise = undefined;
40
- this.resolve = Utils_1.UNDEF;
41
- this.reject = Utils_1.UNDEF;
36
+ this.resolve = UNDEF;
37
+ this.reject = UNDEF;
42
38
  }
43
39
  static get current() { return TransactionImpl.curr; }
44
40
  get id() { return this.changeset.id; }
@@ -54,8 +50,8 @@ class TransactionImpl extends Transaction {
54
50
  const restore = TransactionImpl.inspection;
55
51
  try {
56
52
  TransactionImpl.inspection = true;
57
- if (Dbg_1.Log.isOn && Dbg_1.Log.opt.transaction)
58
- Dbg_1.Log.write(' ', ' ', `T${this.id}[${this.hint}] is being inspected by T${TransactionImpl.curr.id}[${TransactionImpl.curr.hint}]`);
53
+ if (Log.isOn && Log.opt.transaction)
54
+ Log.write(' ', ' ', `T${this.id}[${this.hint}] is being inspected by T${TransactionImpl.curr.id}[${TransactionImpl.curr.hint}]`);
59
55
  return this.runImpl(undefined, func, ...args);
60
56
  }
61
57
  finally {
@@ -64,9 +60,9 @@ class TransactionImpl extends Transaction {
64
60
  }
65
61
  apply() {
66
62
  if (this.pending > 0)
67
- throw (0, Dbg_1.misuse)('cannot apply transaction having active operations running');
63
+ throw misuse('cannot apply transaction having active operations running');
68
64
  if (this.canceled)
69
- throw (0, Dbg_1.misuse)(`cannot apply transaction that is already canceled: ${this.canceled}`);
65
+ throw misuse(`cannot apply transaction that is already canceled: ${this.canceled}`);
70
66
  this.seal();
71
67
  }
72
68
  seal() {
@@ -153,7 +149,7 @@ class TransactionImpl extends Transaction {
153
149
  return result;
154
150
  }
155
151
  static requestNextFrame(sleepTime = 0) {
156
- return (0, Utils_1.pause)(sleepTime);
152
+ return pause(sleepTime);
157
153
  }
158
154
  static acquire(options) {
159
155
  const curr = TransactionImpl.curr;
@@ -164,7 +160,7 @@ class TransactionImpl extends Transaction {
164
160
  }
165
161
  guard() {
166
162
  if (this.sealed && TransactionImpl.curr !== this)
167
- throw (0, Dbg_1.misuse)('cannot run transaction that is already sealed');
163
+ throw misuse('cannot run transaction that is already sealed');
168
164
  }
169
165
  wrapToRetry(p, func, ...args) {
170
166
  return __awaiter(this, void 0, void 0, function* () {
@@ -230,7 +226,7 @@ class TransactionImpl extends Transaction {
230
226
  if (this.sealed && this.pending === 0) {
231
227
  const reactions = this.applyOrDiscard();
232
228
  TransactionImpl.curr = outer;
233
- TransactionImpl.off(Changeset_1.Changeset.enqueueReactionsToRun, reactions);
229
+ TransactionImpl.off(Changeset.enqueueReactionsToRun, reactions);
234
230
  }
235
231
  else
236
232
  TransactionImpl.curr = outer;
@@ -241,12 +237,12 @@ class TransactionImpl extends Transaction {
241
237
  if (!t.canceled && error) {
242
238
  t.canceled = error;
243
239
  t.after = after;
244
- if (Dbg_1.Log.isOn && Dbg_1.Log.opt.transaction) {
245
- Dbg_1.Log.write('║', ' [!]', `${error.message}`, undefined, ' *** CANCEL ***');
240
+ if (Log.isOn && Log.opt.transaction) {
241
+ Log.write('║', ' [!]', `${error.message}`, undefined, ' *** CANCEL ***');
246
242
  if (after && after !== TransactionImpl.none)
247
- Dbg_1.Log.write('║', ' [!]', `T${t.id}[${t.hint}] will be restarted${t !== after ? ` after T${after.id}[${after.hint}]` : ''}`);
243
+ Log.write('║', ' [!]', `T${t.id}[${t.hint}] will be restarted${t !== after ? ` after T${after.id}[${after.hint}]` : ''}`);
248
244
  }
249
- Changeset_1.Changeset.revokeAllSubscriptions(t.changeset);
245
+ Changeset.revokeAllSubscriptions(t.changeset);
250
246
  }
251
247
  t.sealed = true;
252
248
  }
@@ -256,13 +252,13 @@ class TransactionImpl extends Transaction {
256
252
  this.tryResolveConflicts(conflicts);
257
253
  }
258
254
  tryResolveConflicts(conflicts) {
259
- throw (0, Dbg_1.error)(`T${this.id}[${this.hint}] conflicts with: ${Changeset_1.Dump.conflicts(conflicts)}`, undefined);
255
+ throw error(`T${this.id}[${this.hint}] conflicts with: ${Dump.conflicts(conflicts)}`, undefined);
260
256
  }
261
257
  applyOrDiscard() {
262
258
  let reactions;
263
259
  try {
264
- if (Dbg_1.Log.isOn && Dbg_1.Log.opt.change)
265
- Dbg_1.Log.write('╠═', '', '', undefined, 'changes');
260
+ if (Log.isOn && Log.opt.change)
261
+ Log.write('╠═', '', '', undefined, 'changes');
266
262
  reactions = this.changeset.applyOrDiscard(this.canceled);
267
263
  this.changeset.triggerGarbageCollection();
268
264
  if (this.promise) {
@@ -271,11 +267,11 @@ class TransactionImpl extends Transaction {
271
267
  else
272
268
  this.resolve();
273
269
  }
274
- if (Dbg_1.Log.isOn)
270
+ if (Log.isOn)
275
271
  Object.freeze(this);
276
272
  }
277
273
  catch (e) {
278
- (0, Dbg_1.fatal)(e);
274
+ fatal(e);
279
275
  throw e;
280
276
  }
281
277
  return reactions;
@@ -294,18 +290,18 @@ class TransactionImpl extends Transaction {
294
290
  }
295
291
  static getEditableChangeset() {
296
292
  if (TransactionImpl.inspection)
297
- throw (0, Dbg_1.misuse)('cannot make changes during transaction inspection');
293
+ throw misuse('cannot make changes during transaction inspection');
298
294
  return TransactionImpl.curr.changeset;
299
295
  }
300
296
  static _init() {
301
- Changeset_1.Changeset.current = TransactionImpl.getCurrentChangeset;
302
- Changeset_1.Changeset.edit = TransactionImpl.getEditableChangeset;
297
+ Changeset.current = TransactionImpl.getCurrentChangeset;
298
+ Changeset.edit = TransactionImpl.getEditableChangeset;
303
299
  TransactionImpl.none.sealed = true;
304
300
  TransactionImpl.none.changeset.applyOrDiscard();
305
- Changeset_1.Changeset._init();
301
+ Changeset._init();
306
302
  }
307
303
  }
308
- TransactionImpl.none = new TransactionImpl({ hint: 'Transaction.off' });
304
+ TransactionImpl.none = new TransactionImpl({ hint: '<none>' });
309
305
  TransactionImpl.curr = TransactionImpl.none;
310
306
  TransactionImpl.inspection = false;
311
307
  TransactionImpl.frameStartTime = 0;
@@ -1,24 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Log = exports.fatal = exports.misuse = exports.error = void 0;
4
- function error(message, dump) {
1
+ export function error(message, dump) {
5
2
  if (Log.isOn && Log.opt.error)
6
3
  Log.write('█', ' ███', message, undefined, ' *** ERROR ***', dump);
7
4
  return new Error(message);
8
5
  }
9
- exports.error = error;
10
- function misuse(message, dump) {
6
+ export function misuse(message, dump) {
11
7
  const error = new Error(message);
12
8
  Log.write(' ', ' ███', message, undefined, ' *** ERROR / MISUSE ***', dump !== null && dump !== void 0 ? dump : error);
13
9
  return error;
14
10
  }
15
- exports.misuse = misuse;
16
- function fatal(error) {
11
+ export function fatal(error) {
17
12
  Log.write(' ', ' ███', error.message, undefined, ' *** FATAL ***', error);
18
13
  return error;
19
14
  }
20
- exports.fatal = fatal;
21
- class Log {
15
+ export class Log {
22
16
  static get opt() { return this.getMergedLoggingOptions(undefined); }
23
17
  static setMode(isOn, options) {
24
18
  Log.global = options || Log.DefaultLevel;
@@ -72,7 +66,6 @@ class Log {
72
66
  return result;
73
67
  }
74
68
  }
75
- exports.Log = Log;
76
69
  Log.DefaultLevel = {
77
70
  enabled: true,
78
71
  error: false,
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Sealant = void 0;
4
- const Dbg_1 = require("./Dbg");
5
- class Sealant {
1
+ import { Log, misuse } from './Dbg';
2
+ export class Sealant {
6
3
  static seal(collection, sealedType, typeName, member) {
7
4
  let result = collection;
8
5
  const createCopy = result[Sealant.CreateCopy];
9
6
  if (createCopy)
10
7
  result = createCopy.call(result);
11
- if (Dbg_1.Log.isOn && Dbg_1.Log.opt.write)
12
- Dbg_1.Log.write('║', ' ', `${typeName}.${member.toString()} - collection is sealed`);
8
+ if (Log.isOn && Log.opt.write)
9
+ Log.write('║', ' ', `${typeName}.${member.toString()} - collection is sealed`);
13
10
  Object.setPrototypeOf(result, sealedType);
14
11
  Object.freeze(result);
15
12
  return result;
@@ -22,9 +19,8 @@ class Sealant {
22
19
  return collection;
23
20
  }
24
21
  static error(collection) {
25
- return (0, Dbg_1.misuse)('use toMutable to create mutable copy of sealed collection');
22
+ return misuse('use toMutable to create mutable copy of sealed collection');
26
23
  }
27
24
  }
28
- exports.Sealant = Sealant;
29
25
  Sealant.SealedType = Symbol('rxSealedType');
30
26
  Sealant.CreateCopy = Symbol('rxCreateCopy');
@@ -1,28 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SealedArray = void 0;
4
- const Sealant_1 = require("./Sealant");
5
- class SealedArray extends Array {
6
- pop() { throw Sealant_1.Sealant.error(this); }
7
- push(...items) { throw Sealant_1.Sealant.error(this); }
8
- sort(compareFn) { throw Sealant_1.Sealant.error(this); }
9
- splice(start, deleteCount, ...items) { throw Sealant_1.Sealant.error(this); }
10
- unshift(...items) { throw Sealant_1.Sealant.error(this); }
11
- [Sealant_1.Sealant.CreateCopy]() { return this.slice(); }
1
+ import { Sealant } from './Sealant';
2
+ export class SealedArray extends Array {
3
+ pop() { throw Sealant.error(this); }
4
+ push(...items) { throw Sealant.error(this); }
5
+ sort(compareFn) { throw Sealant.error(this); }
6
+ splice(start, deleteCount, ...items) { throw Sealant.error(this); }
7
+ unshift(...items) { throw Sealant.error(this); }
8
+ [Sealant.CreateCopy]() { return this.slice(); }
12
9
  slice(start, end) {
13
10
  const result = super.slice(start, end);
14
11
  Object.setPrototypeOf(result, Array.prototype);
15
12
  return result;
16
13
  }
17
14
  }
18
- exports.SealedArray = SealedArray;
19
15
  Object.defineProperty(Array.prototype, 'toMutable', {
20
16
  configurable: false, enumerable: false,
21
17
  value() {
22
- return Sealant_1.Sealant.toMutable(this);
18
+ return Sealant.toMutable(this);
23
19
  },
24
20
  });
25
- Object.defineProperty(Array.prototype, Sealant_1.Sealant.SealedType, {
21
+ Object.defineProperty(Array.prototype, Sealant.SealedType, {
26
22
  value: SealedArray.prototype,
27
23
  configurable: false, enumerable: false, writable: false,
28
24
  });
@@ -1,21 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SealedMap = void 0;
4
- const Sealant_1 = require("./Sealant");
5
- class SealedMap extends Map {
6
- clear() { throw Sealant_1.Sealant.error(this); }
7
- delete(key) { throw Sealant_1.Sealant.error(this); }
8
- set(key, value) { throw Sealant_1.Sealant.error(this); }
9
- [Sealant_1.Sealant.CreateCopy]() { return new Map(this.entries()); }
1
+ import { Sealant } from './Sealant';
2
+ export class SealedMap extends Map {
3
+ clear() { throw Sealant.error(this); }
4
+ delete(key) { throw Sealant.error(this); }
5
+ set(key, value) { throw Sealant.error(this); }
6
+ [Sealant.CreateCopy]() { return new Map(this.entries()); }
10
7
  }
11
- exports.SealedMap = SealedMap;
12
8
  Object.defineProperty(Map.prototype, 'toMutable', {
13
9
  configurable: false, enumerable: false,
14
10
  value() {
15
- return Sealant_1.Sealant.toMutable(this);
11
+ return Sealant.toMutable(this);
16
12
  },
17
13
  });
18
- Object.defineProperty(Map.prototype, Sealant_1.Sealant.SealedType, {
14
+ Object.defineProperty(Map.prototype, Sealant.SealedType, {
19
15
  value: SealedMap.prototype,
20
16
  configurable: false, enumerable: false, writable: false,
21
17
  });
@@ -1,21 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SealedSet = void 0;
4
- const Sealant_1 = require("./Sealant");
5
- class SealedSet extends Set {
6
- add(value) { throw Sealant_1.Sealant.error(this); }
7
- clear() { throw Sealant_1.Sealant.error(this); }
8
- delete(value) { throw Sealant_1.Sealant.error(this); }
9
- [Sealant_1.Sealant.CreateCopy]() { return new Set(this.values()); }
1
+ import { Sealant } from './Sealant';
2
+ export class SealedSet extends Set {
3
+ add(value) { throw Sealant.error(this); }
4
+ clear() { throw Sealant.error(this); }
5
+ delete(value) { throw Sealant.error(this); }
6
+ [Sealant.CreateCopy]() { return new Set(this.values()); }
10
7
  }
11
- exports.SealedSet = SealedSet;
12
8
  Object.defineProperty(Set.prototype, 'toMutable', {
13
9
  configurable: false, enumerable: false,
14
10
  value() {
15
- return Sealant_1.Sealant.toMutable(this);
11
+ return Sealant.toMutable(this);
16
12
  },
17
13
  });
18
- Object.defineProperty(Set.prototype, Sealant_1.Sealant.SealedType, {
14
+ Object.defineProperty(Set.prototype, Sealant.SealedType, {
19
15
  value: SealedSet.prototype,
20
16
  configurable: false, enumerable: false, writable: false,
21
17
  });
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,9 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.pause = exports.all = exports.UNDEF = exports.Utils = void 0;
13
- class Utils {
10
+ export class Utils {
14
11
  static freezeSet(obj) {
15
12
  if (obj instanceof Set) {
16
13
  const pd = { configurable: false, enumerable: false, get: UNDEF, set: UNDEF };
@@ -39,12 +36,10 @@ class Utils {
39
36
  return target;
40
37
  }
41
38
  }
42
- exports.Utils = Utils;
43
- function UNDEF(...args) {
39
+ export function UNDEF(...args) {
44
40
  throw new Error('this method should never be called');
45
41
  }
46
- exports.UNDEF = UNDEF;
47
- function all(promises) {
42
+ export function all(promises) {
48
43
  return __awaiter(this, void 0, void 0, function* () {
49
44
  let error;
50
45
  const result = yield Promise.all(promises.map(x => x.catch(e => { error = error || e; return e; })));
@@ -53,10 +48,8 @@ function all(promises) {
53
48
  return result;
54
49
  });
55
50
  }
56
- exports.all = all;
57
- function pause(timeout) {
51
+ export function pause(timeout) {
58
52
  return new Promise(function (resolve) {
59
53
  setTimeout(resolve.bind(null, () => resolve), timeout);
60
54
  });
61
55
  }
62
- exports.pause = pause;
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.22.310",
3
+ "version": "0.22.313",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
+ "type": "module",
5
6
  "main": "build/dist/source/api.js",
6
7
  "types": "build/dist/source/api.d.ts",
7
8
  "files": [
@@ -33,12 +34,11 @@
33
34
  "@types/react": "18.0.14",
34
35
  "@typescript-eslint/eslint-plugin": "5.29.0",
35
36
  "@typescript-eslint/parser": "5.29.0",
36
- "ava": "3.15.0",
37
+ "ava": "4.3.0",
38
+ "c8": "7.11.3",
37
39
  "eslint": "8.18.0",
38
- "nyc": "15.1.0",
39
40
  "react": "18.2.0",
40
41
  "ts-node": "10.8.1",
41
- "tsconfig-paths": "4.0.0",
42
42
  "typescript": "4.7.3"
43
43
  },
44
44
  "scripts": {
@@ -46,6 +46,6 @@
46
46
  "fix": "eslint --fix source/**/*.ts test/**/*.ts react/**/*.tsx",
47
47
  "pack": "eslint source/**/*.ts test/**/*.ts react/**/*.tsx && tsc --sourceMap false --removeComments true",
48
48
  "test": "ava",
49
- "cover": "nyc ava && open build/coverage/index.html"
49
+ "cover": "c8 ava && open build/coverage/index.html"
50
50
  }
51
51
  }