reactronic 0.24.118 → 0.24.120

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.
@@ -37,9 +37,15 @@ export declare abstract class RxNode<E = unknown> {
37
37
  static frameDuration: number;
38
38
  static acquire<E = void>(driver: RxNodeDriver<E>, declaration?: RxNodeDecl<E>, preset?: RxNodeDecl<E>): RxNode<E>;
39
39
  static get isFirstUpdate(): boolean;
40
- static get nodeStamp(): number;
40
+ static get key(): string;
41
+ static get stamp(): number;
42
+ static get triggers(): unknown;
43
+ static get priority(): Priority;
44
+ static set priority(value: Priority);
45
+ static get childrenShuffling(): boolean;
46
+ static set childrenShuffling(value: boolean);
41
47
  static triggerUpdate(node: RxNode<any>, triggers: unknown): void;
42
- static updateNestedTreesThenDo(action: (error: unknown) => void): void;
48
+ static updateNestedNodesThenDo(action: (error: unknown) => void): void;
43
49
  static findMatchingHost<E = unknown, R = unknown>(node: RxNode<E>, match: SimpleDelegate<RxNode<E>, boolean>): RxNode<R> | undefined;
44
50
  static findMatchingPrevSibling<E = unknown, R = unknown>(node: RxNode<E>, match: SimpleDelegate<RxNode<E>, boolean>): RxNode<R> | undefined;
45
51
  static forEachChildRecursively<E = unknown>(node: RxNode<E>, action: SimpleDelegate<RxNode<E>>): void;
@@ -17,7 +17,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
17
17
  });
18
18
  };
19
19
  import { MergeList } from '../util/MergeList.js';
20
- import { emitLetters, getCallerInfo } from './RxNodeUtils.js';
20
+ import { emitLetters, getCallerInfo } from '../util/Utils.js';
21
21
  import { Reentrance } from '../Options.js';
22
22
  import { ObservableObject } from '../core/Mvcc.js';
23
23
  import { Transaction } from '../core/Transaction.js';
