@ersbeth/picoflow 2.0.0 → 2.0.1

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 (82) hide show
  1. package/dist/picoflow.js +322 -314
  2. package/dist/types/api/base/flowSubscribable.d.ts +1 -1
  3. package/dist/types/api/base/flowSubscribable.d.ts.map +1 -1
  4. package/dist/types/api/nodes/async/flowDerivationAsync.d.ts +1 -1
  5. package/dist/types/api/nodes/async/flowDerivationAsync.d.ts.map +1 -1
  6. package/dist/types/api/nodes/flowEffect.d.ts +2 -1
  7. package/dist/types/api/nodes/flowEffect.d.ts.map +1 -1
  8. package/dist/types/api/nodes/flowSignal.d.ts +1 -1
  9. package/dist/types/api/nodes/flowSignal.d.ts.map +1 -1
  10. package/dist/types/api/nodes/flowValue.d.ts +2 -1
  11. package/dist/types/api/nodes/flowValue.d.ts.map +1 -1
  12. package/dist/types/api/nodes/sync/flowDerivation.d.ts +1 -1
  13. package/dist/types/api/nodes/sync/flowDerivation.d.ts.map +1 -1
  14. package/dist/types/api/nodes/utils.d.ts +2 -1
  15. package/dist/types/api/nodes/utils.d.ts.map +1 -1
  16. package/dist/types/base/disposable.d.ts +1 -1
  17. package/dist/types/base/disposable.d.ts.map +1 -1
  18. package/dist/types/base/node.d.ts +1 -1
  19. package/dist/types/base/node.d.ts.map +1 -1
  20. package/dist/types/base/observable.d.ts +1 -3
  21. package/dist/types/base/observable.d.ts.map +1 -1
  22. package/dist/types/converters/solid.d.ts +1 -1
  23. package/dist/types/converters/solid.d.ts.map +1 -1
  24. package/dist/types/nodes/arrayNode.d.ts +24 -1
  25. package/dist/types/nodes/arrayNode.d.ts.map +1 -1
  26. package/dist/types/nodes/effectNode.d.ts +15 -1
  27. package/dist/types/nodes/effectNode.d.ts.map +1 -1
  28. package/dist/types/nodes/index.d.ts +0 -1
  29. package/dist/types/nodes/index.d.ts.map +1 -1
  30. package/dist/types/nodes/mapNode.d.ts +18 -1
  31. package/dist/types/nodes/mapNode.d.ts.map +1 -1
  32. package/dist/types/nodes/signalNode.d.ts +9 -1
  33. package/dist/types/nodes/signalNode.d.ts.map +1 -1
  34. package/dist/types/nodes/valueAsyncNode.d.ts +22 -1
  35. package/dist/types/nodes/valueAsyncNode.d.ts.map +1 -1
  36. package/dist/types/nodes/valueNode.d.ts +19 -1
  37. package/dist/types/nodes/valueNode.d.ts.map +1 -1
  38. package/dist/types/nodes/valueSyncNode.d.ts +22 -1
  39. package/dist/types/nodes/valueSyncNode.d.ts.map +1 -1
  40. package/dist/types/schedulers/asyncResolver.d.ts +18 -1
  41. package/dist/types/schedulers/asyncResolver.d.ts.map +1 -1
  42. package/dist/types/schedulers/asyncScheduler.d.ts +19 -1
  43. package/dist/types/schedulers/asyncScheduler.d.ts.map +1 -1
  44. package/dist/types/schedulers/pendingError.d.ts +8 -1
  45. package/dist/types/schedulers/pendingError.d.ts.map +1 -1
  46. package/dist/types/schedulers/scheduler.d.ts +9 -1
  47. package/dist/types/schedulers/scheduler.d.ts.map +1 -1
  48. package/dist/types/schedulers/syncResolver.d.ts +18 -1
  49. package/dist/types/schedulers/syncResolver.d.ts.map +1 -1
  50. package/dist/types/schedulers/syncScheduler.d.ts +18 -1
  51. package/dist/types/schedulers/syncScheduler.d.ts.map +1 -1
  52. package/docs/api/typedoc-sidebar.json +65 -1
  53. package/package.json +1 -1
  54. package/src/api/base/flowSubscribable.ts +1 -1
  55. package/src/api/nodes/async/flowConstantAsync.ts +1 -1
  56. package/src/api/nodes/async/flowDerivationAsync.ts +2 -2
  57. package/src/api/nodes/async/flowStateAsync.ts +1 -1
  58. package/src/api/nodes/async/flowWritableDerivationAsync.ts +1 -1
  59. package/src/api/nodes/collections/flowArray.ts +1 -1
  60. package/src/api/nodes/collections/flowMap.ts +1 -1
  61. package/src/api/nodes/flowEffect.ts +3 -3
  62. package/src/api/nodes/flowSignal.ts +2 -2
  63. package/src/api/nodes/flowValue.ts +2 -1
  64. package/src/api/nodes/sync/flowConstant.ts +1 -1
  65. package/src/api/nodes/sync/flowDerivation.ts +2 -2
  66. package/src/api/nodes/sync/flowState.ts +1 -1
  67. package/src/api/nodes/sync/flowWritableDerivation.ts +1 -1
  68. package/src/api/nodes/utils.ts +3 -1
  69. package/src/base/disposable.ts +1 -1
  70. package/src/base/node.ts +1 -1
  71. package/src/base/observable.ts +8 -3
  72. package/src/converters/solid.ts +2 -2
  73. package/src/nodes/arrayNode.ts +12 -4
  74. package/src/nodes/effectNode.ts +4 -5
  75. package/src/nodes/index.ts +0 -1
  76. package/src/nodes/mapNode.ts +2 -4
  77. package/src/nodes/signalNode.ts +2 -4
  78. package/src/nodes/valueAsyncNode.ts +2 -5
  79. package/src/nodes/valueNode.ts +10 -6
  80. package/src/nodes/valueSyncNode.ts +2 -5
  81. package/test/base/pendingError.test.ts +1 -1
  82. package/tsconfig.json +1 -1
