reactronic 0.24.309 → 0.24.400

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,12 +1,12 @@
1
1
  import { LoggingOptions } from "../Logging.js";
2
2
  import { MergeListReader, MergedItem } from "../util/MergeList.js";
3
3
  import { MemberOptions } from "../Options.js";
4
- export type Script<E> = (e: E, basis: () => void) => void;
5
- export type ScriptAsync<E> = (e: E, basis: () => Promise<void>) => Promise<void>;
6
- export type Handler<E = unknown, R = void> = (e: E) => R;
4
+ export type Script<E> = (el: E, basis: () => void) => void;
5
+ export type ScriptAsync<E> = (el: E, basis: () => Promise<void>) => Promise<void>;
6
+ export type Handler<E = unknown, R = void> = (el: E) => R;
7
7
  export declare enum Mode {
8
8
  default = 0,
9
- independentUpdate = 1,
9
+ autonomous = 1,
10
10
  manualMount = 2
11
11
  }
12
12
  export declare enum Priority {
@@ -36,9 +36,9 @@ export declare abstract class ReactiveNode<E = unknown> {
36
36
  static readonly longFrameDuration = 300;
37
37
  static currentUpdatePriority: Priority;
38
38
  static frameDuration: number;
39
- static declare<E = void>(driver: ReactiveNodeDriver<E>, script?: Script<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, creation?: Script<E>, creationAsync?: ScriptAsync<E>, destruction?: Script<E>, triggers?: unknown, basis?: ReactiveNodeDecl<E>): ReactiveNode<E>;
39
+ static declare<E = void>(driver: ReactiveNodeDriver<E>, content?: Script<E>, contentAsync?: ScriptAsync<E>, key?: string, mode?: Mode, creation?: Script<E>, creationAsync?: ScriptAsync<E>, destruction?: Script<E>, triggers?: unknown, basis?: ReactiveNodeDecl<E>): ReactiveNode<E>;
40
40
  static declare<E = void>(driver: ReactiveNodeDriver<E>, declaration?: ReactiveNodeDecl<E>): ReactiveNode<E>;
41
- static declare<E = void>(driver: ReactiveNodeDriver<E>, scriptOrDeclaration?: Script<E> | ReactiveNodeDecl<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, creation?: Script<E>, creationAsync?: ScriptAsync<E>, destruction?: Script<E>, triggers?: unknown, basis?: ReactiveNodeDecl<E>): ReactiveNode<E>;
41
+ static declare<E = void>(driver: ReactiveNodeDriver<E>, contentOrDeclaration?: Script<E> | ReactiveNodeDecl<E>, contentAsync?: ScriptAsync<E>, key?: string, mode?: Mode, creation?: Script<E>, creationAsync?: ScriptAsync<E>, destruction?: Script<E>, triggers?: unknown, basis?: ReactiveNodeDecl<E>): ReactiveNode<E>;
42
42
  static withBasis<E = void>(declaration?: ReactiveNodeDecl<E>, basis?: ReactiveNodeDecl<E>): ReactiveNodeDecl<E>;
43
43
  static get isFirstUpdate(): boolean;
44
44
  static get key(): string;
@@ -59,8 +59,8 @@ export declare abstract class ReactiveNode<E = unknown> {
59
59
  static setDefaultLoggingOptions(logging?: LoggingOptions): void;
60
60
  }
61
61
  export type ReactiveNodeDecl<E = unknown> = {
62
- script?: Script<E>;
63
- scriptAsync?: ScriptAsync<E>;
62
+ content?: Script<E>;
63
+ contentAsync?: ScriptAsync<E>;
64
64
  key?: string;
65
65
  mode?: Mode;
66
66
  creation?: Script<E>;
@@ -26,7 +26,7 @@ import { ReactiveSystem, options, raw, reactive, unobs } from "../ReactiveSystem
26
26
  export var Mode;
27
27
  (function (Mode) {
28
28
  Mode[Mode["default"] = 0] = "default";
29
- Mode[Mode["independentUpdate"] = 1] = "independentUpdate";
29
+ Mode[Mode["autonomous"] = 1] = "autonomous";
30
30
  Mode[Mode["manualMount"] = 2] = "manualMount";
31
31
  })(Mode || (Mode = {}));
32
32
  export var Priority;
@@ -36,23 +36,23 @@ export var Priority;
36
36
  Priority[Priority["background"] = 2] = "background";
37
37
  })(Priority || (Priority = {}));
38
38
  export class ReactiveNode {
39
- static declare(driver, scriptOrDeclaration, scriptAsync, key, mode, creation, creationAsync, destruction, triggers, basis) {
39
+ static declare(driver, contentOrDeclaration, contentAsync, key, mode, creation, creationAsync, destruction, triggers, basis) {
40
40
  let result;
41
41
  let declaration;
42
- if (scriptOrDeclaration instanceof Function) {
42
+ if (contentOrDeclaration instanceof Function) {
43
43
  declaration = {
44
- script: scriptOrDeclaration, scriptAsync, key, mode,
44
+ content: contentOrDeclaration, contentAsync, key, mode,
45
45
  creation, creationAsync, destruction, triggers, basis,
46
46
  };
47
47
  }
48
48
  else
49
- declaration = scriptOrDeclaration !== null && scriptOrDeclaration !== void 0 ? scriptOrDeclaration : {};
49
+ declaration = contentOrDeclaration !== null && contentOrDeclaration !== void 0 ? contentOrDeclaration : {};
50
50
  let effectiveKey = declaration.key;
51
51
  const owner = gOwnSeat === null || gOwnSeat === void 0 ? void 0 : gOwnSeat.instance;
52
52
  if (owner) {
53
53
  let existing = owner.driver.child(owner, driver, declaration, declaration.basis);
54
54
  const children = owner.children;
55
- existing !== null && existing !== void 0 ? existing : (existing = children.tryMergeAsExisting(effectiveKey = effectiveKey || generateKey(owner), undefined, "nested elements can be declared inside update function only"));
55
+ existing !== null && existing !== void 0 ? existing : (existing = children.tryMergeAsExisting(effectiveKey = effectiveKey || generateKey(owner), undefined, "nested elements can be declared inside content script only"));
56
56
  if (existing) {
57
57
  result = existing.instance;
58
58
  if (result.driver !== driver && driver !== undefined)
@@ -174,7 +174,7 @@ export class BaseDriver {
174
174
  mount(node) {
175
175
  }
176
176
  update(node) {
177
- return invokeScriptUsingBasisChain(node.element, node.declaration);
177
+ return invokeContentUsingBasisChain(node.element, node.declaration);
178
178
  }
179
179
  child(ownerNode, childDriver, childDeclaration, childBasis) {
180
180
  return undefined;
@@ -211,22 +211,19 @@ function getModeUsingBasisChain(declaration) {
211
211
  var _a;
212
212
  return (_a = declaration === null || declaration === void 0 ? void 0 : declaration.mode) !== null && _a !== void 0 ? _a : ((declaration === null || declaration === void 0 ? void 0 : declaration.basis) ? getModeUsingBasisChain(declaration === null || declaration === void 0 ? void 0 : declaration.basis) : Mode.default);
213
213
  }
214
- function invokeScriptUsingBasisChain(element, declaration) {
214
+ function invokeContentUsingBasisChain(element, declaration) {
215
215
  let result = undefined;
216
216
  const basis = declaration.basis;
217
- const script = declaration.script;
218
- const scriptAsync = declaration.scriptAsync;
219
- if (script && scriptAsync) {
220
- throw misuse("'script' and 'scriptAsync' cannot be defined together");
221
- }
222
- if (script) {
223
- result = script(element, basis ? () => invokeScriptUsingBasisChain(element, basis) : NOP);
224
- }
225
- else if (scriptAsync) {
226
- result = scriptAsync(element, basis ? () => invokeScriptUsingBasisChain(element, basis) : NOP_ASYNC);
227
- }
217
+ const content = declaration.content;
218
+ const contentAsync = declaration.contentAsync;
219
+ if (content && contentAsync)
220
+ throw misuse("'content' and 'contentAsync' cannot be defined together");
221
+ if (content)
222
+ result = content(element, basis ? () => invokeContentUsingBasisChain(element, basis) : NOP);
223
+ else if (contentAsync)
224
+ result = contentAsync(element, basis ? () => invokeContentUsingBasisChain(element, basis) : NOP_ASYNC);
228
225
  else if (basis)
229
- result = invokeScriptUsingBasisChain(element, basis);
226
+ result = invokeContentUsingBasisChain(element, basis);
230
227
  return result;
231
228
  }
232
229
  function invokeCreationUsingBasisChain(element, declaration) {
@@ -234,15 +231,12 @@ function invokeCreationUsingBasisChain(element, declaration) {
234
231
  const basis = declaration.basis;
235
232
  const creation = declaration.creation;
236
233
  const creationAsync = declaration.creationAsync;
237
- if (creation && creationAsync) {
234
+ if (creation && creationAsync)
238
235
  throw misuse("'creation' and 'creationAsync' cannot be defined together");
239
- }
240
- if (creation) {
236
+ if (creation)
241
237
  result = creation(element, basis ? () => invokeCreationUsingBasisChain(element, basis) : NOP);
242
- }
243
- else if (creationAsync) {
238
+ else if (creationAsync)
244
239
  result = creationAsync(element, basis ? () => invokeCreationUsingBasisChain(element, basis) : NOP_ASYNC);
245
- }
246
240
  else if (basis)
247
241
  result = invokeCreationUsingBasisChain(element, basis);
248
242
  return result;
@@ -299,7 +293,7 @@ class ReactiveNodeImpl extends ReactiveNode {
299
293
  this.priority = Priority.realtime;
300
294
  this.childrenShuffling = false;
301
295
  ReactiveNodeImpl.grandNodeCount++;
302
- if (this.has(Mode.independentUpdate))
296
+ if (this.has(Mode.autonomous))
303
297
  ReactiveNodeImpl.disposableNodeCount++;
304
298
  }
305
299
  get strictOrder() { return this.children.isStrict; }
@@ -312,8 +306,8 @@ class ReactiveNodeImpl extends ReactiveNode {
312
306
  updateNow(this.seat);
313
307
  }
314
308
  configureReactronic(options) {
315
- if (this.stamp < Number.MAX_SAFE_INTEGER - 1 || !this.has(Mode.independentUpdate))
316
- throw new Error("reactronic can be configured only for elements with independent update mode and only during activation");
309
+ if (this.stamp < Number.MAX_SAFE_INTEGER - 1 || !this.has(Mode.autonomous))
310
+ throw new Error("reactronic can be configured only for elements with autonomous mode and only during activation");
317
311
  return ReactiveSystem.getOperation(this.update).configure(options);
318
312
  }
319
313
  static get ownSeat() {
@@ -479,7 +473,7 @@ function updateIncrementally(owner, stamp, allChildren, items, priority) {
479
473
  function triggerUpdateViaSeat(seat) {
480
474
  const node = seat.instance;
481
475
  if (node.stamp >= 0) {
482
- if (node.has(Mode.independentUpdate)) {
476
+ if (node.has(Mode.autonomous)) {
483
477
  if (node.stamp === Number.MAX_SAFE_INTEGER) {
484
478
  Transaction.outside(() => {
485
479
  if (ReactiveSystem.isLogging)
@@ -543,7 +537,7 @@ function triggerDeactivation(seat, isLeader, individual) {
543
537
  console.log(`WARNING: it is recommended to assign explicit key for conditional element in order to avoid unexpected side effects: ${node.key}`);
544
538
  node.stamp = ~node.stamp;
545
539
  const childrenAreLeaders = unobs(() => driver.destroy(node, isLeader));
546
- if (node.has(Mode.independentUpdate)) {
540
+ if (node.has(Mode.autonomous)) {
547
541
  seat.aux = undefined;
548
542
  const last = gLastToDispose;
549
543
  if (last)
@@ -101,7 +101,7 @@ export function getCallerInfo(prefix) {
101
101
  return result;
102
102
  }
103
103
  function extractFunctionAndLocation(s) {
104
- const match = s.match(/(?:\s*at\s+)?(?:(\S+)\s\()?(?:.*?)([^\/\(\):]+)(?:(:|\d)*\)?)$/);
104
+ const match = s.match(/(?:\s*at\s+)?(?:(\S+)\s\()?(?:.*?)([^\/\(\)]+)(?:(:|\d)*\)?)$/);
105
105
  return {
106
106
  func: (match === null || match === void 0 ? void 0 : match[1]) || "",
107
107
  file: (match === null || match === void 0 ? void 0 : match[2]) || "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.24.309",
3
+ "version": "0.24.400",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
5
  "publisher": "Nezaboodka Software",
6
6
  "license": "Apache-2.0",
@@ -31,13 +31,13 @@
31
31
  },
32
32
  "homepage": "https://github.com/nezaboodka/reactronic/blob/master/README.md#readme",
33
33
  "devDependencies": {
34
- "@types/node": "20.11.28",
35
- "@types/react": "18.3.4",
36
- "@typescript-eslint/eslint-plugin": "7.2.0",
37
- "@typescript-eslint/parser": "7.2.0",
38
- "ava": "6.1.2",
39
- "c8": "9.1.0",
40
- "eslint": "8.57.0",
34
+ "@types/node": "22.8.5",
35
+ "@types/react": "18.3.12",
36
+ "@typescript-eslint/eslint-plugin": "8.12.2",
37
+ "@typescript-eslint/parser": "8.12.2",
38
+ "ava": "6.2.0",
39
+ "c8": "10.1.2",
40
+ "eslint": "9.13.0",
41
41
  "react": "18.3.1",
42
42
  "ts-node": "10.9.2",
43
43
  "typescript": "5.5.4"