reactronic 0.24.501 → 0.91.25002

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.
@@ -20,6 +20,7 @@ export declare class ReactiveSystem {
20
20
  export declare function transaction<T>(action: F<T>, ...args: any[]): T;
21
21
  export declare function unobs<T>(func: F<T>, ...args: any[]): T;
22
22
  export declare function sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
23
+ export declare function contextually<T>(p: Promise<T>): Promise<T>;
23
24
  export declare function raw(proto: object, prop: PropertyKey): any;
24
25
  export declare function obs(proto: object, prop: PropertyKey): any;
25
26
  export declare function transactional(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
@@ -31,6 +31,9 @@ export function unobs(func, ...args) {
31
31
  export function sensitive(sensitivity, func, ...args) {
32
32
  return Mvcc.sensitive(sensitivity, func, ...args);
33
33
  }
34
+ export function contextually(p) {
35
+ throw new Error("not implemented yet");
36
+ }
34
37
  export function raw(proto, prop) {
35
38
  return Mvcc.decorateData(false, proto, prop);
36
39
  }
@@ -16,7 +16,7 @@ export { Changeset } from "./core/Changeset.js";
16
16
  export { Transaction } from "./core/Transaction.js";
17
17
  export { Indicator } from "./core/Indicator.js";
18
18
  export { Journal } from "./core/Journal.js";
19
- export { ReactiveSystem, raw, obs, transactional, reactive, cached, transaction, unobs, sensitive, options } from "./ReactiveSystem.js";
19
+ export { ReactiveSystem, raw, obs, transactional, reactive, cached, transaction, unobs, sensitive, contextually, options } from "./ReactiveSystem.js";
20
20
  export { Reaction } from "./Reaction.js";
21
21
  export { ReactiveNode, Mode, Priority, BaseDriver, ReactiveNodeVariable } from "./core/ReactiveNode.js";
22
22
  export type { Script, ScriptAsync, Handler, ReactiveNodeDecl, ReactiveNodeDriver, ReactiveNodeContext } from "./core/ReactiveNode.js";
@@ -12,7 +12,7 @@ export { Changeset } from "./core/Changeset.js";
12
12
  export { Transaction } from "./core/Transaction.js";
13
13
  export { Indicator } from "./core/Indicator.js";
14
14
  export { Journal } from "./core/Journal.js";
15
- export { ReactiveSystem, raw, obs, transactional, reactive, cached, transaction, unobs, sensitive, options } from "./ReactiveSystem.js";
15
+ export { ReactiveSystem, raw, obs, transactional, reactive, cached, transaction, unobs, sensitive, contextually, options } from "./ReactiveSystem.js";
16
16
  export { Reaction } from "./Reaction.js";
17
17
  export { ReactiveNode, Mode, Priority, BaseDriver, ReactiveNodeVariable } from "./core/ReactiveNode.js";
18
18
  export { Clock } from "./Clock.js";
@@ -7,7 +7,8 @@ export type Handler<E = unknown, R = void> = (el: E) => R;
7
7
  export declare enum Mode {
8
8
  default = 0,
9
9
  autonomous = 1,
10
- manualMount = 2
10
+ manualMount = 2,
11
+ rootNode = 4
11
12
  }
12
13
  export declare enum Priority {
13
14
  realtime = 0,
@@ -36,9 +37,9 @@ export declare abstract class ReactiveNode<E = unknown> {
36
37
  static readonly longFrameDuration = 300;
37
38
  static currentUpdatePriority: Priority;
38
39
  static frameDuration: number;
39
- static declare<E = void>(driver: ReactiveNodeDriver<E>, content?: Script<E>, contentAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveNodeDecl<E>): ReactiveNode<E>;
40
+ static declare<E = void>(driver: ReactiveNodeDriver<E>, script?: Script<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveNodeDecl<E>): ReactiveNode<E>;
40
41
  static declare<E = void>(driver: ReactiveNodeDriver<E>, declaration?: ReactiveNodeDecl<E>): ReactiveNode<E>;
41
- static declare<E = void>(driver: ReactiveNodeDriver<E>, contentOrDeclaration?: Script<E> | ReactiveNodeDecl<E>, contentAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveNodeDecl<E>): ReactiveNode<E>;
42
+ static declare<E = void>(driver: ReactiveNodeDriver<E>, scriptOrDeclaration?: Script<E> | ReactiveNodeDecl<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveNodeDecl<E>): ReactiveNode<E>;
42
43
  static withBasis<E = void>(declaration?: ReactiveNodeDecl<E>, basis?: ReactiveNodeDecl<E>): ReactiveNodeDecl<E>;
43
44
  static get isFirstUpdate(): boolean;
44
45
  static get key(): string;
@@ -59,8 +60,8 @@ export declare abstract class ReactiveNode<E = unknown> {
59
60
  static setDefaultLoggingOptions(logging?: LoggingOptions): void;
60
61
  }
61
62
  export type ReactiveNodeDecl<E = unknown> = {
62
- content?: Script<E>;
63
- contentAsync?: ScriptAsync<E>;
63
+ script?: Script<E>;
64
+ scriptAsync?: ScriptAsync<E>;
64
65
  key?: string;
65
66
  mode?: Mode;
66
67
  preparation?: Script<E>;
@@ -74,11 +75,11 @@ export type ReactiveNodeDriver<E = unknown> = {
74
75
  readonly isPartition: boolean;
75
76
  readonly initialize?: Handler<E>;
76
77
  create(node: ReactiveNode<E>): E;
77
- prepare(node: ReactiveNode<E>): void;
78
- finalize(node: ReactiveNode<E>, isLeader: boolean): boolean;
79
- mount(node: ReactiveNode<E>): void;
80
- update(node: ReactiveNode<E>): void | Promise<void>;
81
- child(ownerNode: ReactiveNode<E>, childDriver: ReactiveNodeDriver<any>, childDeclaration?: ReactiveNodeDecl<any>, childBasis?: ReactiveNodeDecl<any>): MergedItem<ReactiveNode> | undefined;
78
+ runPreparation(node: ReactiveNode<E>): void;
79
+ runFinalization(node: ReactiveNode<E>, isLeader: boolean): boolean;
80
+ runMount(node: ReactiveNode<E>): void;
81
+ runScript(node: ReactiveNode<E>): void | Promise<void>;
82
+ declareChild(ownerNode: ReactiveNode<E>, childDriver: ReactiveNodeDriver<any>, childDeclaration?: ReactiveNodeDecl<any>, childBasis?: ReactiveNodeDecl<any>): MergedItem<ReactiveNode> | undefined;
82
83
  provideHost(node: ReactiveNode<E>): ReactiveNode<E>;
83
84
  };
84
85
  export type ReactiveNodeContext<T extends Object = Object> = {
@@ -90,11 +91,11 @@ export declare abstract class BaseDriver<E = unknown> implements ReactiveNodeDri
90
91
  readonly initialize?: Handler<E> | undefined;
91
92
  constructor(name: string, isPartition: boolean, initialize?: Handler<E> | undefined);
92
93
  abstract create(node: ReactiveNode<E>): E;
93
- prepare(node: ReactiveNode<E>): void | Promise<void>;
94
- finalize(node: ReactiveNode<E>, isLeader: boolean): boolean;
95
- mount(node: ReactiveNode<E>): void;
96
- update(node: ReactiveNode<E>): void | Promise<void>;
97
- child(ownerNode: ReactiveNode<E>, childDriver: ReactiveNodeDriver<any>, childDeclaration?: ReactiveNodeDecl<any>, childBasis?: ReactiveNodeDecl<any>): MergedItem<ReactiveNode> | undefined;
94
+ runPreparation(node: ReactiveNode<E>): void | Promise<void>;
95
+ runFinalization(node: ReactiveNode<E>, isLeader: boolean): boolean;
96
+ runMount(node: ReactiveNode<E>): void;
97
+ runScript(node: ReactiveNode<E>): void | Promise<void>;
98
+ declareChild(ownerNode: ReactiveNode<E>, childDriver: ReactiveNodeDriver<any>, childDeclaration?: ReactiveNodeDecl<any>, childBasis?: ReactiveNodeDecl<any>): MergedItem<ReactiveNode> | undefined;
98
99
  provideHost(node: ReactiveNode<E>): ReactiveNode<E>;
99
100
  }
100
101
  export declare class ReactiveNodeVariable<T extends Object = Object> {
@@ -28,6 +28,7 @@ export var Mode;
28
28
  Mode[Mode["default"] = 0] = "default";
29
29
  Mode[Mode["autonomous"] = 1] = "autonomous";
30
30
  Mode[Mode["manualMount"] = 2] = "manualMount";
31
+ Mode[Mode["rootNode"] = 4] = "rootNode";
31
32
  })(Mode || (Mode = {}));
32
33
  export var Priority;
33
34
  (function (Priority) {
@@ -36,23 +37,23 @@ export var Priority;
36
37
  Priority[Priority["background"] = 2] = "background";
37
38
  })(Priority || (Priority = {}));
38
39
  export class ReactiveNode {
39
- static declare(driver, contentOrDeclaration, contentAsync, key, mode, preparation, preparationAsync, finalization, triggers, basis) {
40
+ static declare(driver, scriptOrDeclaration, scriptAsync, key, mode, preparation, preparationAsync, finalization, triggers, basis) {
40
41
  let result;
41
42
  let declaration;
42
- if (contentOrDeclaration instanceof Function) {
43
+ if (scriptOrDeclaration instanceof Function) {
43
44
  declaration = {
44
- content: contentOrDeclaration, contentAsync, key, mode,
45
+ script: scriptOrDeclaration, scriptAsync, key, mode,
45
46
  preparation, preparationAsync, finalization, triggers, basis,
46
47
  };
47
48
  }
48
49
  else
49
- declaration = contentOrDeclaration !== null && contentOrDeclaration !== void 0 ? contentOrDeclaration : {};
50
+ declaration = scriptOrDeclaration !== null && scriptOrDeclaration !== void 0 ? scriptOrDeclaration : {};
50
51
  let effectiveKey = declaration.key;
51
- const owner = gOwnSlot === null || gOwnSlot === void 0 ? void 0 : gOwnSlot.instance;
52
+ const owner = (getModeUsingBasisChain(declaration) & Mode.rootNode) !== Mode.rootNode ? gOwnSlot === null || gOwnSlot === void 0 ? void 0 : gOwnSlot.instance : undefined;
52
53
  if (owner) {
53
- let existing = owner.driver.child(owner, driver, declaration, declaration.basis);
54
+ let existing = owner.driver.declareChild(owner, driver, declaration, declaration.basis);
54
55
  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 content script only"));
56
+ existing !== null && existing !== void 0 ? existing : (existing = children.tryMergeAsExisting(effectiveKey = effectiveKey || generateKey(owner), undefined, "nested elements can be declared inside 'script' only"));
56
57
  if (existing) {
57
58
  result = existing.instance;
58
59
  if (result.driver !== driver && driver !== undefined)
@@ -162,21 +163,21 @@ export class BaseDriver {
162
163
  this.isPartition = isPartition;
163
164
  this.initialize = initialize;
164
165
  }
165
- prepare(node) {
166
+ runPreparation(node) {
166
167
  var _a;
167
168
  (_a = this.initialize) === null || _a === void 0 ? void 0 : _a.call(this, node.element);
168
169
  return invokePreparationUsingBasisChain(node.element, node.declaration);
169
170
  }
170
- finalize(node, isLeader) {
171
+ runFinalization(node, isLeader) {
171
172
  invokeFinalizationUsingBasisChain(node.element, node.declaration);
172
173
  return isLeader;
173
174
  }
174
- mount(node) {
175
+ runMount(node) {
175
176
  }
176
- update(node) {
177
- return invokeContentUsingBasisChain(node.element, node.declaration);
177
+ runScript(node) {
178
+ return invokeScriptUsingBasisChain(node.element, node.declaration);
178
179
  }
179
- child(ownerNode, childDriver, childDeclaration, childBasis) {
180
+ declareChild(ownerNode, childDriver, childDeclaration, childBasis) {
180
181
  return undefined;
181
182
  }
182
183
  provideHost(node) {
@@ -211,19 +212,19 @@ function getModeUsingBasisChain(declaration) {
211
212
  var _a;
212
213
  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
214
  }
214
- function invokeContentUsingBasisChain(element, declaration) {
215
+ function invokeScriptUsingBasisChain(element, declaration) {
215
216
  let result = undefined;
216
217
  const basis = declaration.basis;
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);
218
+ const script = declaration.script;
219
+ const scriptAsync = declaration.scriptAsync;
220
+ if (script && scriptAsync)
221
+ throw misuse("'script' and 'scriptAsync' cannot be defined together");
222
+ if (script)
223
+ result = script(element, basis ? () => invokeScriptUsingBasisChain(element, basis) : NOP);
224
+ else if (scriptAsync)
225
+ result = scriptAsync(element, basis ? () => invokeScriptUsingBasisChain(element, basis) : NOP_ASYNC);
225
226
  else if (basis)
226
- result = invokeContentUsingBasisChain(element, basis);
227
+ result = invokeScriptUsingBasisChain(element, basis);
227
228
  return result;
228
229
  }
229
230
  function invokePreparationUsingBasisChain(element, declaration) {
@@ -494,16 +495,16 @@ function mountOrRemountIfNecessary(node) {
494
495
  if (node.stamp === Number.MAX_SAFE_INTEGER) {
495
496
  unobs(() => {
496
497
  node.stamp = Number.MAX_SAFE_INTEGER - 1;
497
- driver.prepare(node);
498
+ driver.runPreparation(node);
498
499
  if (!node.has(Mode.manualMount)) {
499
500
  node.stamp = 0;
500
501
  if (node.host !== node)
501
- driver.mount(node);
502
+ driver.runMount(node);
502
503
  }
503
504
  });
504
505
  }
505
506
  else if (node.isMoved && !node.has(Mode.manualMount) && node.host !== node)
506
- unobs(() => driver.mount(node));
507
+ unobs(() => driver.runMount(node));
507
508
  }
508
509
  function updateNow(slot) {
509
510
  const node = slot.instance;
@@ -517,7 +518,7 @@ function updateNow(slot) {
517
518
  node.numerator = 0;
518
519
  node.children.beginMerge();
519
520
  const driver = node.driver;
520
- result = driver.update(node);
521
+ result = driver.runScript(node);
521
522
  result = proceedSyncOrAsync(result, v => { runUpdateNestedNodesThenDo(slot, undefined, NOP); return v; }, e => { console.log(e); runUpdateNestedNodesThenDo(slot, e !== null && e !== void 0 ? e : new Error("unknown error"), NOP); });
522
523
  }
523
524
  catch (e) {
@@ -536,7 +537,7 @@ function triggerFinalization(slot, isLeader, individual) {
536
537
  if (individual && node.key !== node.declaration.key && !driver.isPartition)
537
538
  console.log(`WARNING: it is recommended to assign explicit key for conditional element in order to avoid unexpected side effects: ${node.key}`);
538
539
  node.stamp = ~node.stamp;
539
- const childrenAreLeaders = unobs(() => driver.finalize(node, isLeader));
540
+ const childrenAreLeaders = unobs(() => driver.runFinalization(node, isLeader));
540
541
  if (node.has(Mode.autonomous)) {
541
542
  slot.aux = undefined;
542
543
  const last = gLastToDispose;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.24.501",
3
+ "version": "0.91.25002",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
5
  "publisher": "Nezaboodka Software",
6
6
  "license": "Apache-2.0",
@@ -31,14 +31,14 @@
31
31
  },
32
32
  "homepage": "https://github.com/nezaboodka/reactronic/blob/master/README.md#readme",
33
33
  "devDependencies": {
34
- "@types/node": "22.8.6",
35
- "@types/react": "18.3.12",
36
- "@typescript-eslint/eslint-plugin": "8.12.2",
37
- "@typescript-eslint/parser": "8.12.2",
34
+ "@types/node": "22.13.0",
35
+ "@types/react": "19.0.8",
36
+ "@typescript-eslint/eslint-plugin": "8.22.0",
37
+ "@typescript-eslint/parser": "8.22.0",
38
38
  "ava": "6.2.0",
39
- "c8": "10.1.2",
40
- "eslint": "9.14.0",
41
- "react": "18.3.1",
39
+ "c8": "10.1.3",
40
+ "eslint": "9.19.0",
41
+ "react": "19.0.0",
42
42
  "ts-node": "10.9.2",
43
43
  "typescript": "5.5.4"
44
44
  },