reactronic 0.93.25025 → 0.94.25027

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.
Files changed (45) hide show
  1. package/README.md +41 -40
  2. package/build/dist/source/Enums.d.ts +32 -0
  3. package/build/dist/source/Enums.js +37 -0
  4. package/build/dist/source/OperationEx.d.ts +7 -0
  5. package/build/dist/source/{ReactiveLoop.js → OperationEx.js} +8 -8
  6. package/build/dist/source/Options.d.ts +7 -27
  7. package/build/dist/source/Options.js +0 -24
  8. package/build/dist/source/Pipe.d.ts +2 -2
  9. package/build/dist/source/Pipe.js +2 -2
  10. package/build/dist/source/Ref.d.ts +1 -1
  11. package/build/dist/source/Ref.js +4 -4
  12. package/build/dist/source/System.d.ts +29 -0
  13. package/build/dist/source/{ReactiveSystem.js → System.js} +24 -19
  14. package/build/dist/source/api.d.ts +12 -10
  15. package/build/dist/source/api.js +10 -8
  16. package/build/dist/source/core/Changeset.d.ts +8 -7
  17. package/build/dist/source/core/Changeset.js +18 -18
  18. package/build/dist/source/core/Data.d.ts +6 -6
  19. package/build/dist/source/core/Data.js +2 -2
  20. package/build/dist/source/core/Indicator.d.ts +2 -2
  21. package/build/dist/source/core/Indicator.js +3 -3
  22. package/build/dist/source/core/Journal.d.ts +2 -2
  23. package/build/dist/source/core/Journal.js +7 -7
  24. package/build/dist/source/core/Meta.d.ts +1 -1
  25. package/build/dist/source/core/Meta.js +1 -1
  26. package/build/dist/source/core/Mvcc.d.ts +17 -16
  27. package/build/dist/source/core/Mvcc.js +30 -30
  28. package/build/dist/source/core/MvccArray.d.ts +3 -3
  29. package/build/dist/source/core/MvccArray.js +4 -4
  30. package/build/dist/source/core/MvccMap.d.ts +3 -3
  31. package/build/dist/source/core/MvccMap.js +4 -4
  32. package/build/dist/source/core/MvccMergeList.d.ts +2 -2
  33. package/build/dist/source/core/MvccMergeList.js +2 -2
  34. package/build/dist/source/core/Operation.d.ts +25 -25
  35. package/build/dist/source/core/Operation.js +200 -200
  36. package/build/dist/source/core/Transaction.d.ts +3 -3
  37. package/build/dist/source/core/Transaction.js +72 -72
  38. package/build/dist/source/core/Tree.d.ts +26 -0
  39. package/build/dist/source/core/Tree.js +120 -0
  40. package/build/dist/source/core/TreeNode.d.ts +117 -0
  41. package/build/dist/source/core/{ReactiveNode.js → TreeNode.js} +57 -185
  42. package/package.json +1 -1
  43. package/build/dist/source/ReactiveLoop.d.ts +0 -7
  44. package/build/dist/source/ReactiveSystem.d.ts +0 -30
  45. package/build/dist/source/core/ReactiveNode.d.ts +0 -107
@@ -19,144 +19,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
19
  import { misuse } from "../util/Dbg.js";
20
20
  import { MergeList } from "../util/MergeList.js";
21
21
  import { emitLetters, getCallerInfo, proceedSyncOrAsync } from "../util/Utils.js";
22
- import { Isolation, Reentrance } from "../Options.js";
23
- import { TriggeringObject } from "../core/Mvcc.js";
22
+ import { Priority, Mode, Isolation, Reentrance } from "../Enums.js";
23
+ import { ObservableObject } from "../core/Mvcc.js";
24
24
  import { Transaction } from "../core/Transaction.js";
