reactronic 0.24.107 → 0.24.111

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.
@@ -12,47 +12,49 @@ export declare const enum Priority {
12
12
  Normal = 1,
13
13
  Background = 2
14
14
  }
15
- export declare abstract class RxNode<T = any> {
16
- abstract readonly key: string;
17
- abstract readonly driver: RxNodeDriver<T>;
18
- abstract readonly declaration: Readonly<RxNodeDecl<T>>;
19
- abstract readonly level: number;
20
- abstract readonly owner: RxNode;
21
- abstract element: T;
22
- abstract readonly host: RxNode;
23
- abstract readonly children: MergeListReader<RxNode>;
24
- abstract readonly slot: MergedItem<RxNode<T>> | undefined;
25
- abstract readonly stamp: number;
26
- abstract readonly outer: RxNode;
27
- abstract readonly context: RxNodeContext | undefined;
28
- abstract readonly isInitialUpdate: boolean;
29
- abstract priority?: Priority;
30
- abstract childrenShuffling: boolean;
31
- abstract strictOrder: boolean;
32
- abstract has(mode: Mode): boolean;
33
- abstract configureReactronic(options: Partial<MemberOptions>): MemberOptions;
15
+ export interface RxElement {
16
+ node: RxNode<any>;
34
17
  }
35
- export interface RxNodeDecl<T = unknown> {
36
- preset?: RxNodeDecl<T>;
18
+ export interface RxNode<E extends RxElement = any> {
19
+ readonly key: string;
20
+ readonly driver: RxNodeDriver<E>;
21
+ readonly declaration: Readonly<RxNodeDecl<E>>;
22
+ readonly level: number;
23
+ readonly owner: RxNode;
24
+ element: E;
25
+ readonly host: RxNode;
26
+ readonly children: MergeListReader<RxNode>;
27
+ readonly seat: MergedItem<RxNode<E>> | undefined;
28
+ readonly stamp: number;
29
+ readonly outer: RxNode;
30
+ readonly context: RxNodeContext | undefined;
31
+ readonly isInitialUpdate: boolean;
32
+ priority?: Priority;
33
+ childrenShuffling: boolean;
34
+ strictOrder: boolean;
35
+ has(mode: Mode): boolean;
36
+ configureReactronic(options: Partial<MemberOptions>): MemberOptions;
37
+ }
38
+ export interface RxNodeDecl<E extends RxElement> {
39
+ preset?: RxNodeDecl<E>;
37
40
  key?: string;
38
41
  mode?: Mode;
39
42
  triggers?: unknown;
40
- specify?: Delegate<T>;
41
- create?: Delegate<T>;
42
- initialize?: Delegate<T>;
43
- update?: Delegate<T>;
44
- finalize?: Delegate<T>;
43
+ specify?: Delegate<E>;
44
+ create?: Delegate<E>;
45
+ initialize?: Delegate<E>;
46
+ update?: Delegate<E>;
47
+ finalize?: Delegate<E>;
45
48
  }
46
- export interface RxNodeDriver<T> {
49
+ export interface RxNodeDriver<E extends RxElement> {
47
50
  readonly name: string;
48
51
  readonly isPartitionSeparator: boolean;
49
- readonly predefine?: SimpleDelegate<T>;
50
- allocate(node: RxNode<T>): T;
51
- assign(element: T): void;
52
- initialize(element: T): void;
53
- mount(element: T): void;
54
- update(element: T): void | Promise<void>;
55
- finalize(element: T, isLeader: boolean): boolean;
52
+ readonly predefine?: SimpleDelegate<E>;
53
+ allocate(node: RxNode<E>): E;
54
+ initialize(element: E): void;
55
+ mount(element: E): void;
56
+ update(element: E): void | Promise<void>;
57
+ finalize(element: E, isLeader: boolean): boolean;
56
58
  }
57
59
  export interface RxNodeContext<T extends Object = Object> {
58
60
  value: T;
@@ -10,5 +10,3 @@ export var Priority;
10
10
  Priority[Priority["Normal"] = 1] = "Normal";
11
11
  Priority[Priority["Background"] = 2] = "Background";
12
12
  })(Priority || (Priority = {}));
13
- export class RxNode {
14
- }
@@ -1,34 +1,29 @@
1
1
  import { LoggingOptions } from './Logging.js';
2
- import { Priority, RxNodeDecl, RxNodeDriver, SimpleDelegate, RxNode } from './RxNode.js';
2
+ import { Priority, RxNodeDecl, RxNodeDriver, SimpleDelegate, RxNode, RxElement } from './RxNode.js';
3
3
  export declare class RxTree {
4
4
  static readonly shortFrameDuration = 16;
5
5
  static readonly longFrameDuration = 300;
6
6
  static currentUpdatePriority: Priority;
7
7
  static frameDuration: number;
8
- static declare<T = undefined>(driver: RxNodeDriver<T>, declaration?: RxNodeDecl<T>, preset?: RxNodeDecl<T>): T;
9
- static triggerUpdate(element: {
10
- node: RxNode;
11
- }, triggers: unknown): void;
8
+ static declare<E extends RxElement>(driver: RxNodeDriver<E>, declaration?: RxNodeDecl<E>, preset?: RxNodeDecl<E>): E;
9
+ static triggerUpdate(element: RxElement, triggers: unknown): void;
12
10
  static updateNestedTreesThenDo(action: (error: unknown) => void): void;
13
- static findMatchingHost<T, R>(node: RxNode<T>, match: SimpleDelegate<RxNode<T>, boolean>): RxNode<R> | undefined;
14
- static findMatchingPrevSibling<T, R>(node: RxNode<T>, match: SimpleDelegate<RxNode<T>, boolean>): RxNode<R> | undefined;
15
- static forEachChildRecursively<T>(node: RxNode<T>, action: SimpleDelegate<RxNode<T>>): void;
11
+ static findMatchingHost<E extends RxElement, R extends RxElement>(node: RxNode<E>, match: SimpleDelegate<RxNode<E>, boolean>): RxNode<R> | undefined;
12
+ static findMatchingPrevSibling<E extends RxElement, R extends RxElement>(node: RxNode<E>, match: SimpleDelegate<RxNode<E>, boolean>): RxNode<R> | undefined;
13
+ static forEachChildRecursively<E extends RxElement>(node: RxNode<E>, action: SimpleDelegate<RxNode<E>>): void;
16
14
  static getDefaultLoggingOptions(): LoggingOptions | undefined;
17
15
  static setDefaultLoggingOptions(logging?: LoggingOptions): void;
18
16
  }
19
- export declare abstract class BaseDriver<T extends {
20
- node: RxNode;
21
- }> implements RxNodeDriver<T> {
17
+ export declare abstract class BaseDriver<E extends RxElement> implements RxNodeDriver<E> {
22
18
  readonly name: string;
23
19
  readonly isPartitionSeparator: boolean;
24
- readonly predefine?: SimpleDelegate<T> | undefined;
25
- constructor(name: string, isPartitionSeparator: boolean, predefine?: SimpleDelegate<T> | undefined);
26
- abstract allocate(node: RxNode<T>): T;
27
- assign(element: T): void;
28
- initialize(element: T): void;
29
- mount(element: T): void;
30
- update(element: T): void | Promise<void>;
31
- finalize(element: T, isLeader: boolean): boolean;
20
+ readonly predefine?: SimpleDelegate<E> | undefined;
21
+ constructor(name: string, isPartitionSeparator: boolean, predefine?: SimpleDelegate<E> | undefined);
22
+ abstract allocate(node: RxNode<E>): E;
23
+ initialize(element: E): void;
24
+ mount(element: E): void;
25
+ update(element: E): void | Promise<void>;
26
+ finalize(element: E, isLeader: boolean): boolean;
32
27
  }
33
28
  export declare class RxNodeVariable<T extends Object = Object> {
34
29
  readonly defaultValue: T | undefined;
@@ -54,24 +54,24 @@ export class RxTree {
54
54
  }
55
55
  else {
56
56
  const node = new RxNodeImpl(key || generateKey(owner), driver, declaration, owner);
57
- node.slot = children.mergeAsAdded(node);
57
+ node.seat = children.mergeAsAdded(node);
58
58
  result = node.element;
59
59
  }
60
60
  }
61
61
  else {
62
62
  const node = new RxNodeImpl(key || '', driver, declaration, owner);
63
- node.slot = MergeList.createItem(node);
63
+ node.seat = MergeList.createItem(node);
64
64
  result = node.element;
65
- triggerUpdate(node.slot);
65
+ triggerUpdateGivenSeat(node.seat);
66
66
  }
67
67
  return result;
68
68
  }
69
69
  static triggerUpdate(element, triggers) {
70
- const el = element;
71
- const declaration = el.node.declaration;
70
+ const node = element.node;
71
+ const declaration = node.declaration;
72
72
  if (!triggersAreEqual(triggers, declaration.triggers)) {
73
73
  declaration.triggers = triggers;
74
- triggerUpdate(el.node.slot);
74
+ triggerUpdateGivenSeat(node.seat);
75
75
  }
76
76
  }
77
77
  static updateNestedTreesThenDo(action) {
@@ -84,7 +84,7 @@ export class RxTree {
84
84
  return p;
85
85
  }
86
86
  static findMatchingPrevSibling(node, match) {
87
- let p = node.slot.prev;
87
+ let p = node.seat.prev;
88
88
  while (p && !match(p.instance))
89
89
  p = p.prev;
90
90
  return p === null || p === void 0 ? void 0 : p.instance;
@@ -111,9 +111,6 @@ export class BaseDriver {
111
111
  this.isPartitionSeparator = isPartitionSeparator;
112
112
  this.predefine = predefine;
113
113
  }
114
- assign(element) {
115
- assignViaPresetChain(element, element.node.declaration);
116
- }
117
114
  initialize(element) {
118
115
  var _a;
119
116
  (_a = this.predefine) === null || _a === void 0 ? void 0 : _a.call(this, element);
@@ -157,14 +154,6 @@ function getModeViaPresetChain(declaration) {
157
154
  var _a;
158
155
  return (_a = declaration === null || declaration === void 0 ? void 0 : declaration.mode) !== null && _a !== void 0 ? _a : ((declaration === null || declaration === void 0 ? void 0 : declaration.preset) ? getModeViaPresetChain(declaration === null || declaration === void 0 ? void 0 : declaration.preset) : Mode.Default);
159
156
  }
160
- function assignViaPresetChain(element, declaration) {
161
- const preset = declaration.preset;
162
- const create = declaration.create;
163
- if (create)
164
- create(element, preset ? () => assignViaPresetChain(element, preset) : NOP);
165
- else if (preset)
166
- assignViaPresetChain(element, preset);
167
- }
168
157
  function initializeViaPresetChain(element, declaration) {
169
158
  const preset = declaration.preset;
170
159
  const initialize = declaration.initialize;
@@ -224,7 +213,7 @@ class RxNodeImpl {
224
213
  this.element = driver.allocate(this);
225
214
  this.host = this;
226
215
  this.children = new MergeList(getNodeKey, true);
227
- this.slot = undefined;
216
+ this.seat = undefined;
228
217
  this.stamp = Number.MAX_SAFE_INTEGER;
229
218
  this.context = undefined;
230
219
  this.numerator = 0;
@@ -237,12 +226,12 @@ class RxNodeImpl {
237
226
  get isInitialUpdate() { return this.stamp === 1; }
238
227
  get strictOrder() { return this.children.isStrict; }
239
228
  set strictOrder(value) { this.children.isStrict = value; }
240
- get isMoved() { return this.owner.children.isMoved(this.slot); }
229
+ get isMoved() { return this.owner.children.isMoved(this.seat); }
241
230
  has(mode) {
242
231
  return (getModeViaPresetChain(this.declaration) & mode) === mode;
243
232
  }
244
233
  update(_triggers) {
245
- updateNow(this.slot);
234
+ updateNow(this.seat);
246
235
  }
247
236
  configureReactronic(options) {
248
237
  if (this.stamp < Number.MAX_SAFE_INTEGER - 1 || !this.has(Mode.PinpointUpdate))
@@ -258,7 +247,7 @@ class RxNodeImpl {
258
247
  var _a, _b;
259
248
  let node = RxNodeImpl.current.instance;
260
249
  while (((_a = node.context) === null || _a === void 0 ? void 0 : _a.variable) !== variable && node.owner !== node)
261
- node = node.outer.slot.instance;
250
+ node = node.outer.seat.instance;
262
251
  return (_b = node.context) === null || _b === void 0 ? void 0 : _b.value;
263
252
  }
264
253
  static useNodeVariableValue(variable) {
@@ -319,8 +308,8 @@ function runUpdateNestedTreesThenDo(error, action) {
319
308
  let promised = undefined;
320
309
  try {
321
310
  children.endMerge(error);
322
- for (const slot of children.removedItems(true))
323
- triggerFinalization(slot, true, true);
311
+ for (const child of children.removedItems(true))
312
+ triggerFinalization(child, true, true);
324
313
  if (!error) {
325
314
  const sequential = children.isStrict;
326
315
  let p1 = undefined;
@@ -337,7 +326,7 @@ function runUpdateNestedTreesThenDo(error, action) {
337
326
  const p = (_a = el.node.priority) !== null && _a !== void 0 ? _a : Priority.Realtime;
338
327
  mounting = markToMountIfNecessary(mounting, host, child, children, sequential);
339
328
  if (p === Priority.Realtime)
340
- triggerUpdate(child);
329
+ triggerUpdateGivenSeat(child);
341
330
  else if (p === Priority.Normal)
342
331
  p1 = push(child, p1);
343
332
  else
@@ -355,27 +344,27 @@ function runUpdateNestedTreesThenDo(error, action) {
355
344
  }
356
345
  }
357
346
  }
358
- function markToMountIfNecessary(mounting, host, slot, children, sequential) {
359
- const node = slot.instance;
347
+ function markToMountIfNecessary(mounting, host, seat, children, sequential) {
348
+ const node = seat.instance;
360
349
  const el = node.element;
361
350
  if (el.native && !node.has(Mode.ManualMount)) {
362
351
  if (mounting || node.host !== host) {
363
- children.markAsMoved(slot);
352
+ children.markAsMoved(seat);
364
353
  mounting = false;
365
354
  }
366
355
  }
367
- else if (sequential && children.isMoved(slot))
356
+ else if (sequential && children.isMoved(seat))
368
357
  mounting = true;
369
358
  node.host = host;
370
359
  return mounting;
371
360
  }
372
- function startIncrementalUpdate(ownerSlot, allChildren, priority1, priority2) {
361
+ function startIncrementalUpdate(ownerSeat, allChildren, priority1, priority2) {
373
362
  return __awaiter(this, void 0, void 0, function* () {
374
- const stamp = ownerSlot.instance.stamp;
363
+ const stamp = ownerSeat.instance.stamp;
375
364
  if (priority1)
376
- yield updateIncrementally(ownerSlot, stamp, allChildren, priority1, Priority.Normal);
365
+ yield updateIncrementally(ownerSeat, stamp, allChildren, priority1, Priority.Normal);
377
366
  if (priority2)
378
- yield updateIncrementally(ownerSlot, stamp, allChildren, priority2, Priority.Background);
367
+ yield updateIncrementally(ownerSeat, stamp, allChildren, priority2, Priority.Background);
379
368
  });
380
369
  }
381
370
  function updateIncrementally(owner, stamp, allChildren, items, priority) {
@@ -391,7 +380,7 @@ function updateIncrementally(owner, stamp, allChildren, items, priority) {
391
380
  const frameDurationLimit = priority === Priority.Background ? RxTree.shortFrameDuration : Infinity;
392
381
  let frameDuration = Math.min(frameDurationLimit, Math.max(RxTree.frameDuration / 4, RxTree.shortFrameDuration));
393
382
  for (const child of items) {
394
- triggerUpdate(child);
383
+ triggerUpdateGivenSeat(child);
395
384
  if (Transaction.isFrameOver(1, frameDuration)) {
396
385
  RxTree.currentUpdatePriority = outerPriority;
397
386
  yield Transaction.requestNextFrame(0);
@@ -409,8 +398,8 @@ function updateIncrementally(owner, stamp, allChildren, items, priority) {
409
398
  }
410
399
  });
411
400
  }
412
- function triggerUpdate(slot) {
413
- const node = slot.instance;
401
+ function triggerUpdateGivenSeat(seat) {
402
+ const node = seat.instance;
414
403
  if (node.stamp >= 0) {
415
404
  if (node.has(Mode.PinpointUpdate)) {
416
405
  if (node.stamp === Number.MAX_SAFE_INTEGER) {
@@ -425,7 +414,7 @@ function triggerUpdate(slot) {
425
414
  unobs(node.update, node.declaration.triggers);
426
415
  }
427
416
  else
428
- updateNow(slot);
417
+ updateNow(seat);
429
418
  }
430
419
  }
431
420
  function mountOrRemountIfNecessary(node) {
@@ -434,7 +423,6 @@ function mountOrRemountIfNecessary(node) {
434
423
  if (node.stamp === Number.MAX_SAFE_INTEGER) {
435
424
  node.stamp = Number.MAX_SAFE_INTEGER - 1;
436
425
  unobs(() => {
437
- driver.assign(element);
438
426
  driver.initialize(element);
439
427
  if (!node.has(Mode.ManualMount)) {
440
428
  node.stamp = 0;
@@ -447,12 +435,12 @@ function mountOrRemountIfNecessary(node) {
447
435
  else if (node.isMoved && !node.has(Mode.ManualMount) && element.node.host !== element.node)
448
436
  unobs(() => driver.mount(element));
449
437
  }
450
- function updateNow(slot) {
451
- const node = slot.instance;
438
+ function updateNow(seat) {
439
+ const node = seat.instance;
452
440
  const el = node.element;
453
441
  if (node.stamp >= 0) {
454
442
  let result = undefined;
455
- runInside(slot, () => {
443
+ runInside(seat, () => {
456
444
  mountOrRemountIfNecessary(node);
457
445
  if (node.stamp < Number.MAX_SAFE_INTEGER - 1) {
458
446
  try {
@@ -475,8 +463,8 @@ function updateNow(slot) {
475
463
  });
476
464
  }
477
465
  }
478
- function triggerFinalization(slot, isLeader, individual) {
479
- const node = slot.instance;
466
+ function triggerFinalization(seat, isLeader, individual) {
467
+ const node = seat.instance;
480
468
  const el = node.element;
481
469
  if (node.stamp >= 0) {
482
470
  const driver = node.driver;
@@ -487,14 +475,14 @@ function triggerFinalization(slot, isLeader, individual) {
487
475
  el.native = null;
488
476
  el.controller = null;
489
477
  if (node.has(Mode.PinpointUpdate)) {
490
- slot.aux = undefined;
478
+ seat.aux = undefined;
491
479
  const last = gLastToDispose;
492
480
  if (last)
493
- gLastToDispose = last.aux = slot;
481
+ gLastToDispose = last.aux = seat;
494
482
  else
495
- gFirstToDispose = gLastToDispose = slot;
496
- if (gFirstToDispose === slot)
497
- Transaction.run({ separation: 'disposal', hint: `runDisposalLoop(initiator=${slot.instance.key})` }, () => {
483
+ gFirstToDispose = gLastToDispose = seat;
484
+ if (gFirstToDispose === seat)
485
+ Transaction.run({ separation: 'disposal', hint: `runDisposalLoop(initiator=${seat.instance.key})` }, () => {
498
486
  void runDisposalLoop().then(NOP, error => console.log(error));
499
487
  });
500
488
  }
@@ -506,12 +494,12 @@ function triggerFinalization(slot, isLeader, individual) {
506
494
  function runDisposalLoop() {
507
495
  return __awaiter(this, void 0, void 0, function* () {
508
496
  yield Transaction.requestNextFrame();
509
- let slot = gFirstToDispose;
510
- while (slot !== undefined) {
497
+ let seat = gFirstToDispose;
498
+ while (seat !== undefined) {
511
499
  if (Transaction.isFrameOver(500, 5))
512
500
  yield Transaction.requestNextFrame();
513
- RxSystem.dispose(slot.instance);
514
- slot = slot.aux;
501
+ RxSystem.dispose(seat.instance);
502
+ seat = seat.aux;
515
503
  RxNodeImpl.disposableNodeCount--;
516
504
  }
517
505
  gFirstToDispose = gLastToDispose = undefined;
@@ -528,10 +516,10 @@ function wrapToRunInside(func) {
528
516
  wrappedToRunInside = func;
529
517
  return wrappedToRunInside;
530
518
  }
531
- function runInside(slot, func, ...args) {
519
+ function runInside(seat, func, ...args) {
532
520
  const outer = gCurrent;
533
521
  try {
534
- gCurrent = slot;
522
+ gCurrent = seat;
535
523
  return func(...args);
536
524
  }
537
525
  finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.24.107",
3
+ "version": "0.24.111",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
5
  "publisher": "Nezaboodka Software",
6
6
  "license": "Apache-2.0",