reactronic 0.21.517 → 0.21.521

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
@@ -6,7 +6,7 @@
6
6
  [![CircleCI Status](https://circleci.com/gh/nezaboodka/reactronic.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/nezaboodka/reactronic)
7
7
  ![Coverage](https://img.shields.io/badge/coverage-97%25-success.svg)
8
8
  ![Lines](https://img.shields.io/badge/lines-1715-success.svg)
9
- [![Demo](https://img.shields.io/badge/demo-live-success.svg)](https://gitlab.com/nezaboodka/nevod.web.public/-/blob/master/README.md)
9
+ [![Demo](https://img.shields.io/badge/demo-live-success.svg)](https://gitlab.com/nezaboodka/nevod.website/-/blob/master/README.md)
10
10
 
11
11
  # **Reactronic** - Transactional Reactive State Management
12
12
 
@@ -27,8 +27,8 @@ export declare class Ref<T = any> {
27
27
  static similarRefs(v1: Ref, v2: Ref): boolean;
28
28
  }
29
29
  export declare class ToggleRef<T = boolean> extends Ref<T> {
30
- readonly value1: T;
31
- readonly value2: T;
32
- constructor(owner: any, name: string, value1: T, value2: T);
30
+ readonly valueOn: T;
31
+ readonly valueOff: T;
32
+ constructor(owner: any, name: string, valueOn: T, valueOff: T);
33
33
  toggle(): void;
34
34
  }
@@ -49,22 +49,22 @@ class Ref {
49
49
  }
50
50
  exports.Ref = Ref;
51
51
  class ToggleRef extends Ref {
52
- constructor(owner, name, value1, value2) {
52
+ constructor(owner, name, valueOn, valueOff) {
53
53
  super(owner, name);
54
- this.value1 = value1;
55
- this.value2 = value2;
54
+ this.valueOn = valueOn;
55
+ this.valueOff = valueOff;
56
56
  }
57
57
  toggle() {
58
58
  const o = this.owner;
59
59
  const p = this.name;
60
60
  Transaction_1.Transaction.runAs({ hint: `toggle ${o.constructor.name}.${p}` }, () => {
61
61
  const v = o[p];
62
- const isValue1 = v === this.value1 || (v instanceof Ref && this.value1 instanceof Ref &&
63
- Ref.sameRefs(v, this.value1));
64
- if (!isValue1)
65
- o[p] = this.value1;
62
+ const isOn = v === this.valueOn || (v instanceof Ref && this.valueOn instanceof Ref &&
63
+ Ref.sameRefs(v, this.valueOn));
64
+ if (!isOn)
65
+ o[p] = this.valueOn;
66
66
  else
67
- o[p] = this.value2;
67
+ o[p] = this.valueOff;
68
68
  });
69
69
  }
70
70
  }
@@ -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,
@@ -1,4 +1,4 @@
1
- export { all, sleep } from './util/Utils';
1
+ export { all, pause } from './util/Utils';
2
2
  export { SealedArray } from './util/SealedArray';
3
3
  export { SealedMap } from './util/SealedMap';
4
4
  export { SealedSet } from './util/SealedSet';
@@ -1,9 +1,9 @@
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.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.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
- Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return Utils_1.sleep; } });
6
+ Object.defineProperty(exports, "pause", { enumerable: true, get: function () { return Utils_1.pause; } });
7
7
  var SealedArray_1 = require("./util/SealedArray");
8
8
  Object.defineProperty(exports, "SealedArray", { enumerable: true, get: function () { return SealedArray_1.SealedArray; } });
9
9
  var SealedMap_1 = require("./util/SealedMap");
@@ -24,4 +24,7 @@ export declare abstract class Transaction implements Worker {
24
24
  static run<T>(func: F<T>, ...args: any[]): T;
25
25
  static runAs<T>(options: SnapshotOptions | null, func: F<T>, ...args: any[]): T;
26
26
  static standalone<T>(func: F<T>, ...args: any[]): T;
27
+ static isTimeOver(everyN?: number): boolean;
28
+ static requestMoreTime(): Promise<void>;
29
+ static get isCanceled(): boolean;
27
30
  }
@@ -22,6 +22,9 @@ class Transaction {
22
22
  static run(func, ...args) { return TransactionImpl.run(func, ...args); }
23
23
  static runAs(options, func, ...args) { return TransactionImpl.runAs(options, func, ...args); }
24
24
  static standalone(func, ...args) { return TransactionImpl.standalone(func, ...args); }
25
+ static isTimeOver(everyN = 1) { return TransactionImpl.isTimeOver(everyN); }
26
+ static requestMoreTime() { return TransactionImpl.requestMoreTime(); }
27
+ static get isCanceled() { return TransactionImpl.current.isCanceled; }
25
28
  }
26
29
  exports.Transaction = Transaction;
27
30
  class TransactionImpl extends Transaction {
@@ -139,6 +142,18 @@ class TransactionImpl extends Transaction {
139
142
  TransactionImpl.curr = outer;
140
143
  }
141
144
  }
145
+ static isTimeOver(everyN = 1) {
146
+ TransactionImpl.checkCount++;
147
+ let result = TransactionImpl.checkCount % everyN !== 0;
148
+ if (result) {
149
+ const ms = performance.now() - TransactionImpl.startTime;
150
+ result = ms > TransactionImpl.durationLimit;
151
+ }
152
+ return result;
153
+ }
154
+ static requestMoreTime(sleepTime = 0) {
155
+ return (0, Utils_1.pause)(sleepTime);
156
+ }
142
157
  static acquire(options) {
143
158
  return (options === null || options === void 0 ? void 0 : options.standalone) || TransactionImpl.curr.isFinished
144
159
  ? new TransactionImpl(options)
@@ -187,6 +202,10 @@ class TransactionImpl extends Transaction {
187
202
  let result;
188
203
  const outer = TransactionImpl.curr;
189
204
  try {
205
+ if (outer === TransactionImpl.none) {
206
+ TransactionImpl.startTime = performance.now();
207
+ TransactionImpl.checkCount = 0;
208
+ }
190
209
  TransactionImpl.curr = this;
191
210
  this.pending++;
192
211
  this.snapshot.acquire(outer.snapshot);
@@ -287,4 +306,7 @@ class TransactionImpl extends Transaction {
287
306
  TransactionImpl.none = new TransactionImpl({ hint: '<none>' });
288
307
  TransactionImpl.curr = TransactionImpl.none;
289
308
  TransactionImpl.inspection = false;
309
+ TransactionImpl.startTime = 0;
310
+ TransactionImpl.durationLimit = 14;
311
+ TransactionImpl.checkCount = 0;
290
312
  TransactionImpl._init();
@@ -6,4 +6,4 @@ export declare class Utils {
6
6
  }
7
7
  export declare function UNDEF(...args: any[]): never;
8
8
  export declare function all(promises: Array<Promise<any>>): Promise<any[]>;
9
- export declare function sleep<T>(timeout: number): Promise<T>;
9
+ export declare function pause<T>(timeout: number): Promise<T>;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.sleep = exports.all = exports.UNDEF = exports.Utils = void 0;
12
+ exports.pause = exports.all = exports.UNDEF = exports.Utils = void 0;
13
13
  class Utils {
14
14
  static freezeSet(obj) {
15
15
  if (obj instanceof Set) {
@@ -52,9 +52,9 @@ function all(promises) {
52
52
  });
53
53
  }
54
54
  exports.all = all;
55
- function sleep(timeout) {
55
+ function pause(timeout) {
56
56
  return new Promise(function (resolve) {
57
57
  setTimeout(resolve.bind(null, () => resolve), timeout);
58
58
  });
59
59
  }
60
- exports.sleep = sleep;
60
+ exports.pause = pause;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.21.517",
3
+ "version": "0.21.521",
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",
@@ -29,16 +29,16 @@
29
29
  },
30
30
  "homepage": "https://github.com/nezaboodka/reactronic/blob/master/README.md#readme",
31
31
  "devDependencies": {
32
- "@types/node": "16.10.1",
33
- "@types/react": "17.0.24",
34
- "@typescript-eslint/eslint-plugin": "4.31.2",
35
- "@typescript-eslint/parser": "4.31.2",
32
+ "@types/node": "16.11.11",
33
+ "@types/react": "17.0.37",
34
+ "@typescript-eslint/eslint-plugin": "5.5.0",
35
+ "@typescript-eslint/parser": "5.5.0",
36
36
  "ava": "3.15.0",
37
- "eslint": "7.32.0",
37
+ "eslint": "8.3.0",
38
38
  "nyc": "15.1.0",
39
39
  "react": "17.0.2",
40
- "ts-node": "10.2.1",
41
- "tsconfig-paths": "3.11.0",
40
+ "ts-node": "10.4.0",
41
+ "tsconfig-paths": "3.12.0",
42
42
  "typescript": "4.4.3"
43
43
  },
44
44
  "scripts": {