package/dist/picoflow.js CHANGED
@@ -4,192 +4,6 @@ function isDisposable(obj) {
4
4
  return obj !== null && obj !== void 0 && typeof obj.dispose === "function";
5
5
  }
6
6
 
7
- class ExecutionStack {
8
- static _pendingQueue = [];
9
- static _effectQueue = [];
10
- static _executionScheduled;
11
- static pushPending(node) {
12
- ExecutionStack._scheduleExecution();
13
- ExecutionStack._pendingQueue.push(node);
14
- }
15
- static pushEffect(effect) {
16
- ExecutionStack._scheduleExecution();
17
- ExecutionStack._effectQueue.push(effect);
18
- }
19
- static _scheduleExecution() {
20
- if (ExecutionStack._executionScheduled) return;
21
- ExecutionStack._executionScheduled = new Promise((resolve) => {
22
- setTimeout(() => {
23
- ExecutionStack._executionScheduled = void 0;
24
- ExecutionStack._execute();
25
- resolve();
26
- }, 0);
27
- });
28
- }
29
- static _execute() {
30
- ExecutionStack._pendingQueue.forEach((node) => {
31
- node.execute();
32
- });
33
- ExecutionStack._pendingQueue.length = 0;
34
- ExecutionStack._effectQueue.forEach((effect) => {
35
- effect.execute();
36
- });
37
- ExecutionStack._effectQueue.length = 0;
38
- }
39
- }
40
-
41
- class Disposable {
42
- _disposed = false;
43
- get disposed() {
44
- return this._disposed;
45
- }
46
- dispose() {
47
- if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
48
- this._disposed = true;
49
- }
50
- }
51
-
52
- class Node extends Disposable {
53
- _dependencies = /* @__PURE__ */ new Set();
54
- _dependents = /* @__PURE__ */ new Set();
55
- _status = "resolved";
56
- get status() {
57
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
58
- return this._status;
59
- }
60
- set status(status) {
61
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
62
- this._status = status;
63
- }
64
- registerDependency(dependency) {
65
- if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
66
- this._dependencies.add(dependency);
67
- dependency.registerDependent(this);
68
- }
69
- unregisterDependency(dependency) {
70
- if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
71
- this._dependencies.delete(dependency);
72
- dependency.unregisterDependent(this);
73
- }
74
- clearDependencies() {
75
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
76
- this._dependencies.forEach((dependency) => {
77
- dependency.unregisterDependent(this);
78
- });
79
- this._dependencies.clear();
80
- }
81
- registerDependent(dependent) {
82
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
83
- this._dependents.add(dependent);
84
- }
85
- unregisterDependent(dependent) {
86
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
87
- this._dependents.delete(dependent);
88
- }
89
- notifyDependents() {
90
- if (this.disposed) return;
91
- this._dependents.forEach((dependent) => {
92
- dependent.notify();
93
- });
94
- }
95
- watch(tracker) {
96
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
97
- tracker.registerDependency(this);
98
- }
99
- trigger() {
100
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
101
- this.notifyDependents();
102
- }
103
- notify() {
104
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
105
- if (this.status === "dirty") return;
106
- this.status = "dirty";
107
- this.notifyDependents();
108
- }
109
- dispose() {
110
- if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
111
- Array.from(this._dependents).forEach((dependant) => {
112
- dependant.unregisterDependency(this);
113
- this.unregisterDependent(dependant);
114
- });
115
- Array.from(this._dependencies).forEach((dependency) => {
116
- this.unregisterDependency(dependency);
117
- });
118
- this._disposed = true;
119
- }
120
- }
121
-
122
- class Observable extends Disposable {
123
- _dependents = /* @__PURE__ */ new Set();
124
- _status = "resolved";
125
- get status() {
126
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
127
- return this._status;
128
- }
129
- set status(status) {
130
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
131
- this._status = status;
132
- }
133
- registerDependent(dependent) {
134
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
135
- this._dependents.add(dependent);
136
- }
137
- unregisterDependent(dependent) {
138
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
139
- this._dependents.delete(dependent);
140
- }
141
- notifyDependents() {
142
- if (this.disposed) return;
143
- this._dependents.forEach((dependent) => {
144
- dependent.notify();
145
- });
146
- }
147
- watch(tracker) {
148
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
149
- tracker.registerDependency(this);
150
- }
151
- trigger() {
152
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
153
- this.notifyDependents();
154
- }
155
- dispose() {
156
- if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
157
- Array.from(this._dependents).forEach((dependant) => {
158
- dependant.unregisterDependency(this);
159
- this.unregisterDependent(dependant);
160
- });
161
- this._disposed = true;
162
- }
163
- }
164
-
165
- class Observer extends Disposable {
166
- _dependencies = /* @__PURE__ */ new Set();
167
- registerDependency(dependency) {
168
- if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
169
- this._dependencies.add(dependency);
170
- dependency.registerDependent(this);
171
- }
172
- unregisterDependency(dependency) {
173
- if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
174
- this._dependencies.delete(dependency);
175
- dependency.unregisterDependent(this);
176
- }
177
- clearDependencies() {
178
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
179
- this._dependencies.forEach((dependency) => {
180
- dependency.unregisterDependent(this);
181
- });
182
- this._dependencies.clear();
183
- }
184
- dispose() {
185
- if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
186
- Array.from(this._dependencies).forEach((dependency) => {
187
- this.unregisterDependency(dependency);
188
- });
189
- this._disposed = true;
190
- }
191
- }
192
-
193
7
  class PendingError extends Error {
194
8
  pendingPromise;
195
9
  constructor(promise) {
@@ -348,52 +162,238 @@ class SyncResolver {
348
162
  this._onValue(value);
349
163
  }
350
164
  }
351
- abort() {
352
- this._iteration++;
353
- this._aborted = true;
165
+ abort() {
166
+ this._iteration++;
167
+ this._aborted = true;
168
+ }
169
+ }
170
+
171
+ class SyncScheduler {
172
+ _compute;
173
+ _resolver;
174
+ _onResolve;
175
+ _onReject;
176
+ _settled = Promise.withResolvers();
177
+ _disposed = false;
178
+ constructor(compute, onResolve, onReject) {
179
+ this._compute = compute;
180
+ this._onResolve = (value) => {
181
+ onResolve(value);
182
+ this._settled.resolve();
183
+ };
184
+ this._onReject = (error) => {
185
+ onReject(error);
186
+ this._settled.resolve();
187
+ };
188
+ this._resolver = new SyncResolver(compute, this._onResolve, this._onReject);
189
+ }
190
+ get settled() {
191
+ return this._settled.promise;
192
+ }
193
+ overwrite(value) {
194
+ if (this._disposed) throw new Error("[PicoFlow] ComputationScheduler is disposed");
195
+ if (this._resolver.finished) {
196
+ this._settled = Promise.withResolvers();
197
+ this._resolver = new SyncResolver(this._compute, this._onResolve, this._onReject);
198
+ }
199
+ this._resolver.overwrite(value);
200
+ }
201
+ compute() {
202
+ if (this._disposed) throw new Error("[PicoFlow] ComputationScheduler is disposed");
203
+ if (this._resolver.finished) {
204
+ this._settled = Promise.withResolvers();
205
+ this._resolver = new SyncResolver(this._compute, this._onResolve, this._onReject);
206
+ }
207
+ this._resolver.compute();
208
+ }
209
+ dispose() {
210
+ this._resolver.abort();
211
+ this._disposed = true;
212
+ }
213
+ }
214
+
215
+ class Disposable {
216
+ _disposed = false;
217
+ get disposed() {
218
+ return this._disposed;
219
+ }
220
+ dispose() {
221
+ if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
222
+ this._disposed = true;
223
+ }
224
+ }
225
+
226
+ class ExecutionStack {
227
+ static _pendingQueue = [];
228
+ static _effectQueue = [];
229
+ static _executionScheduled;
230
+ static pushPending(node) {
231
+ ExecutionStack._scheduleExecution();
232
+ ExecutionStack._pendingQueue.push(node);
233
+ }
234
+ static pushEffect(effect) {
235
+ ExecutionStack._scheduleExecution();
236
+ ExecutionStack._effectQueue.push(effect);
237
+ }
238
+ static _scheduleExecution() {
239
+ if (ExecutionStack._executionScheduled) return;
240
+ ExecutionStack._executionScheduled = new Promise((resolve) => {
241
+ setTimeout(() => {
242
+ ExecutionStack._executionScheduled = void 0;
243
+ ExecutionStack._execute();
244
+ resolve();
245
+ }, 0);
246
+ });
247
+ }
248
+ static _execute() {
249
+ ExecutionStack._pendingQueue.forEach((node) => {
250
+ node.execute();
251
+ });
252
+ ExecutionStack._pendingQueue.length = 0;
253
+ ExecutionStack._effectQueue.forEach((effect) => {
254
+ effect.execute();
255
+ });
256
+ ExecutionStack._effectQueue.length = 0;
257
+ }
258
+ }
259
+
260
+ class Node extends Disposable {
261
+ _dependencies = /* @__PURE__ */ new Set();
262
+ _dependents = /* @__PURE__ */ new Set();
263
+ _status = "resolved";
264
+ get status() {
265
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
266
+ return this._status;
267
+ }
268
+ set status(status) {
269
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
270
+ this._status = status;
271
+ }
272
+ registerDependency(dependency) {
273
+ if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
274
+ this._dependencies.add(dependency);
275
+ dependency.registerDependent(this);
276
+ }
277
+ unregisterDependency(dependency) {
278
+ if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
279
+ this._dependencies.delete(dependency);
280
+ dependency.unregisterDependent(this);
281
+ }
282
+ clearDependencies() {
283
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
284
+ this._dependencies.forEach((dependency) => {
285
+ dependency.unregisterDependent(this);
286
+ });
287
+ this._dependencies.clear();
288
+ }
289
+ registerDependent(dependent) {
290
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
291
+ this._dependents.add(dependent);
292
+ }
293
+ unregisterDependent(dependent) {
294
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
295
+ this._dependents.delete(dependent);
296
+ }
297
+ notifyDependents() {
298
+ if (this.disposed) return;
299
+ this._dependents.forEach((dependent) => {
300
+ dependent.notify();
301
+ });
302
+ }
303
+ watch(tracker) {
304
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
305
+ tracker.registerDependency(this);
306
+ }
307
+ trigger() {
308
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
309
+ this.notifyDependents();
310
+ }
311
+ notify() {
312
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
313
+ if (this.status === "dirty") return;
314
+ this.status = "dirty";
315
+ this.notifyDependents();
316
+ }
317
+ dispose() {
318
+ if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
319
+ Array.from(this._dependents).forEach((dependant) => {
320
+ dependant.unregisterDependency(this);
321
+ this.unregisterDependent(dependant);
322
+ });
323
+ Array.from(this._dependencies).forEach((dependency) => {
324
+ this.unregisterDependency(dependency);
325
+ });
326
+ this._disposed = true;
327
+ }
328
+ }
329
+
330
+ class Observable extends Disposable {
331
+ _dependents = /* @__PURE__ */ new Set();
332
+ _status = "resolved";
333
+ get status() {
334
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
335
+ return this._status;
336
+ }
337
+ set status(status) {
338
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
339
+ this._status = status;
340
+ }
341
+ registerDependent(dependent) {
342
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
343
+ this._dependents.add(dependent);
344
+ }
345
+ unregisterDependent(dependent) {
346
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
347
+ this._dependents.delete(dependent);
348
+ }
349
+ notifyDependents() {
350
+ if (this.disposed) return;
351
+ this._dependents.forEach((dependent) => {
352
+ dependent.notify();
353
+ });
354
+ }
355
+ watch(tracker) {
356
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
357
+ tracker.registerDependency(this);
358
+ }
359
+ trigger() {
360
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
361
+ this.notifyDependents();
362
+ }
363
+ dispose() {
364
+ if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
365
+ Array.from(this._dependents).forEach((dependant) => {
366
+ dependant.unregisterDependency(this);
367
+ this.unregisterDependent(dependant);
368
+ });
369
+ this._disposed = true;
354
370
  }
355
371
  }
356
372
 
357
- class SyncScheduler {
358
- _compute;
359
- _resolver;
360
- _onResolve;
361
- _onReject;
362
- _settled = Promise.withResolvers();
363
- _disposed = false;
364
- constructor(compute, onResolve, onReject) {
365
- this._compute = compute;
366
- this._onResolve = (value) => {
367
- onResolve(value);
368
- this._settled.resolve();
369
- };
370
- this._onReject = (error) => {
371
- onReject(error);
372
- this._settled.resolve();
373
- };
374
- this._resolver = new SyncResolver(compute, this._onResolve, this._onReject);
375
- }
376
- get settled() {
377
- return this._settled.promise;
373
+ class Observer extends Disposable {
374
+ _dependencies = /* @__PURE__ */ new Set();
375
+ registerDependency(dependency) {
376
+ if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
377
+ this._dependencies.add(dependency);
378
+ dependency.registerDependent(this);
378
379
  }
379
- overwrite(value) {
380
- if (this._disposed) throw new Error("[PicoFlow] ComputationScheduler is disposed");
381
- if (this._resolver.finished) {
382
- this._settled = Promise.withResolvers();
383
- this._resolver = new SyncResolver(this._compute, this._onResolve, this._onReject);
384
- }
385
- this._resolver.overwrite(value);
380
+ unregisterDependency(dependency) {
381
+ if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
382
+ this._dependencies.delete(dependency);
383
+ dependency.unregisterDependent(this);
386
384
  }
387
- compute() {
388
- if (this._disposed) throw new Error("[PicoFlow] ComputationScheduler is disposed");
389
- if (this._resolver.finished) {
390
- this._settled = Promise.withResolvers();
391
- this._resolver = new SyncResolver(this._compute, this._onResolve, this._onReject);
392
- }
393
- this._resolver.compute();
385
+ clearDependencies() {
386
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
387
+ this._dependencies.forEach((dependency) => {
388
+ dependency.unregisterDependent(this);
389
+ });
390
+ this._dependencies.clear();
394
391
  }
395
392
  dispose() {
396
- this._resolver.abort();
393
+ if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
394
+ Array.from(this._dependencies).forEach((dependency) => {
395
+ this.unregisterDependency(dependency);
396
+ });
397
397
  this._disposed = true;
398
398
  }
399
399
  }
@@ -552,6 +552,83 @@ class ValueNode extends Node {
552
552
  }
553
553
  }
554
554
 
555
+ class ValueAsyncNode extends ValueNode {
556
+ _scheduler;
557
+ _compute;
558
+ constructor(promiseOrCompute) {
559
+ super();
560
+ if (typeof promiseOrCompute === "function") {
561
+ this._compute = () => promiseOrCompute(this, this._value);
562
+ } else {
563
+ this._compute = () => promiseOrCompute;
564
+ }
565
+ this.status = "dirty";
566
+ this._scheduler = new AsyncScheduler(
567
+ () => this._compute(),
568
+ (value) => this._onResolve(value),
569
+ (error) => this._onReject(error)
570
+ );
571
+ }
572
+ _onResolve(value) {
573
+ this.status = "resolved";
574
+ this._value = value;
575
+ this._error = void 0;
576
+ this.notifyDependents();
577
+ }
578
+ _onReject(error) {
579
+ this.status = "error";
580
+ this._error = error;
581
+ this.notifyDependents();
582
+ }
583
+ set(promiseOrUpdater) {
584
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
585
+ if (typeof promiseOrUpdater === "function") {
586
+ const updater = promiseOrUpdater;
587
+ switch (this.status) {
588
+ case "resolved": {
589
+ this.status = "pending";
590
+ this._scheduler.overwrite(updater(this._value));
591
+ this.notifyDependents();
592
+ return;
593
+ }
594
+ case "pending":
595
+ case "error":
596
+ case "dirty": {
597
+ this.status = "pending";
598
+ this._scheduler.overwrite(updater(this._value));
599
+ this.notifyDependents();
600
+ return;
601
+ }
602
+ }
603
+ } else {
604
+ this.status = "pending";
605
+ const promise = promiseOrUpdater;
606
+ this._scheduler.overwrite(promise);
607
+ this.notifyDependents();
608
+ }
609
+ }
610
+ refresh() {
611
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
612
+ this.execute();
613
+ }
614
+ }
615
+
616
+ function constantAsync(valueOrInitializer) {
617
+ return new ValueAsyncNode(valueOrInitializer);
618
+ }
619
+
620
+ function derivationAsync(compute) {
621
+ return new ValueAsyncNode(compute);
622
+ }
623
+
624
+ function stateAsync(valueOrInitializer) {
625
+ return new ValueAsyncNode(valueOrInitializer);
626
+ }
627
+
628
+ function writableDerivationAsync(compute) {
629
+ return new ValueAsyncNode(compute);
630
+ }
631
+
555
632
  class ValueSyncNode extends ValueNode {
556
633
  _scheduler;
557
634
  _compute;
@@ -657,6 +734,14 @@ class ArrayNode extends ValueSyncNode {
657
734
  clearedItems: []
658
735
  });
659
736
  }
737
+ get(tracker) {
738
+ const values = super.get(tracker);
739
+ return [...values];
740
+ }
741
+ async pick() {
742
+ const values = await super.pick();
743
+ return [...values];
744
+ }
660
745
  get length() {
661
746
  if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
662
747
  return this._value.length;
@@ -744,6 +829,10 @@ class ArrayNode extends ValueSyncNode {
744
829
  }
745
830
  }
746
831
 
832
+ function array(initial) {
833
+ return new ArrayNode(initial);
834
+ }
835
+
747
836
  class MapNode extends ValueSyncNode {
748
837
  $lastAction;
749
838
  constructor(value = /* @__PURE__ */ new Map()) {
@@ -815,95 +904,6 @@ class MapNode extends ValueSyncNode {
815
904
  }
816
905
  }
817
906
 
818
- class SignalNode extends Observable {
819
- subscribe(onTrigger, onError, onPending) {
820
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
821
- const effect = new EffectNode((t) => this.watch(t), onTrigger, onError, onPending);
822
- return effect;
823
- }
824
- }
825
-
826
- class ValueAsyncNode extends ValueNode {
827
- _scheduler;
828
- _compute;
829
- constructor(promiseOrCompute) {
830
- super();
831
- if (typeof promiseOrCompute === "function") {
832
- this._compute = () => promiseOrCompute(this, this._value);
833
- } else {
834
- this._compute = () => promiseOrCompute;
835
- }
836
- this.status = "dirty";
837
- this._scheduler = new AsyncScheduler(
838
- () => this._compute(),
839
- (value) => this._onResolve(value),
840
- (error) => this._onReject(error)
841
- );
842
- }
843
- _onResolve(value) {
844
- this.status = "resolved";
845
- this._value = value;
846
- this._error = void 0;
847
- this.notifyDependents();
848
- }
849
- _onReject(error) {
850
- this.status = "error";
851
- this._error = error;
852
- this.notifyDependents();
853
- }
854
- set(promiseOrUpdater) {
855
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
856
- if (typeof promiseOrUpdater === "function") {
857
- const updater = promiseOrUpdater;
858
- switch (this.status) {
859
- case "resolved": {
860
- this.status = "pending";
861
- this._scheduler.overwrite(updater(this._value));
862
- this.notifyDependents();
863
- return;
864
- }
865
- case "pending":
866
- case "error":
867
- case "dirty": {
868
- this.status = "pending";
869
- this._scheduler.overwrite(updater(this._value));
870
- this.notifyDependents();
871
- return;
872
- }
873
- }
874
- } else {
875
- this.status = "pending";
876
- const promise = promiseOrUpdater;
877
- this._scheduler.overwrite(promise);
878
- this.notifyDependents();
879
- }
880
- }
881
- refresh() {
882
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
883
- this.execute();
884
- }
885
- }
886
-
887
- function constantAsync(valueOrInitializer) {
888
- return new ValueAsyncNode(valueOrInitializer);
889
- }
890
-
891
- function derivationAsync(compute) {
892
- return new ValueAsyncNode(compute);
893
- }
894
-
895
- function stateAsync(valueOrInitializer) {
896
- return new ValueAsyncNode(valueOrInitializer);
897
- }
898
-
899
- function writableDerivationAsync(compute) {
900
- return new ValueAsyncNode(compute);
901
- }
902
-
903
- function array(initial) {
904
- return new ArrayNode(initial);
905
- }
906
-
907
907
  function map(initial) {
908
908
  if (initial instanceof Map) {
909
909
  return new MapNode(initial);
@@ -915,6 +915,14 @@ function subscribe(data, onData, onError, onPending) {
915
915
  return new EffectNode(data, onData, onError, onPending);
916
916
  }
917
917
 
918
+ class SignalNode extends Observable {
919
+ subscribe(onTrigger, onError, onPending) {
920
+ if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
921
+ const effect = new EffectNode((t) => this.watch(t), onTrigger, onError, onPending);
922
+ return effect;
923
+ }
924
+ }
925
+
918
926
  function signal() {
919
927
  return new SignalNode();
920
928
  }
@@ -1,4 +1,4 @@
1
- import { FlowEffect } from '../nodes';
1
+ import { FlowEffect } from '../nodes/flowEffect';
2
2
  import { FlowTracker } from './flowTracker';
3
3
  /**
4
4
  * Function that tracks reactive dependencies and returns data.
@@ -1 +1 @@
1
- {"version":3,"file":"flowSubscribable.d.ts","sourceRoot":"","sources":["../../../../src/api/base/flowSubscribable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,WAAW,KAAK,CAAC,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,SAAS,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,SAAS,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAC/B;;;;;;;;;;;;OAYG;IACH,SAAS,CACL,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC7B,OAAO,CAAC,EAAE,mBAAmB,EAC7B,SAAS,CAAC,EAAE,qBAAqB,GAClC,UAAU,CAAC;CACjB"}
1
+ {"version":3,"file":"flowSubscribable.d.ts","sourceRoot":"","sources":["../../../../src/api/base/flowSubscribable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,WAAW,KAAK,CAAC,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,SAAS,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,SAAS,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAC/B;;;;;;;;;;;;OAYG;IACH,SAAS,CACL,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC7B,OAAO,CAAC,EAAE,mBAAmB,EAC7B,SAAS,CAAC,EAAE,qBAAqB,GAClC,UAAU,CAAC;CACjB"}
@@ -1,4 +1,4 @@
1
- import { FlowTracker } from '../../../../api/base';
1
+ import { FlowTracker } from '../../base';
2
2
  import { FlowValue } from '../flowValue';
3
3
  import { NotPromise } from '../utils';
4
4
  /** Function that derives a value asynchronously from dependencies and optionally the previous value. */