reactronic 0.94.25029 → 0.94.25031

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
@@ -231,7 +231,7 @@ class Component<P> extends React.Component<P> {
231
231
  }
232
232
 
233
233
  componentWillUnmount(): void {
234
- atomicAction(ReactiveSystem.dispose, this)
234
+ atomicAction(disposeObservableObject, this)
235
235
  }
236
236
  }
237
237
  ```
@@ -1,4 +1,5 @@
1
+ import { misuse } from "./util/Dbg.js";
1
2
  import { ObservableObject } from "./core/Mvcc.js";
2
3
  export class Pipe extends ObservableObject {
3
- static create(hint, capacity) { throw new Error("not implemented"); }
4
+ static create(hint, capacity) { throw misuse("not implemented"); }
4
5
  }
@@ -1,3 +1,4 @@
1
+ import { misuse } from "./util/Dbg.js";
1
2
  import { runAtomically, runNonReactively } from "./System.js";
2
3
  export function refs(owner) {
3
4
  return new Proxy(owner, RefGettingProxy);
@@ -34,7 +35,7 @@ export class Ref {
34
35
  return this.variable;
35
36
  }
36
37
  unobserve() {
37
- throw new Error("not implemented");
38
+ throw misuse("not implemented");
38
39
  }
39
40
  static sameRefs(v1, v2) {
40
41
  return v1.owner === v2.owner && v1.name === v2.name && v1.index === v2.index;
@@ -1,4 +1,4 @@
1
- import { Log } from "./util/Dbg.js";
1
+ import { Log, misuse } from "./util/Dbg.js";
2
2
  import { Kind, Isolation } from "./Enums.js";
3
3
  import { Meta, ObjectHandle } from "./core/Data.js";
4
4
  import { Changeset } from "./core/Changeset.js";
@@ -39,7 +39,7 @@ export function runSensitively(sensitivity, func, ...args) {
39
39
  return Mvcc.sensitive(sensitivity, func, ...args);
40
40
  }
41
41
  export function runContextually(p) {
42
- throw new Error("not implemented yet");
42
+ throw misuse("not implemented yet");
43
43
  }
44
44
  export function manageReactiveOperation(method) {
45
45
  return ReactiveOperationImpl.manageReactiveOperation(method);
@@ -1,4 +1,5 @@
1
1
  export { all, pause, proceedSyncOrAsync } from "./util/Utils.js";
2
+ export { Uri } from "./util/Uri.js";
2
3
  export { MergeList } from "./util/MergeList.js";
3
4
  export type { MergedItem, MergeListReader } from "./util/MergeList.js";
4
5
  export { SealedArray } from "./util/SealedArray.js";
@@ -20,5 +21,5 @@ export { Journal } from "./core/Journal.js";
20
21
  export { runAtomically, runNonReactively, runSensitively, runContextually, manageReactiveOperation, configureCurrentReactiveOperation, disposeObservableObject } from "./System.js";
21
22
  export { ReactiveSystem, observable, atomic, reactive, cached, options } from "./System.js";
22
23
  export { ReactiveOperationEx } from "./OperationEx.js";
23
- export { ReactiveTree, ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
24
+ export { ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
24
25
  export type { Script, ScriptAsync, Handler, ReactiveTreeNodeDecl, ReactiveTreeNodeDriver, ReactiveTreeNodeContext } from "./core/TreeNode.js";
@@ -1,4 +1,5 @@
1
1
  export { all, pause, proceedSyncOrAsync } from "./util/Utils.js";
2
+ export { Uri } from "./util/Uri.js";
2
3
  export { MergeList } from "./util/MergeList.js";
3
4
  export { SealedArray } from "./util/SealedArray.js";
4
5
  export { SealedMap } from "./util/SealedMap.js";
@@ -16,4 +17,4 @@ export { Journal } from "./core/Journal.js";
16
17
  export { runAtomically, runNonReactively, runSensitively, runContextually, manageReactiveOperation, configureCurrentReactiveOperation, disposeObservableObject } from "./System.js";
17
18
  export { ReactiveSystem, observable, atomic, reactive, cached, options } from "./System.js";
18
19
  export { ReactiveOperationEx } from "./OperationEx.js";
19
- export { ReactiveTree, ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
20
+ export { ReactiveTreeNode, BaseDriver, ReactiveTreeVariable } from "./core/TreeNode.js";
@@ -1,3 +1,4 @@
1
+ import { misuse } from "../util/Dbg.js";
1
2
  import { Isolation } from "../Enums.js";
2
3
  import { ObservableObject } from "./Mvcc.js";
3
4
  import { Meta, ContentFootprint } from "./Data.js";
@@ -38,7 +39,7 @@ export class JournalImpl extends Journal {
38
39
  if (this._unsaved === patch)
39
40
  this._unsaved = new Map();
40
41
  else
41
- throw new Error("not implemented");
42
+ throw misuse("not implemented");
42
43
  }
43
44
  undo(count = 1) {
44
45
  Transaction.run({ hint: "Journal.undo", isolation: Isolation.disjoinFromOuterAndInnerTransactions }, () => {
@@ -6,23 +6,11 @@ import { ObservableObject } from "../core/Mvcc.js";
6
6
  export type Script<E> = (el: E, basis: () => void) => void;
7
7
  export type ScriptAsync<E> = (el: E, basis: () => Promise<void>) => Promise<void>;
8
8
  export type Handler<E = unknown, R = void> = (el: E) => R;
9
- export declare class ReactiveTree {
10
- static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, script?: Script<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
11
- static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, declaration?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
12
- static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, scriptOrDeclaration?: Script<E> | ReactiveTreeNodeDecl<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
13
- static withBasis<E = void>(declaration?: ReactiveTreeNodeDecl<E>, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNodeDecl<E>;
14
- static get isFirstScriptRun(): boolean;
15
- static triggerScriptRun(node: ReactiveTreeNode<any>, triggers: unknown): void;
16
- static triggerFinalization(node: ReactiveTreeNode<any>): void;
17
- static runNestedNodeScriptsThenDo(action: (error: unknown) => void): void;
18
- static markAsMounted(node: ReactiveTreeNode<any>, yes: boolean): void;
19
- static findMatchingHost<E = unknown, R = unknown>(node: ReactiveTreeNode<E>, match: Handler<ReactiveTreeNode<E>, boolean>): ReactiveTreeNode<R> | undefined;
20
- static findMatchingPrevSibling<E = unknown, R = unknown>(node: ReactiveTreeNode<E>, match: Handler<ReactiveTreeNode<E>, boolean>): ReactiveTreeNode<R> | undefined;
21
- static forEachChildRecursively<E = unknown>(node: ReactiveTreeNode<E>, action: Handler<ReactiveTreeNode<E>>): void;
22
- static getDefaultLoggingOptions(): LoggingOptions | undefined;
23
- static setDefaultLoggingOptions(logging?: LoggingOptions): void;
24
- }
25
9
  export declare abstract class ReactiveTreeNode<E = unknown> {
10
+ static readonly shortFrameDuration = 16;
11
+ static readonly longFrameDuration = 300;
12
+ static frameDuration: number;
13
+ static currentScriptPriority: Priority;
26
14
  abstract readonly key: string;
27
15
  abstract readonly driver: ReactiveTreeNodeDriver<E>;
28
16
  abstract readonly declaration: Readonly<ReactiveTreeNodeDecl<E>>;
@@ -38,16 +26,25 @@ export declare abstract class ReactiveTreeNode<E = unknown> {
38
26
  abstract priority?: Priority;
39
27
  abstract childrenShuffling: boolean;
40
28
  abstract strictOrder: boolean;
29
+ abstract getUri(relativeTo?: ReactiveTreeNode<any>): string;
41
30
  abstract has(mode: Mode): boolean;
42
- abstract configureReactronic(options: Partial<ReactivityOptions>): ReactivityOptions;
43
- static get key(): string;
44
- static get stamp(): number;
45
- static get triggers(): unknown;
46
- static get priority(): Priority;
47
- static set priority(value: Priority);
48
- static get childrenShuffling(): boolean;
49
- static set childrenShuffling(value: boolean);
50
- static get effectiveScriptPriority(): Priority;
31
+ abstract configureReactivity(options: Partial<ReactivityOptions>): ReactivityOptions;
32
+ static get current(): ReactiveTreeNode;
33
+ static get isFirstScriptRun(): boolean;
34
+ static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, script?: Script<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
35
+ static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, declaration?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
36
+ static declare<E = void>(driver: ReactiveTreeNodeDriver<E>, scriptOrDeclaration?: Script<E> | ReactiveTreeNodeDecl<E>, scriptAsync?: ScriptAsync<E>, key?: string, mode?: Mode, preparation?: Script<E>, preparationAsync?: ScriptAsync<E>, finalization?: Script<E>, triggers?: unknown, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNode<E>;
37
+ static withBasis<E = void>(declaration?: ReactiveTreeNodeDecl<E>, basis?: ReactiveTreeNodeDecl<E>): ReactiveTreeNodeDecl<E>;
38
+ static triggerScriptRun(node: ReactiveTreeNode<any>, triggers: unknown): void;
39
+ static triggerFinalization(node: ReactiveTreeNode<any>): void;
40
+ static runNestedNodeScriptsThenDo(action: (error: unknown) => void): void;
41
+ static markAsMounted(node: ReactiveTreeNode<any>, yes: boolean): void;
42
+ lookupTreeNodeByUri<E = unknown>(uri: string): ReactiveTreeNode<E> | undefined;
43
+ static findMatchingHost<E = unknown, R = unknown>(node: ReactiveTreeNode<E>, match: Handler<ReactiveTreeNode<E>, boolean>): ReactiveTreeNode<R> | undefined;
44
+ static findMatchingPrevSibling<E = unknown, R = unknown>(node: ReactiveTreeNode<E>, match: Handler<ReactiveTreeNode<E>, boolean>): ReactiveTreeNode<R> | undefined;
45
+ static forEachChildRecursively<E = unknown>(node: ReactiveTreeNode<E>, action: Handler<ReactiveTreeNode<E>>): void;
46
+ static getDefaultLoggingOptions(): LoggingOptions | undefined;
47
+ static setDefaultLoggingOptions(logging?: LoggingOptions): void;
51
48
  }
52
49
  export type ReactiveTreeNodeDecl<E = unknown> = {
53
50
  script?: Script<E>;
@@ -95,7 +92,7 @@ export declare class ReactiveTreeVariable<T extends Object = Object> {
95
92
  get value(): T;
96
93
  get valueOrUndefined(): T | undefined;
97
94
  }
98
- export declare function generateKey(owner: ReactiveTreeNodeImpl): string;
95
+ export declare function generateKey(owner?: ReactiveTreeNodeImpl): string;
99
96
  export declare function getModeUsingBasisChain(declaration?: ReactiveTreeNodeDecl<any>): Mode;
100
97
  declare class ReactiveTreeNodeContextImpl<T extends Object = Object> extends ObservableObject implements ReactiveTreeNodeContext<T> {
101
98
  next: ReactiveTreeNodeContextImpl<object> | undefined;
@@ -107,10 +104,6 @@ declare class ReactiveTreeNodeImpl<E = unknown> extends ReactiveTreeNode<E> {
107
104
  static logging: LoggingOptions | undefined;
108
105
  static grandNodeCount: number;
109
106
  static disposableNodeCount: number;
110
- static readonly shortFrameDuration = 16;
111
- static readonly longFrameDuration = 300;
112
- static currentScriptPriority: Priority;
113
- static frameDuration: number;
114
107
  readonly key: string;
115
108
  readonly driver: ReactiveTreeNodeDriver<E>;
116
109
  declaration: ReactiveTreeNodeDecl<E>;
@@ -127,16 +120,17 @@ declare class ReactiveTreeNodeImpl<E = unknown> extends ReactiveTreeNode<E> {
127
120
  priority: Priority;
128
121
  childrenShuffling: boolean;
129
122
  constructor(key: string, driver: ReactiveTreeNodeDriver<E>, declaration: Readonly<ReactiveTreeNodeDecl<E>>, owner: ReactiveTreeNodeImpl | undefined);
123
+ getUri(relativeTo?: ReactiveTreeNode<any>): string;
130
124
  get strictOrder(): boolean;
131
125
  set strictOrder(value: boolean);
132
126
  get isMoved(): boolean;
133
127
  has(mode: Mode): boolean;
134
128
  script(_triggers: unknown): void;
135
- configureReactronic(options: Partial<ReactivityOptions>): ReactivityOptions;
129
+ configureReactivity(options: Partial<ReactivityOptions>): ReactivityOptions;
136
130
  static get nodeSlot(): MergedItem<ReactiveTreeNodeImpl>;
137
- static tryUseNodeVariableValue<T extends Object>(variable: ReactiveTreeVariable<T>): T | undefined;
138
- static useNodeVariableValue<T extends Object>(variable: ReactiveTreeVariable<T>): T;
139
- static setNodeVariableValue<T extends Object>(variable: ReactiveTreeVariable<T>, value: T | undefined): void;
131
+ static tryUseTreeVariableValue<T extends Object>(variable: ReactiveTreeVariable<T>): T | undefined;
132
+ static useTreeVariableValue<T extends Object>(variable: ReactiveTreeVariable<T>): T;
133
+ static setTreeVariableValue<T extends Object>(variable: ReactiveTreeVariable<T>, value: T | undefined): void;
140
134
  }
141
135
  export declare function observablesAreEqual(a1: any, a2: any): boolean;
142
136
  export {};
@@ -17,13 +17,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
17
17
  });
18
18
  };
19
19
  import { misuse } from "../util/Dbg.js";
20
+ import { Uri } from "../util/Uri.js";
20
21
  import { MergeList } from "../util/MergeList.js";
21
22
  import { emitLetters, getCallerInfo, proceedSyncOrAsync } from "../util/Utils.js";
22
23
  import { Priority, Mode, Isolation, Reentrance } from "../Enums.js";
23
24
  import { ObservableObject } from "../core/Mvcc.js";
24
25
  import { Transaction } from "../core/Transaction.js";
25
26
  import { ReactiveSystem, options, observable, reactive, runAtomically, runNonReactively, manageReactiveOperation, disposeObservableObject } from "../System.js";
26
- export class ReactiveTree {
27
+ export class ReactiveTreeNode {
28
+ static get current() {
29
+ return ReactiveTreeNodeImpl.nodeSlot.instance;
30
+ }
31
+ static get isFirstScriptRun() {
32
+ return ReactiveTreeNode.current.stamp === 1;
33
+ }
27
34
  static declare(driver, scriptOrDeclaration, scriptAsync, key, mode, preparation, preparationAsync, finalization, triggers, basis) {
28
35
  let result;
29
36
  let declaration;
@@ -44,7 +51,7 @@ export class ReactiveTree {
44
51
  if (existing) {
45
52
  result = existing.instance;
46
53
  if (result.driver !== driver && driver !== undefined)
47
- throw new Error(`changing element driver is not yet supported: "${result.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
54
+ throw misuse(`changing element driver is not yet supported: "${result.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
48
55
  const exTriggers = result.declaration.triggers;
49
56
  if (observablesAreEqual(declaration.triggers, exTriggers))
50
57
  declaration.triggers = exTriggers;
@@ -56,7 +63,7 @@ export class ReactiveTree {
56
63
  }
57
64
  }
58
65
  else {
59
- result = new ReactiveTreeNodeImpl(effectiveKey || "", driver, declaration, owner);
66
+ result = new ReactiveTreeNodeImpl(effectiveKey || generateKey(owner), driver, declaration, owner);
60
67
  result.slot = MergeList.createItem(result);
61
68
  triggerScriptRunViaSlot(result.slot);
62
69
  }
@@ -69,9 +76,6 @@ export class ReactiveTree {
69
76
  declaration = basis !== null && basis !== void 0 ? basis : {};
70
77
  return declaration;
71
78
  }
72
- static get isFirstScriptRun() {
73
- return ReactiveTreeNodeImpl.nodeSlot.instance.stamp === 1;
74
- }
75
79
  static triggerScriptRun(node, triggers) {
76
80
  const impl = node;
77
81
  const declaration = impl.declaration;
@@ -90,11 +94,22 @@ export class ReactiveTree {
90
94
  static markAsMounted(node, yes) {
91
95
  const n = node;
92
96
  if (n.stamp < 0)
93
- throw new Error("deactivated node cannot be mounted or unmounted");
97
+ throw misuse("deactivated node cannot be mounted or unmounted");
94
98
  if (n.stamp >= Number.MAX_SAFE_INTEGER)
95
- throw new Error("node must be activated before mounting");
99
+ throw misuse("node must be activated before mounting");
96
100
  n.stamp = yes ? 0 : Number.MAX_SAFE_INTEGER - 1;
97
101
  }
102
+ lookupTreeNodeByUri(uri) {
103
+ var _a;
104
+ const t = Uri.parse(uri);
105
+ if (t.authority !== this.key)
106
+ throw misuse(`authority '${t.authority}' doesn't match root node key '${this.key}'`);
107
+ const segments = t.path.split("/");
108
+ let result = this;
109
+ for (let i = 1; i < segments.length && result !== undefined; i++)
110
+ result = (_a = result.children.lookup(segments[i])) === null || _a === void 0 ? void 0 : _a.instance;
111
+ return result;
112
+ }
98
113
  static findMatchingHost(node, match) {
99
114
  let p = node.host;
100
115
  while (p !== p.host && !match(p))
@@ -110,7 +125,7 @@ export class ReactiveTree {
110
125
  static forEachChildRecursively(node, action) {
111
126
  action(node);
112
127
  for (const child of node.children.items())
113
- ReactiveTree.forEachChildRecursively(child.instance, action);
128
+ ReactiveTreeNode.forEachChildRecursively(child.instance, action);
114
129
  }
115
130
  static getDefaultLoggingOptions() {
116
131
  return ReactiveTreeNodeImpl.logging;
@@ -119,32 +134,10 @@ export class ReactiveTree {
119
134
  ReactiveTreeNodeImpl.logging = logging;
120
135
  }
121
136
  }
122
- export class ReactiveTreeNode {
123
- static get key() {
124
- return ReactiveTreeNodeImpl.nodeSlot.instance.key;
125
- }
126
- static get stamp() {
127
- return ReactiveTreeNodeImpl.nodeSlot.instance.stamp;
128
- }
129
- static get triggers() {
130
- return ReactiveTreeNodeImpl.nodeSlot.instance.declaration.triggers;
131
- }
132
- static get priority() {
133
- return ReactiveTreeNodeImpl.nodeSlot.instance.priority;
134
- }
135
- static set priority(value) {
136
- ReactiveTreeNodeImpl.nodeSlot.instance.priority = value;
137
- }
138
- static get childrenShuffling() {
139
- return ReactiveTreeNodeImpl.nodeSlot.instance.childrenShuffling;
140
- }
141
- static set childrenShuffling(value) {
142
- ReactiveTreeNodeImpl.nodeSlot.instance.childrenShuffling = value;
143
- }
144
- static get effectiveScriptPriority() {
145
- return ReactiveTreeNodeImpl.currentScriptPriority;
146
- }
147
- }
137
+ ReactiveTreeNode.shortFrameDuration = 16;
138
+ ReactiveTreeNode.longFrameDuration = 300;
139
+ ReactiveTreeNode.frameDuration = ReactiveTreeNode.longFrameDuration;
140
+ ReactiveTreeNode.currentScriptPriority = Priority.realtime;
148
141
  export class BaseDriver {
149
142
  constructor(name, isPartition, initialize) {
150
143
  this.name = name;
@@ -177,17 +170,17 @@ export class ReactiveTreeVariable {
177
170
  this.defaultValue = defaultValue;
178
171
  }
179
172
  set value(value) {
180
- ReactiveTreeNodeImpl.setNodeVariableValue(this, value);
173
+ ReactiveTreeNodeImpl.setTreeVariableValue(this, value);
181
174
  }
182
175
  get value() {
183
- return ReactiveTreeNodeImpl.useNodeVariableValue(this);
176
+ return ReactiveTreeNodeImpl.useTreeVariableValue(this);
184
177
  }
185
178
  get valueOrUndefined() {
186
- return ReactiveTreeNodeImpl.tryUseNodeVariableValue(this);
179
+ return ReactiveTreeNodeImpl.tryUseTreeVariableValue(this);
187
180
  }
188
181
  }
189
182
  export function generateKey(owner) {
190
- const n = owner.numerator++;
183
+ const n = owner !== undefined ? owner.numerator++ : 0;
191
184
  const lettered = emitLetters(n);
192
185
  let result;
193
186
  if (ReactiveSystem.isLogging)
@@ -285,40 +278,56 @@ class ReactiveTreeNodeImpl extends ReactiveTreeNode {
285
278
  if (this.has(Mode.autonomous))
286
279
  ReactiveTreeNodeImpl.disposableNodeCount++;
287
280
  }
288
- get strictOrder() { return this.children.isStrict; }
289
- set strictOrder(value) { this.children.isStrict = value; }
290
- get isMoved() { return this.owner.children.isMoved(this.slot); }
281
+ getUri(relativeTo) {
282
+ const path = [];
283
+ const authority = gatherAuthorityAndPath(this, path);
284
+ const result = Uri.from({
285
+ scheme: "node",
286
+ authority,
287
+ path: "/" + path.join("/"),
288
+ });
289
+ return result.toString();
290
+ }
291
+ get strictOrder() {
292
+ return this.children.isStrict;
293
+ }
294
+ set strictOrder(value) {
295
+ this.children.isStrict = value;
296
+ }
297
+ get isMoved() {
298
+ return this.owner.children.isMoved(this.slot);
299
+ }
291
300
  has(mode) {
292
301
  return (getModeUsingBasisChain(this.declaration) & mode) === mode;
293
302
  }
294
303
  script(_triggers) {
295
304
  runScriptNow(this.slot);
296
305
  }
297
- configureReactronic(options) {
306
+ configureReactivity(options) {
298
307
  if (this.stamp < Number.MAX_SAFE_INTEGER - 1 || !this.has(Mode.autonomous))
299
- throw new Error("reactronic can be configured only for elements with autonomous mode and only during activation");
308
+ throw misuse("reactronic can be configured only for elements with autonomous mode and only during preparation");
300
309
  return manageReactiveOperation(this.script).configure(options);
301
310
  }
302
311
  static get nodeSlot() {
303
312
  if (!gNodeSlot)
304
- throw new Error("current element is undefined");
313
+ throw misuse("current element is undefined");
305
314
  return gNodeSlot;
306
315
  }
307
- static tryUseNodeVariableValue(variable) {
316
+ static tryUseTreeVariableValue(variable) {
308
317
  var _a, _b;
309
318
  let node = ReactiveTreeNodeImpl.nodeSlot.instance;
310
319
  while (((_a = node.context) === null || _a === void 0 ? void 0 : _a.variable) !== variable && node.owner !== node)
311
320
  node = node.outer.slot.instance;
312
321
  return (_b = node.context) === null || _b === void 0 ? void 0 : _b.value;
313
322
  }
314
- static useNodeVariableValue(variable) {
323
+ static useTreeVariableValue(variable) {
315
324
  var _a;
316
- const result = (_a = ReactiveTreeNodeImpl.tryUseNodeVariableValue(variable)) !== null && _a !== void 0 ? _a : variable.defaultValue;
325
+ const result = (_a = ReactiveTreeNodeImpl.tryUseTreeVariableValue(variable)) !== null && _a !== void 0 ? _a : variable.defaultValue;
317
326
  if (!result)
318
- throw new Error("unknown node variable");
327
+ throw misuse("unknown node variable");
319
328
  return result;
320
329
  }
321
- static setNodeVariableValue(variable, value) {
330
+ static setTreeVariableValue(variable, value) {
322
331
  const node = ReactiveTreeNodeImpl.nodeSlot.instance;
323
332
  const owner = node.owner;
324
333
  const hostCtx = runNonReactively(() => { var _a; return (_a = owner.context) === null || _a === void 0 ? void 0 : _a.value; });
@@ -346,10 +355,6 @@ class ReactiveTreeNodeImpl extends ReactiveTreeNode {
346
355
  ReactiveTreeNodeImpl.logging = undefined;
347
356
  ReactiveTreeNodeImpl.grandNodeCount = 0;
348
357
  ReactiveTreeNodeImpl.disposableNodeCount = 0;
349
- ReactiveTreeNodeImpl.shortFrameDuration = 16;
350
- ReactiveTreeNodeImpl.longFrameDuration = 300;
351
- ReactiveTreeNodeImpl.currentScriptPriority = Priority.realtime;
352
- ReactiveTreeNodeImpl.frameDuration = ReactiveTreeNodeImpl.longFrameDuration;
353
358
  __decorate([
354
359
  reactive,
355
360
  options({
@@ -362,6 +367,16 @@ __decorate([
362
367
  __metadata("design:paramtypes", [Object]),
363
368
  __metadata("design:returntype", void 0)
364
369
  ], ReactiveTreeNodeImpl.prototype, "script", null);
370
+ function gatherAuthorityAndPath(node, path, relativeTo) {
371
+ let authority;
372
+ if (node.owner !== node && node.owner !== relativeTo) {
373
+ authority = gatherAuthorityAndPath(node.owner, path);
374
+ path.push(node.key);
375
+ }
376
+ else
377
+ authority = node.key;
378
+ return authority;
379
+ }
365
380
  function getNodeKey(node) {
366
381
  return node.stamp >= 0 ? node.key : undefined;
367
382
  }
@@ -442,8 +457,8 @@ function runNestedScriptsIncrementally(owner, stamp, allChildren, items, priorit
442
457
  try {
443
458
  if (node.childrenShuffling)
444
459
  shuffle(items);
445
- const frameDurationLimit = priority === Priority.background ? ReactiveTreeNodeImpl.shortFrameDuration : Infinity;
446
- let frameDuration = Math.min(frameDurationLimit, Math.max(ReactiveTreeNodeImpl.frameDuration / 4, ReactiveTreeNodeImpl.shortFrameDuration));
460
+ const frameDurationLimit = priority === Priority.background ? ReactiveTreeNode.shortFrameDuration : Infinity;
461
+ let frameDuration = Math.min(frameDurationLimit, Math.max(ReactiveTreeNode.frameDuration / 4, ReactiveTreeNode.shortFrameDuration));
447
462
  for (const child of items) {
448
463
  triggerScriptRunViaSlot(child);
449
464
  if (Transaction.isFrameOver(1, frameDuration)) {
@@ -451,9 +466,9 @@ function runNestedScriptsIncrementally(owner, stamp, allChildren, items, priorit
451
466
  yield Transaction.requestNextFrame(0);
452
467
  outerPriority = ReactiveTreeNodeImpl.currentScriptPriority;
453
468
  ReactiveTreeNodeImpl.currentScriptPriority = priority;
454
- frameDuration = Math.min(4 * frameDuration, Math.min(frameDurationLimit, ReactiveTreeNodeImpl.frameDuration));
469
+ frameDuration = Math.min(4 * frameDuration, Math.min(frameDurationLimit, ReactiveTreeNode.frameDuration));
455
470
  }
456
- if (Transaction.isCanceled && Transaction.isFrameOver(1, ReactiveTreeNodeImpl.shortFrameDuration / 3))
471
+ if (Transaction.isCanceled && Transaction.isFrameOver(1, ReactiveTreeNode.shortFrameDuration / 3))
457
472
  break;
458
473
  }
459
474
  }
@@ -1,3 +1,4 @@
1
+ import { misuse } from "./Dbg.js";
1
2
  export class MergeList {
2
3
  constructor(getKey, strict = false) {
3
4
  this.getKey = getKey;
@@ -13,7 +14,7 @@ export class MergeList {
13
14
  get isStrict() { return this.strict; }
14
15
  set isStrict(value) {
15
16
  if (this.isMergeInProgress && this.current.count > 0)
16
- throw new Error("cannot change strict mode in the middle of merge");
17
+ throw misuse("cannot change strict mode in the middle of merge");
17
18
  this.strict = value;
18
19
  }
19
20
  get count() {
@@ -46,7 +47,7 @@ export class MergeList {
46
47
  tryMergeAsExisting(key, resolution, error) {
47
48
  const tag = this.tag;
48
49
  if (tag < 0)
49
- throw new Error(error !== null && error !== void 0 ? error : "merge is not in progress");
50
+ throw misuse(error !== null && error !== void 0 ? error : "merge is not in progress");
50
51
  let item = this.strictNextItem;
51
52
  if (key !== (item ? this.getKey(item.instance) : undefined))
52
53
  item = this.lookup(key);
@@ -65,7 +66,7 @@ export class MergeList {
65
66
  else if (resolution)
66
67
  resolution.isDuplicate = true;
67
68
  else
68
- throw new Error(`duplicate collection item: ${key}`);
69
+ throw misuse(`duplicate collection item: ${key}`);
69
70
  }
70
71
  else if (resolution)
71
72
  resolution.isDuplicate = false;
@@ -74,7 +75,7 @@ export class MergeList {
74
75
  mergeAsAdded(instance) {
75
76
  const key = this.getKey(instance);
76
77
  if (this.lookup(key) !== undefined)
77
- throw new Error(`key is already in use: ${key}`);
78
+ throw misuse(`key is already in use: ${key}`);
78
79
  let tag = this.tag;
79
80
  if (tag < 0) {
80
81
  tag = ~this.tag + 1;
@@ -98,11 +99,11 @@ export class MergeList {
98
99
  }
99
100
  }
100
101
  move(item, after) {
101
- throw new Error("not implemented");
102
+ throw misuse("not implemented");
102
103
  }
103
104
  beginMerge() {
104
105
  if (this.isMergeInProgress)
105
- throw new Error("merge is in progress already");
106
+ throw misuse("merge is in progress already");
106
107
  this.tag = ~this.tag + 1;
107
108
  this.strictNextItem = this.current.first;
108
109
  this.removed.grab(this.current, false);
@@ -110,7 +111,7 @@ export class MergeList {
110
111
  }
111
112
  endMerge(error) {
112
113
  if (!this.isMergeInProgress)
113
- throw new Error("merge is ended already");
114
+ throw misuse("merge is ended already");
114
115
  this.tag = ~this.tag;
115
116
  if (error === undefined) {
116
117
  const currentCount = this.current.count;
@@ -0,0 +1,20 @@
1
+ export interface UriComponents {
2
+ scheme: string;
3
+ authority?: string;
4
+ path?: string;
5
+ query?: string;
6
+ fragment?: string;
7
+ }
8
+ export declare class Uri implements UriComponents {
9
+ private static readonly regexp;
10
+ readonly scheme: string;
11
+ readonly authority: string;
12
+ readonly path: string;
13
+ readonly query: string;
14
+ readonly fragment: string;
15
+ protected constructor(scheme: string, authority?: string, path?: string, query?: string, fragment?: string);
16
+ equalsTo(uri: Uri): boolean;
17
+ toString(): string;
18
+ static parse(value: string): Uri;
19
+ static from(components: UriComponents): Uri;
20
+ }
@@ -0,0 +1,67 @@
1
+ import { misuse } from "./Dbg.js";
2
+ export class Uri {
3
+ constructor(scheme, authority, path, query, fragment) {
4
+ this.scheme = scheme;
5
+ this.authority = authority !== null && authority !== void 0 ? authority : "";
6
+ this.path = path !== null && path !== void 0 ? path : "";
7
+ this.query = query !== null && query !== void 0 ? query : "";
8
+ this.fragment = fragment !== null && fragment !== void 0 ? fragment : "";
9
+ validateUri(this);
10
+ }
11
+ equalsTo(uri) {
12
+ return this.scheme === uri.scheme &&
13
+ this.authority === uri.authority &&
14
+ this.path === uri.path &&
15
+ this.query === uri.query &&
16
+ this.fragment === uri.fragment;
17
+ }
18
+ toString() {
19
+ let result = `${this.scheme}://${this.authority}${this.path}`;
20
+ if (this.query) {
21
+ result += `?${this.query}`;
22
+ }
23
+ if (this.fragment) {
24
+ result += `#${this.fragment}`;
25
+ }
26
+ return result;
27
+ }
28
+ static parse(value) {
29
+ var _a, _b, _c, _d, _e;
30
+ let result;
31
+ const match = Uri.regexp.exec(value);
32
+ if (!match) {
33
+ result = new Uri("");
34
+ }
35
+ else {
36
+ result = new Uri((_a = match[2]) !== null && _a !== void 0 ? _a : "", (_b = match[4]) !== null && _b !== void 0 ? _b : "", (_c = match[5]) !== null && _c !== void 0 ? _c : "", (_d = match[7]) !== null && _d !== void 0 ? _d : "", (_e = match[9]) !== null && _e !== void 0 ? _e : "");
37
+ }
38
+ return result;
39
+ }
40
+ static from(components) {
41
+ return new Uri(components.scheme, components.authority, components.path, components.query, components.fragment);
42
+ }
43
+ }
44
+ Uri.regexp = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
45
+ const SCHEME_PATTERN = /^\w[\w\d+.-]*$/;
46
+ const SINGLE_SLASH_START = /^\//;
47
+ const DOUBLE_SLASH_START = /^\/\//;
48
+ function validateUri(uri, strict) {
49
+ if (!uri.scheme && strict) {
50
+ throw misuse(`Scheme is missing: {scheme: "", authority: "${uri.authority}", path: "${uri.path}", query: "${uri.query}", fragment: "${uri.fragment}"}`);
51
+ }
52
+ if (uri.scheme && !SCHEME_PATTERN.test(uri.scheme)) {
53
+ throw misuse("Scheme contains illegal characters.");
54
+ }
55
+ if (uri.path) {
56
+ if (uri.authority) {
57
+ if (!SINGLE_SLASH_START.test(uri.path)) {
58
+ throw misuse("If a URI contains an authority component, then the path component must either be empty or begin with a slash character ('/').");
59
+ }
60
+ }
61
+ else {
62
+ if (DOUBLE_SLASH_START.test(uri.path)) {
63
+ throw misuse("If a URI does not contain an authority component, then the path cannot begin with two slash characters ('//').");
64
+ }
65
+ }
66
+ }
67
+ }
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { fatal, misuse } from "./Dbg.js";
10
11
  export class Utils {
11
12
  static freezeSet(obj) {
12
13
  if (obj instanceof Set) {
@@ -37,7 +38,7 @@ export class Utils {
37
38
  }
38
39
  }
39
40
  export function UNDEF(...args) {
40
- throw new Error("this method should never be called");
41
+ throw fatal(new Error("this method should never be called"));
41
42
  }
42
43
  export function all(promises) {
43
44
  return __awaiter(this, void 0, void 0, function* () {
@@ -63,7 +64,7 @@ export function proceedSyncOrAsync(result, success, failure) {
63
64
  }
64
65
  export function emitLetters(n) {
65
66
  if (n < 0)
66
- throw new Error(`emitLetters: argument (${n}) should not be negative or zero`);
67
+ throw misuse(`emitLetters: argument (${n}) should not be negative or zero`);
67
68
  let result = "";
68
69
  while (n >= 0) {
69
70
  const r = n % 26;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.94.25029",
3
+ "version": "0.94.25031",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
5
  "publisher": "Nezaboodka Software",
6
6
  "license": "Apache-2.0",