@@ -43,7 +43,7 @@ export class RxNode {
43
43
  else
44
44
  declaration = preset !== null && preset !== void 0 ? preset : {};
45
45
  let key = declaration.key;
46
- const owner = gCurrent === null || gCurrent === void 0 ? void 0 : gCurrent.instance;
46
+ const owner = gOwnSeat === null || gOwnSeat === void 0 ? void 0 : gOwnSeat.instance;
47
47
  if (owner) {
48
48
  let existing = undefined;
49
49
  const children = owner.children;
@@ -75,11 +75,28 @@ export class RxNode {
75
75
  return result;
76
76
  }
77
77
  static get isFirstUpdate() {
78
- return (gCurrent === null || gCurrent === void 0 ? void 0 : gCurrent.instance.stamp) === 1;
78
+ return RxNodeImpl.ownSeat.instance.stamp === 1;
79
79
  }
80
- static get nodeStamp() {
81
- var _a;
82
- return (_a = gCurrent === null || gCurrent === void 0 ? void 0 : gCurrent.instance.stamp) !== null && _a !== void 0 ? _a : -1;
80
+ static get key() {
81
+ return RxNodeImpl.ownSeat.instance.key;
82
+ }
83
+ static get stamp() {
84
+ return RxNodeImpl.ownSeat.instance.stamp;
85
+ }
86
+ static get triggers() {
87
+ return RxNodeImpl.ownSeat.instance.declaration.triggers;
88
+ }
89
+ static get priority() {
90
+ return RxNodeImpl.ownSeat.instance.priority;
91
+ }
92
+ static set priority(value) {
93
+ RxNodeImpl.ownSeat.instance.priority = value;
94
+ }
95
+ static get childrenShuffling() {
96
+ return RxNodeImpl.ownSeat.instance.childrenShuffling;
97
+ }
98
+ static set childrenShuffling(value) {
99
+ RxNodeImpl.ownSeat.instance.childrenShuffling = value;
83
100
  }
84
101
  static triggerUpdate(node, triggers) {
85
102
  const impl = node;
@@ -89,8 +106,8 @@ export class RxNode {
89
106
  triggerUpdateViaSeat(impl.seat);
90
107
  }
91
108
  }
92
- static updateNestedTreesThenDo(action) {
93
- runUpdateNestedTreesThenDo(undefined, action);
109
+ static updateNestedNodesThenDo(action) {
110
+ runUpdateNestedNodesThenDo(undefined, action);
94
111
  }
95
112
  static findMatchingHost(node, match) {
96
113
  let p = node.host;
@@ -209,8 +226,9 @@ __decorate([
209
226
  raw,
210
227
  __metadata("design:type", RxNodeVariable)
211
228
  ], RxNodeContextImpl.prototype, "variable", void 0);
212
- class RxNodeImpl {
229
+ class RxNodeImpl extends RxNode {
213
230
  constructor(key, driver, declaration, owner) {
231
+ super();
214
232
  const thisAsUnknown = this;
215
233
  this.key = key;
216
234
  this.driver = driver;
@@ -253,14 +271,14 @@ class RxNodeImpl {
253
271
  throw new Error('reactronic can be configured only for elements with independent update mode and only inside initialize');
254
272
  return RxSystem.getReaction(this.update).configure(options);
255
273
  }
256
- static get current() {
257
- if (!gCurrent)
274
+ static get ownSeat() {
275
+ if (!gOwnSeat)
258
276
  throw new Error('current element is undefined');
259
- return gCurrent;
277
+ return gOwnSeat;
260
278
  }
261
279
  static tryUseNodeVariableValue(variable) {
262
280
  var _a, _b;
263
- let node = RxNodeImpl.current.instance;
281
+ let node = RxNodeImpl.ownSeat.instance;
264
282
  while (((_a = node.context) === null || _a === void 0 ? void 0 : _a.variable) !== variable && node.owner !== node)
265
283
  node = node.outer.seat.instance;
266
284
  return (_b = node.context) === null || _b === void 0 ? void 0 : _b.value;
@@ -273,7 +291,7 @@ class RxNodeImpl {
273
291
  return result;
274
292
  }
275
293
  static setNodeVariableValue(variable, value) {
276
- const node = RxNodeImpl.current.instance;
294
+ const node = RxNodeImpl.ownSeat.instance;
277
295
  const owner = node.owner;
278
296
  const hostCtx = unobs(() => { var _a; return (_a = owner.context) === null || _a === void 0 ? void 0 : _a.value; });
279
297
  if (value && value !== hostCtx) {
@@ -314,10 +332,10 @@ __decorate([
314
332
  function getNodeKey(node) {
315
333
  return node.stamp >= 0 ? node.key : undefined;
316
334
  }
317
- function runUpdateNestedTreesThenDo(error, action) {
335
+ function runUpdateNestedNodesThenDo(error, action) {
318
336
  var _a;
319
- const curr = RxNodeImpl.current;
320
- const owner = curr.instance;
337
+ const ownSeat = RxNodeImpl.ownSeat;
338
+ const owner = ownSeat.instance;
321
339
  const children = owner.children;
322
340
  if (children.isMergeInProgress) {
323
341
  let promised = undefined;
@@ -349,7 +367,7 @@ function runUpdateNestedTreesThenDo(error, action) {
349
367
  partition = childNode;
350
368
  }
351
369
  if (!Transaction.isCanceled && (p1 !== undefined || p2 !== undefined))
352
- promised = startIncrementalUpdate(curr, children, p1, p2).then(() => action(error), e => action(e));
370
+ promised = startIncrementalUpdate(ownSeat, children, p1, p2).then(() => action(error), e => action(e));
353
371
  }
354
372
  }
355
373
  finally {
@@ -461,12 +479,12 @@ function updateNow(seat) {
461
479
  const driver = node.driver;
462
480
  result = driver.update(node);
463
481
  if (result instanceof Promise)
464
- result.then(v => { runUpdateNestedTreesThenDo(undefined, NOP); return v; }, e => { console.log(e); runUpdateNestedTreesThenDo(e !== null && e !== void 0 ? e : new Error('unknown error'), NOP); });
482
+ result.then(v => { runUpdateNestedNodesThenDo(undefined, NOP); return v; }, e => { console.log(e); runUpdateNestedNodesThenDo(e !== null && e !== void 0 ? e : new Error('unknown error'), NOP); });
465
483
  else
466
- runUpdateNestedTreesThenDo(undefined, NOP);
484
+ runUpdateNestedNodesThenDo(undefined, NOP);
467
485
  }
468
486
  catch (e) {
469
- runUpdateNestedTreesThenDo(e, NOP);
487
+ runUpdateNestedNodesThenDo(e, NOP);
470
488
  console.log(`Update failed: ${node.key}`);
471
489
  console.log(`${e}`);
472
490
  }
@@ -515,23 +533,23 @@ function runDisposalLoop() {
515
533
  }
516
534
  function wrapToRunInside(func) {
517
535
  let wrappedToRunInside;
518
- const current = gCurrent;
519
- if (current)
536
+ const outer = gOwnSeat;
537
+ if (outer)
520
538
  wrappedToRunInside = (...args) => {
521
- return runInside(current, func, ...args);
539
+ return runInside(outer, func, ...args);
522
540
  };
523
541
  else
524
542
  wrappedToRunInside = func;
525
543
  return wrappedToRunInside;
526
544
  }
527
545
  function runInside(seat, func, ...args) {
528
- const outer = gCurrent;
546
+ const outer = gOwnSeat;
529
547
  try {
530
- gCurrent = seat;
548
+ gOwnSeat = seat;
531
549
  return func(...args);
532
550
  }
533
551
  finally {
534
- gCurrent = outer;
552
+ gOwnSeat = outer;
535
553
  }
536
554
  }
537
555
  function triggersAreEqual(a1, a2) {
@@ -584,6 +602,6 @@ function defaultReject(error) {
584
602
  }
585
603
  Promise.prototype.then = reactronicDomHookedThen;
586
604
  const NOP = (...args) => { };
587
- let gCurrent = undefined;
605
+ let gOwnSeat = undefined;
588
606
  let gFirstToDispose = undefined;
589
607
  let gLastToDispose = undefined;
@@ -7,3 +7,6 @@ export declare class Utils {
7
7
  export declare function UNDEF(...args: any[]): never;
8
8
  export declare function all(promises: Array<Promise<any>>): Promise<any[]>;
9
9
  export declare function pause<T>(timeout: number): Promise<T>;
10
+ export declare function emitLetters(n: number): string;
11
+ export declare function objectHasMember<T>(obj: any, member: string): obj is T;
12
+ export declare function getCallerInfo(prefix: string): string;
@@ -53,3 +53,49 @@ export function pause(timeout) {
53
53
  setTimeout(resolve.bind(null, () => resolve), timeout);
54
54
  });
55
55
  }
56
+ export function emitLetters(n) {
57
+ if (n < 0)
58
+ throw new Error(`emitLetters: argument (${n}) should not be negative or zero`);
59
+ let result = '';
60
+ while (n >= 0) {
61
+ const r = n % 26;
62
+ n = Math.floor(n / 26) - 1;
63
+ result = String.fromCharCode(65 + r) + result;
64
+ }
65
+ return result;
66
+ }
67
+ export function objectHasMember(obj, member) {
68
+ return obj === Object(obj) && !Array.isArray(obj) && member in obj;
69
+ }
70
+ export function getCallerInfo(prefix) {
71
+ const restore = Error.stackTraceLimit = 20;
72
+ const error = new Error();
73
+ const stack = error.stack || '';
74
+ Error.stackTraceLimit = restore;
75
+ const lines = stack.split('\n');
76
+ let i = lines.findIndex(x => x.indexOf('.acquire') >= 0);
77
+ i = i >= 0 ? i + 2 : 5;
78
+ let caller = extractFunctionAndLocation(lines[i]);
79
+ let location = caller;
80
+ if (caller.func.endsWith('.update')) {
81
+ i = i - 1;
82
+ caller = extractFunctionAndLocation(lines[i]);
83
+ location = extractFunctionAndLocation(lines[i + 1]);
84
+ }
85
+ else {
86
+ while (!caller.func && i > 0) {
87
+ i = i - 1;
88
+ caller = extractFunctionAndLocation(lines[i]);
89
+ }
90
+ location = extractFunctionAndLocation(lines[i + 1]);
91
+ }
92
+ const result = `${prefix}·${caller.func}@${location.file}`;
93
+ return result;
94
+ }
95
+ function extractFunctionAndLocation(s) {
96
+ const match = s.match(/(?:\s*at\s+)?(?:(\S+)\s\()?(?:.*?)([^\/\(\):]+)(?:(:|\d)*\)?)$/);
97
+ return {
98
+ func: (match === null || match === void 0 ? void 0 : match[1]) || '',
99
+ file: (match === null || match === void 0 ? void 0 : match[2]) || '',
100
+ };
101
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.24.118",
3
+ "version": "0.24.120",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
5
  "publisher": "Nezaboodka Software",
6
6
  "license": "Apache-2.0",
@@ -1,3 +0,0 @@
1
- export declare function emitLetters(n: number): string;
2
- export declare function objectHasMember<T>(obj: any, member: string): obj is T;
3
- export declare function getCallerInfo(prefix: string): string;
@@ -1,46 +0,0 @@
1
- export function emitLetters(n) {
2
- if (n < 0)
3
- throw new Error(`emitLetters: argument (${n}) should not be negative or zero`);
4
- let result = '';
5
- while (n >= 0) {
6
- const r = n % 26;
7
- n = Math.floor(n / 26) - 1;
8
- result = String.fromCharCode(65 + r) + result;
9
- }
10
- return result;
11
- }
12
- export function objectHasMember(obj, member) {
13
- return obj === Object(obj) && !Array.isArray(obj) && member in obj;
14
- }
15
- export function getCallerInfo(prefix) {
16
- const restore = Error.stackTraceLimit = 20;
17
- const error = new Error();
18
- const stack = error.stack || '';
19
- Error.stackTraceLimit = restore;
20
- const lines = stack.split('\n');
21
- let i = lines.findIndex(x => x.indexOf('.acquire') >= 0);
22
- i = i >= 0 ? i + 2 : 5;
23
- let caller = extractFunctionAndLocation(lines[i]);
24
- let location = caller;
25
- if (caller.func.endsWith('.update')) {
26
- i = i - 1;
27
- caller = extractFunctionAndLocation(lines[i]);
28
- location = extractFunctionAndLocation(lines[i + 1]);
29
- }
30
- else {
31
- while (!caller.func && i > 0) {
32
- i = i - 1;
33
- caller = extractFunctionAndLocation(lines[i]);
34
- }
35
- location = extractFunctionAndLocation(lines[i + 1]);
36
- }
37
- const result = `${prefix}·${caller.func}@${location.file}`;
38
- return result;
39
- }
40
- function extractFunctionAndLocation(s) {
41
- const match = s.match(/(?:\s*at\s+)?(?:(\S+)\s\()?(?:.*?)([^\/\(\):]+)(?:(:|\d)*\)?)$/);
42
- return {
43
- func: (match === null || match === void 0 ? void 0 : match[1]) || '',
44
- file: (match === null || match === void 0 ? void 0 : match[2]) || '',
45
- };
46
- }