25
- import { ReactiveSystem, options, trigger, reaction, atomicRun, nonReactiveRun } from "../ReactiveSystem.js";
26
- export var Mode;
27
- (function (Mode) {
28
- Mode[Mode["default"] = 0] = "default";
29
- Mode[Mode["autonomous"] = 1] = "autonomous";
30
- Mode[Mode["manualMount"] = 2] = "manualMount";
31
- Mode[Mode["rootNode"] = 4] = "rootNode";
32
- })(Mode || (Mode = {}));
33
- export var Priority;
34
- (function (Priority) {
35
- Priority[Priority["realtime"] = 0] = "realtime";
36
- Priority[Priority["normal"] = 1] = "normal";
37
- Priority[Priority["background"] = 2] = "background";
38
- })(Priority || (Priority = {}));
39
- export class ReactiveNode {
40
- static declare(driver, scriptOrDeclaration, scriptAsync, key, mode, preparation, preparationAsync, finalization, triggers, basis) {
41
- let result;
42
- let declaration;
43
- if (scriptOrDeclaration instanceof Function) {
44
- declaration = {
45
- script: scriptOrDeclaration, scriptAsync, key, mode,
46
- preparation, preparationAsync, finalization, triggers, basis,
47
- };
48
- }
49
- else
50
- declaration = scriptOrDeclaration !== null && scriptOrDeclaration !== void 0 ? scriptOrDeclaration : {};
51
- let effectiveKey = declaration.key;
52
- const owner = (getModeUsingBasisChain(declaration) & Mode.rootNode) !== Mode.rootNode ? gNodeSlot === null || gNodeSlot === void 0 ? void 0 : gNodeSlot.instance : undefined;
53
- if (owner) {
54
- let existing = owner.driver.declareChild(owner, driver, declaration, declaration.basis);
55
- const children = owner.children;
56
- existing !== null && existing !== void 0 ? existing : (existing = children.tryMergeAsExisting(effectiveKey = effectiveKey || generateKey(owner), undefined, "nested elements can be declared inside 'script' only"));
57
- if (existing) {
58
- result = existing.instance;
59
- if (result.driver !== driver && driver !== undefined)
60
- throw new Error(`changing element driver is not yet supported: "${result.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
61
- const exTriggers = result.declaration.triggers;
62
- if (triggersAreEqual(declaration.triggers, exTriggers))
63
- declaration.triggers = exTriggers;
64
- result.declaration = declaration;
65
- }
66
- else {
67
- result = new ReactiveNodeImpl(effectiveKey || generateKey(owner), driver, declaration, owner);
68
- result.slot = children.mergeAsAdded(result);
69
- }
70
- }
71
- else {
72
- result = new ReactiveNodeImpl(effectiveKey || "", driver, declaration, owner);
73
- result.slot = MergeList.createItem(result);
74
- triggerScriptRunViaSlot(result.slot);
75
- }
76
- return result;
77
- }
78
- static withBasis(declaration, basis) {
79
- if (declaration)
80
- declaration.basis = basis;
81
- else
82
- declaration = basis !== null && basis !== void 0 ? basis : {};
83
- return declaration;
84
- }
85
- static get isFirstScriptRun() {
86
- return ReactiveNodeImpl.nodeSlot.instance.stamp === 1;
87
- }
88
- static get key() {
89
- return ReactiveNodeImpl.nodeSlot.instance.key;
90
- }
91
- static get stamp() {
92
- return ReactiveNodeImpl.nodeSlot.instance.stamp;
93
- }
94
- static get triggers() {
95
- return ReactiveNodeImpl.nodeSlot.instance.declaration.triggers;
96
- }
97
- static get priority() {
98
- return ReactiveNodeImpl.nodeSlot.instance.priority;
99
- }
100
- static set priority(value) {
101
- ReactiveNodeImpl.nodeSlot.instance.priority = value;
102
- }
103
- static get childrenShuffling() {
104
- return ReactiveNodeImpl.nodeSlot.instance.childrenShuffling;
105
- }
106
- static set childrenShuffling(value) {
107
- ReactiveNodeImpl.nodeSlot.instance.childrenShuffling = value;
108
- }
109
- static triggerScriptRun(node, triggers) {
110
- const impl = node;
111
- const declaration = impl.declaration;
112
- if (!triggersAreEqual(triggers, declaration.triggers)) {
113
- declaration.triggers = triggers;
114
- triggerScriptRunViaSlot(impl.slot);
115
- }
116
- }
117
- static triggerFinalization(node) {
118
- const impl = node;
119
- triggerFinalization(impl.slot, true, true);
120
- }
121
- static runNestedNodeScriptsThenDo(action) {
122
- runNestedNodeScriptsThenDoImpl(ReactiveNodeImpl.nodeSlot, undefined, action);
123
- }
124
- static markAsMounted(node, yes) {
125
- const n = node;
126
- if (n.stamp < 0)
127
- throw new Error("deactivated node cannot be mounted or unmounted");
128
- if (n.stamp >= Number.MAX_SAFE_INTEGER)
129
- throw new Error("node must be activated before mounting");
130
- n.stamp = yes ? 0 : Number.MAX_SAFE_INTEGER - 1;
131
- }
132
- static findMatchingHost(node, match) {
133
- let p = node.host;
134
- while (p !== p.host && !match(p))
135
- p = p.host;
136
- return p;
137
- }
138
- static findMatchingPrevSibling(node, match) {
139
- let p = node.slot.prev;
140
- while (p && !match(p.instance))
141
- p = p.prev;
142
- return p === null || p === void 0 ? void 0 : p.instance;
143
- }
144
- static forEachChildRecursively(node, action) {
145
- action(node);
146
- for (const child of node.children.items())
147
- ReactiveNode.forEachChildRecursively(child.instance, action);
148
- }
149
- static getDefaultLoggingOptions() {
150
- return ReactiveNodeImpl.logging;
151
- }
152
- static setDefaultLoggingOptions(logging) {
153
- ReactiveNodeImpl.logging = logging;
154
- }
25
+ import { ReactiveSystem, options, observable, reactive, runAtomically, runNonReactively, manageReactiveOperation, disposeObservableObject } from "../System.js";
26
+ export class ReactiveTreeNode {
155
27
  }
156
- ReactiveNode.shortFrameDuration = 16;
157
- ReactiveNode.longFrameDuration = 300;
158
- ReactiveNode.currentScriptPriority = Priority.realtime;
159
- ReactiveNode.frameDuration = ReactiveNode.longFrameDuration;
160
28
  export class BaseDriver {
161
29
  constructor(name, isPartition, initialize) {
162
30
  this.name = name;
@@ -184,21 +52,21 @@ export class BaseDriver {
184
52
  return node;
185
53
  }
186
54
  }
187
- export class ReactiveNodeVariable {
55
+ export class ReactiveTreeVariable {
188
56
  constructor(defaultValue) {
189
57
  this.defaultValue = defaultValue;
190
58
  }
191
59
  set value(value) {
192
- ReactiveNodeImpl.setNodeVariableValue(this, value);
60
+ ReactiveTreeNodeImpl.setNodeVariableValue(this, value);
193
61
  }
194
62
  get value() {
195
- return ReactiveNodeImpl.useNodeVariableValue(this);
63
+ return ReactiveTreeNodeImpl.useNodeVariableValue(this);
196
64
  }
197
65
  get valueOrUndefined() {
198
- return ReactiveNodeImpl.tryUseNodeVariableValue(this);
66
+ return ReactiveTreeNodeImpl.tryUseNodeVariableValue(this);
199
67
  }
200
68
  }
201
- function generateKey(owner) {
69
+ export function generateKey(owner) {
202
70
  const n = owner.numerator++;
203
71
  const lettered = emitLetters(n);
204
72
  let result;
@@ -250,7 +118,7 @@ function invokeFinalizationUsingBasisChain(element, declaration) {
250
118
  else if (basis)
251
119
  invokeFinalizationUsingBasisChain(element, basis);
252
120
  }
253
- class ReactiveNodeContextImpl extends TriggeringObject {
121
+ class ReactiveTreeNodeContextImpl extends ObservableObject {
254
122
  constructor(variable, value) {
255
123
  super();
256
124
  this.next = undefined;
@@ -259,14 +127,14 @@ class ReactiveNodeContextImpl extends TriggeringObject {
259
127
  }
260
128
  }
261
129
  __decorate([
262
- trigger(false),
130
+ observable(false),
263
131
  __metadata("design:type", Object)
264
- ], ReactiveNodeContextImpl.prototype, "next", void 0);
132
+ ], ReactiveTreeNodeContextImpl.prototype, "next", void 0);
265
133
  __decorate([
266
- trigger(false),
267
- __metadata("design:type", ReactiveNodeVariable)
268
- ], ReactiveNodeContextImpl.prototype, "variable", void 0);
269
- class ReactiveNodeImpl extends ReactiveNode {
134
+ observable(false),
135
+ __metadata("design:type", ReactiveTreeVariable)
136
+ ], ReactiveTreeNodeContextImpl.prototype, "variable", void 0);
137
+ class ReactiveTreeNodeImpl extends ReactiveTreeNode {
270
138
  constructor(key, driver, declaration, owner) {
271
139
  super();
272
140
  const thisAsUnknown = this;
@@ -293,9 +161,9 @@ class ReactiveNodeImpl extends ReactiveNode {
293
161
  this.numerator = 0;
294
162
  this.priority = Priority.realtime;
295
163
  this.childrenShuffling = false;
296
- ReactiveNodeImpl.grandNodeCount++;
164
+ ReactiveTreeNodeImpl.grandNodeCount++;
297
165
  if (this.has(Mode.autonomous))
298
- ReactiveNodeImpl.disposableNodeCount++;
166
+ ReactiveTreeNodeImpl.disposableNodeCount++;
299
167
  }
300
168
  get strictOrder() { return this.children.isStrict; }
301
169
  set strictOrder(value) { this.children.isStrict = value; }
@@ -309,7 +177,7 @@ class ReactiveNodeImpl extends ReactiveNode {
309
177
  configureReactronic(options) {
310
178
  if (this.stamp < Number.MAX_SAFE_INTEGER - 1 || !this.has(Mode.autonomous))
311
179
  throw new Error("reactronic can be configured only for elements with autonomous mode and only during activation");
312
- return ReactiveSystem.getOperation(this.script).configure(options);
180
+ return manageReactiveOperation(this.script).configure(options);
313
181
  }
314
182
  static get nodeSlot() {
315
183
  if (!gNodeSlot)
@@ -318,35 +186,35 @@ class ReactiveNodeImpl extends ReactiveNode {
318
186
  }
319
187
  static tryUseNodeVariableValue(variable) {
320
188
  var _a, _b;
321
- let node = ReactiveNodeImpl.nodeSlot.instance;
189
+ let node = ReactiveTreeNodeImpl.nodeSlot.instance;
322
190
  while (((_a = node.context) === null || _a === void 0 ? void 0 : _a.variable) !== variable && node.owner !== node)
323
191
  node = node.outer.slot.instance;
324
192
  return (_b = node.context) === null || _b === void 0 ? void 0 : _b.value;
325
193
  }
326
194
  static useNodeVariableValue(variable) {
327
195
  var _a;
328
- const result = (_a = ReactiveNodeImpl.tryUseNodeVariableValue(variable)) !== null && _a !== void 0 ? _a : variable.defaultValue;
196
+ const result = (_a = ReactiveTreeNodeImpl.tryUseNodeVariableValue(variable)) !== null && _a !== void 0 ? _a : variable.defaultValue;
329
197
  if (!result)
330
198
  throw new Error("unknown node variable");
331
199
  return result;
332
200
  }
333
201
  static setNodeVariableValue(variable, value) {
334
- const node = ReactiveNodeImpl.nodeSlot.instance;
202
+ const node = ReactiveTreeNodeImpl.nodeSlot.instance;
335
203
  const owner = node.owner;
336
- const hostCtx = nonReactiveRun(() => { var _a; return (_a = owner.context) === null || _a === void 0 ? void 0 : _a.value; });
204
+ const hostCtx = runNonReactively(() => { var _a; return (_a = owner.context) === null || _a === void 0 ? void 0 : _a.value; });
337
205
  if (value && value !== hostCtx) {
338
206
  if (hostCtx)
339
207
  node.outer = owner;
340
208
  else
341
209
  node.outer = owner.outer;
342
- atomicRun({ isolation: Isolation.joinAsNestedTransaction }, () => {
210
+ runAtomically({ isolation: Isolation.joinAsNestedTransaction }, () => {
343
211
  const ctx = node.context;
344
212
  if (ctx) {
345
213
  ctx.variable = variable;
346
214
  ctx.value = value;
347
215
  }
348
216
  else
349
- node.context = new ReactiveNodeContextImpl(variable, value);
217
+ node.context = new ReactiveTreeNodeContextImpl(variable, value);
350
218
  });
351
219
  }
352
220
  else if (hostCtx)
@@ -355,21 +223,25 @@ class ReactiveNodeImpl extends ReactiveNode {
355
223
  node.outer = owner.outer;
356
224
  }
357
225
  }
358
- ReactiveNodeImpl.logging = undefined;
359
- ReactiveNodeImpl.grandNodeCount = 0;
360
- ReactiveNodeImpl.disposableNodeCount = 0;
226
+ ReactiveTreeNodeImpl.logging = undefined;
227
+ ReactiveTreeNodeImpl.grandNodeCount = 0;
228
+ ReactiveTreeNodeImpl.disposableNodeCount = 0;
229
+ ReactiveTreeNodeImpl.shortFrameDuration = 16;
230
+ ReactiveTreeNodeImpl.longFrameDuration = 300;
231
+ ReactiveTreeNodeImpl.currentScriptPriority = Priority.realtime;
232
+ ReactiveTreeNodeImpl.frameDuration = ReactiveTreeNodeImpl.longFrameDuration;
361
233
  __decorate([
362
- reaction,
234
+ reactive,
363
235
  options({
364
236
  reentrance: Reentrance.cancelAndWaitPrevious,
365
237
  allowObsoleteToFinish: true,
366
- triggeringArgs: true,
238
+ observableArgs: true,
367
239
  noSideEffects: false,
368
240
  }),
369
241
  __metadata("design:type", Function),
370
242
  __metadata("design:paramtypes", [Object]),
371
243
  __metadata("design:returntype", void 0)
372
- ], ReactiveNodeImpl.prototype, "script", null);
244
+ ], ReactiveTreeNodeImpl.prototype, "script", null);
373
245
  function getNodeKey(node) {
374
246
  return node.stamp >= 0 ? node.key : undefined;
375
247
  }
@@ -444,29 +316,29 @@ function runNestedScriptsIncrementally(owner, stamp, allChildren, items, priorit
444
316
  return __awaiter(this, void 0, void 0, function* () {
445
317
  yield Transaction.requestNextFrame();
446
318
  const node = owner.instance;
447
- if (!Transaction.isCanceled || !Transaction.isFrameOver(1, ReactiveNode.shortFrameDuration / 3)) {
448
- let outerPriority = ReactiveNode.currentScriptPriority;
449
- ReactiveNode.currentScriptPriority = priority;
319
+ if (!Transaction.isCanceled || !Transaction.isFrameOver(1, ReactiveTreeNodeImpl.shortFrameDuration / 3)) {
320
+ let outerPriority = ReactiveTreeNodeImpl.currentScriptPriority;
321
+ ReactiveTreeNodeImpl.currentScriptPriority = priority;
450
322
  try {
451
323
  if (node.childrenShuffling)
452
324
  shuffle(items);
453
- const frameDurationLimit = priority === Priority.background ? ReactiveNode.shortFrameDuration : Infinity;
454
- let frameDuration = Math.min(frameDurationLimit, Math.max(ReactiveNode.frameDuration / 4, ReactiveNode.shortFrameDuration));
325
+ const frameDurationLimit = priority === Priority.background ? ReactiveTreeNodeImpl.shortFrameDuration : Infinity;
326
+ let frameDuration = Math.min(frameDurationLimit, Math.max(ReactiveTreeNodeImpl.frameDuration / 4, ReactiveTreeNodeImpl.shortFrameDuration));
455
327
  for (const child of items) {
456
328
  triggerScriptRunViaSlot(child);
457
329
  if (Transaction.isFrameOver(1, frameDuration)) {
458
- ReactiveNode.currentScriptPriority = outerPriority;
330
+ ReactiveTreeNodeImpl.currentScriptPriority = outerPriority;
459
331
  yield Transaction.requestNextFrame(0);
460
- outerPriority = ReactiveNode.currentScriptPriority;
461
- ReactiveNode.currentScriptPriority = priority;
462
- frameDuration = Math.min(4 * frameDuration, Math.min(frameDurationLimit, ReactiveNode.frameDuration));
332
+ outerPriority = ReactiveTreeNodeImpl.currentScriptPriority;
333
+ ReactiveTreeNodeImpl.currentScriptPriority = priority;
334
+ frameDuration = Math.min(4 * frameDuration, Math.min(frameDurationLimit, ReactiveTreeNodeImpl.frameDuration));
463
335
  }
464
- if (Transaction.isCanceled && Transaction.isFrameOver(1, ReactiveNode.shortFrameDuration / 3))
336
+ if (Transaction.isCanceled && Transaction.isFrameOver(1, ReactiveTreeNodeImpl.shortFrameDuration / 3))
465
337
  break;
466
338
  }
467
339
  }
468
340
  finally {
469
- ReactiveNode.currentScriptPriority = outerPriority;
341
+ ReactiveTreeNodeImpl.currentScriptPriority = outerPriority;
470
342
  }
471
343
  }
472
344
  });
@@ -479,23 +351,23 @@ function triggerScriptRunViaSlot(nodeSlot) {
479
351
  Transaction.outside(() => {
480
352
  if (ReactiveSystem.isLogging)
481
353
  ReactiveSystem.setLoggingHint(node.element, node.key);
482
- ReactiveSystem.getOperation(node.script).configure({
354
+ manageReactiveOperation(node.script).configure({
483
355
  order: node.level,
484
356
  });
485
357
  });
486
358
  }
487
- nonReactiveRun(node.script, node.declaration.triggers);
359
+ runNonReactively(node.script, node.declaration.triggers);
488
360
  }
489
361
  else if (node.owner !== node)
490
362
  runScriptNow(nodeSlot);
491
363
  else
492
- atomicRun(() => runScriptNow(nodeSlot));
364
+ runAtomically(() => runScriptNow(nodeSlot));
493
365
  }
494
366
  }
495
367
  function mountOrRemountIfNecessary(node) {
496
368
  const driver = node.driver;
497
369
  if (node.stamp === Number.MAX_SAFE_INTEGER) {
498
- nonReactiveRun(() => {
370
+ runNonReactively(() => {
499
371
  node.stamp = Number.MAX_SAFE_INTEGER - 1;
500
372
  driver.runPreparation(node);
501
373
  if (!node.has(Mode.manualMount)) {
@@ -506,7 +378,7 @@ function mountOrRemountIfNecessary(node) {
506
378
  });
507
379
  }
508
380
  else if (node.isMoved && !node.has(Mode.manualMount) && node.host !== node)
509
- nonReactiveRun(() => driver.runMount(node));
381
+ runNonReactively(() => driver.runMount(node));
510
382
  }
511
383
  function runScriptNow(nodeSlot) {
512
384
  const node = nodeSlot.instance;
@@ -539,7 +411,7 @@ function triggerFinalization(nodeSlot, isLeader, individual) {
539
411
  if (individual && node.key !== node.declaration.key && !driver.isPartition)
540
412
  console.log(`WARNING: it is recommended to assign explicit key for conditional element in order to avoid unexpected side effects: ${node.key}`);
541
413
  node.stamp = ~node.stamp;
542
- const childrenAreLeaders = nonReactiveRun(() => driver.runFinalization(node, isLeader));
414
+ const childrenAreLeaders = runNonReactively(() => driver.runFinalization(node, isLeader));
543
415
  if (node.has(Mode.autonomous)) {
544
416
  nodeSlot.aux = undefined;
545
417
  const last = gLastToDispose;
@@ -548,13 +420,13 @@ function triggerFinalization(nodeSlot, isLeader, individual) {
548
420
  else
549
421
  gFirstToDispose = gLastToDispose = nodeSlot;
550
422
  if (gFirstToDispose === nodeSlot)
551
- atomicRun({ isolation: Isolation.disjoinForInternalDisposal, hint: `runDisposalLoop(initiator=${nodeSlot.instance.key})` }, () => {
423
+ runAtomically({ isolation: Isolation.disjoinForInternalDisposal, hint: `runDisposalLoop(initiator=${nodeSlot.instance.key})` }, () => {
552
424
  void runDisposalLoop().then(NOP, error => console.log(error));
553
425
  });
554
426
  }
555
427
  for (const child of node.children.items())
556
428
  triggerFinalization(child, childrenAreLeaders, false);
557
- ReactiveNodeImpl.grandNodeCount--;
429
+ ReactiveTreeNodeImpl.grandNodeCount--;
558
430
  }
559
431
  }
560
432
  function runDisposalLoop() {
@@ -564,9 +436,9 @@ function runDisposalLoop() {
564
436
  while (slot !== undefined) {
565
437
  if (Transaction.isFrameOver(500, 5))
566
438
  yield Transaction.requestNextFrame();
567
- ReactiveSystem.dispose(slot.instance);
439
+ disposeObservableObject(slot.instance);
568
440
  slot = slot.aux;
569
- ReactiveNodeImpl.disposableNodeCount--;
441
+ ReactiveTreeNodeImpl.disposableNodeCount--;
570
442
  }
571
443
  gFirstToDispose = gLastToDispose = undefined;
572
444
  });
@@ -592,7 +464,7 @@ function runInsideContextOfNode(nodeSlot, func, ...args) {
592
464
  gNodeSlot = outer;
593
465
  }
594
466
  }
595
- function triggersAreEqual(a1, a2) {
467
+ export function observablesAreEqual(a1, a2) {
596
468
  let result = a1 === a2;
597
469
  if (!result) {
598
470
  if (Array.isArray(a1)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.93.25025",
3
+ "version": "0.94.25027",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
5
  "publisher": "Nezaboodka Software",
6
6
  "license": "Apache-2.0",
@@ -1,7 +0,0 @@
1
- import { F } from "./util/Utils.js";
2
- import { TriggeringObject } from "./core/Mvcc.js";
3
- export declare class ReactiveLoop<T> extends TriggeringObject {
4
- protected reactiveFunction: F<T>;
5
- constructor(reactiveFunction: F<T>);
6
- protected launch(): T;
7
- }
@@ -1,30 +0,0 @@
1
- import { F } from "./util/Utils.js";
2
- import { Operation, MemberOptions, LoggingOptions, ProfilingOptions, SnapshotOptions } from "./Options.js";
3
- export declare class ReactiveSystem {
4
- static why(brief?: boolean): string;
5
- static getOperation<T>(method: F<T>): Operation<T>;
6
- static pullLastResult<T>(method: F<Promise<T>>, args?: any[]): T | undefined;
7
- static configureCurrentOperation(options: Partial<MemberOptions>): MemberOptions;
8
- static getRevisionOf(obj: any): number;
9
- static takeSnapshot<T>(obj: T): T;
10
- static dispose(obj: any): void;
11
- static get reactivityAutoStartDisabled(): boolean;
12
- static set reactivityAutoStartDisabled(value: boolean);
13
- static get isLogging(): boolean;
14
- static get loggingOptions(): LoggingOptions;
15
- static setLoggingMode(isOn: boolean, options?: LoggingOptions): void;
16
- static setLoggingHint<T extends object>(obj: T, name: string | undefined): void;
17
- static getLoggingHint<T extends object>(obj: T, full?: boolean): string | undefined;
18
- static setProfilingMode(isOn: boolean, options?: Partial<ProfilingOptions>): void;
19
- }
20
- export declare function atomicRun<T>(func: F<T>, ...args: any[]): T;
21
- export declare function atomicRun<T>(options: SnapshotOptions, func: F<T>, ...args: any[]): T;
22
- export declare function nonReactiveRun<T>(func: F<T>, ...args: any[]): T;
23
- export declare function sensitiveRun<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
24
- export declare function contextualRun<T>(p: Promise<T>): Promise<T>;
25
- export declare function trigger(enabled: boolean): (proto: object, prop: PropertyKey) => any;
26
- export declare function trigger<T>(proto: object, prop: PropertyKey): any;
27
- export declare function atomicBlock(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
28
- export declare function reaction(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
29
- export declare function cache(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
30
- export declare function options(value: Partial<MemberOptions>): F<any>;
@@ -1,107 +0,0 @@
1
- import { LoggingOptions } from "../Logging.js";
2
- import { MergeListReader, MergedItem } from "../util/MergeList.js";
3
- import { MemberOptions } from "../Options.js";
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
- export declare enum Mode {
8
- default = 0,
9
- autonomous = 1,
10
- manualMount = 2,
11
- rootNode = 4
12
- }
13
- export declare enum Priority {
14
- realtime = 0,
15
- normal = 1,
16
- background = 2
17
- }
18
- export declare abstract class ReactiveNode<E = unknown> {
19
- abstract readonly key: string;
20
- abstract readonly driver: ReactiveNodeDriver<E>;
21
- abstract readonly declaration: Readonly<ReactiveNodeDecl<E>>;
22
- abstract readonly level: number;
23
- abstract readonly owner: ReactiveNode;
24
- abstract element: E;
25
- abstract readonly host: ReactiveNode;
26
- abstract readonly children: MergeListReader<ReactiveNode>;
27
- abstract readonly slot: MergedItem<ReactiveNode<E>> | undefined;
28
- abstract readonly stamp: number;
29
- abstract readonly outer: ReactiveNode;
30
- abstract readonly context: ReactiveNodeContext | undefined;
31
- abstract priority?: Priority;
32
- abstract childrenShuffling: boolean;
33
- abstract strictOrder: boolean;
34
- abstract has(mode: Mode): boolean;
35
- abstract configureReactronic(options: Partial<MemberOptions>): MemberOptions;
36
- static readonly shortFrameDuration = 16;
37
- static readonly longFrameDuration = 300;
38
- static currentScriptPriority: Priority;
39
- static frameDuration: number;
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>;
41
- static declare<E = void>(driver: ReactiveNodeDriver<E>, declaration?: 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>;
43
- static withBasis<E = void>(declaration?: ReactiveNodeDecl<E>, basis?: ReactiveNodeDecl<E>): ReactiveNodeDecl<E>;
44
- static get isFirstScriptRun(): boolean;
45
- static get key(): string;
46
- static get stamp(): number;
47
- static get triggers(): unknown;
48
- static get priority(): Priority;
49
- static set priority(value: Priority);
50
- static get childrenShuffling(): boolean;
51
- static set childrenShuffling(value: boolean);
52
- static triggerScriptRun(node: ReactiveNode<any>, triggers: unknown): void;
53
- static triggerFinalization(node: ReactiveNode<any>): void;
54
- static runNestedNodeScriptsThenDo(action: (error: unknown) => void): void;
55
- static markAsMounted(node: ReactiveNode<any>, yes: boolean): void;
56
- static findMatchingHost<E = unknown, R = unknown>(node: ReactiveNode<E>, match: Handler<ReactiveNode<E>, boolean>): ReactiveNode<R> | undefined;
57
- static findMatchingPrevSibling<E = unknown, R = unknown>(node: ReactiveNode<E>, match: Handler<ReactiveNode<E>, boolean>): ReactiveNode<R> | undefined;
58
- static forEachChildRecursively<E = unknown>(node: ReactiveNode<E>, action: Handler<ReactiveNode<E>>): void;
59
- static getDefaultLoggingOptions(): LoggingOptions | undefined;
60
- static setDefaultLoggingOptions(logging?: LoggingOptions): void;
61
- }
62
- export type ReactiveNodeDecl<E = unknown> = {
63
- script?: Script<E>;
64
- scriptAsync?: ScriptAsync<E>;
65
- key?: string;
66
- mode?: Mode;
67
- preparation?: Script<E>;
68
- preparationAsync?: ScriptAsync<E>;
69
- finalization?: Script<E>;
70
- triggers?: unknown;
71
- basis?: ReactiveNodeDecl<E>;
72
- };
73
- export type ReactiveNodeDriver<E = unknown> = {
74
- readonly name: string;
75
- readonly isPartition: boolean;
76
- readonly initialize?: Handler<E>;
77
- create(node: ReactiveNode<E>): E;
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;
83
- provideHost(node: ReactiveNode<E>): ReactiveNode<E>;
84
- };
85
- export type ReactiveNodeContext<T extends Object = Object> = {
86
- value: T;
87
- };
88
- export declare abstract class BaseDriver<E = unknown> implements ReactiveNodeDriver<E> {
89
- readonly name: string;
90
- readonly isPartition: boolean;
91
- readonly initialize?: Handler<E> | undefined;
92
- constructor(name: string, isPartition: boolean, initialize?: Handler<E> | undefined);
93
- abstract create(node: ReactiveNode<E>): E;
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;
99
- provideHost(node: ReactiveNode<E>): ReactiveNode<E>;
100
- }
101
- export declare class ReactiveNodeVariable<T extends Object = Object> {
102
- readonly defaultValue: T | undefined;
103
- constructor(defaultValue?: T);
104
- set value(value: T);
105
- get value(): T;
106
- get valueOrUndefined(): T | undefined;
107
- }