@ersbeth/picoflow 0.2.2 → 0.2.3
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/api/doc/picoflow.from.md +55 -0
- package/api/doc/picoflow.from_1.md +55 -0
- package/api/doc/picoflow.from_2.md +55 -0
- package/api/doc/picoflow.from_3.md +55 -0
- package/api/doc/picoflow.from_4.md +55 -0
- package/api/doc/picoflow.from_5.md +55 -0
- package/api/doc/picoflow.md +121 -11
- package/api/doc/picoflow.solidderivation._constructor_.md +49 -0
- package/api/doc/picoflow.solidderivation.get.md +13 -0
- package/api/doc/picoflow.solidderivation.md +94 -0
- package/api/doc/picoflow.solidgetter.md +13 -0
- package/api/doc/picoflow.solidobservable.get.md +13 -0
- package/api/doc/picoflow.solidobservable.md +57 -0
- package/api/doc/picoflow.solidresource._constructor_.md +49 -0
- package/api/doc/picoflow.solidresource.get.md +13 -0
- package/api/doc/picoflow.solidresource.latest.md +13 -0
- package/api/doc/picoflow.solidresource.md +157 -0
- package/api/doc/picoflow.solidresource.refetch.md +13 -0
- package/api/doc/picoflow.solidresource.state.md +13 -0
- package/api/doc/picoflow.solidstate._constructor_.md +49 -0
- package/api/doc/picoflow.solidstate.get.md +13 -0
- package/api/doc/picoflow.solidstate.md +115 -0
- package/api/doc/picoflow.solidstate.set.md +13 -0
- package/api/picoflow.public.api.md +52 -6
- package/dist/picoflow.js +903 -351
- package/dist/types/basic/index.d.ts +0 -1
- package/dist/types/basic/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/solid/converters.d.ts +64 -0
- package/dist/types/solid/converters.d.ts.map +1 -0
- package/dist/types/solid/index.d.ts +3 -0
- package/dist/types/solid/index.d.ts.map +1 -0
- package/dist/types/solid/primitives.d.ts +88 -0
- package/dist/types/solid/primitives.d.ts.map +1 -0
- package/package.json +4 -1
- package/src/basic/index.ts +0 -1
- package/src/index.ts +18 -13
- package/src/solid/converters.ts +159 -0
- package/src/solid/index.ts +2 -0
- package/src/solid/primitives.ts +109 -0
- package/api/doc/picoflow.flowderivationasync._constructor_.md +0 -49
- package/api/doc/picoflow.flowderivationasync.get.md +0 -23
- package/api/doc/picoflow.flowderivationasync.md +0 -86
- package/dist/types/basic/derivationAsync.d.ts +0 -31
- package/dist/types/basic/derivationAsync.d.ts.map +0 -1
- package/src/basic/derivationAsync.ts +0 -38
package/dist/picoflow.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
class FlowSignal {
|
|
2
2
|
/**
|
|
3
3
|
* Triggers the FlowSignal.
|
|
4
4
|
* Notifies all registered listeners and schedules execution of associated effects.
|
|
@@ -93,9 +93,9 @@ let FlowSignal$1 = class FlowSignal {
|
|
|
93
93
|
_unregisterEffect(effect) {
|
|
94
94
|
this._effects.delete(effect);
|
|
95
95
|
}
|
|
96
|
-
}
|
|
96
|
+
}
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
class FlowEffect {
|
|
99
99
|
/**
|
|
100
100
|
* Creates a new FlowEffect.
|
|
101
101
|
*
|
|
@@ -169,9 +169,9 @@ let FlowEffect$1 = class FlowEffect {
|
|
|
169
169
|
this._dependencies.delete(dependency);
|
|
170
170
|
dependency._unregisterEffect(this);
|
|
171
171
|
}
|
|
172
|
-
}
|
|
172
|
+
}
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
class FlowObservable extends FlowSignal {
|
|
175
175
|
/* INTERNAL -------------------------------------------*/
|
|
176
176
|
/*@internal*/
|
|
177
177
|
_value;
|
|
@@ -187,14 +187,14 @@ let FlowObservable$1 = class FlowObservable extends FlowSignal$1 {
|
|
|
187
187
|
* @returns A disposer function to cancel the subscription.
|
|
188
188
|
*/
|
|
189
189
|
subscribe(listener) {
|
|
190
|
-
const effect = new FlowEffect
|
|
190
|
+
const effect = new FlowEffect((get) => {
|
|
191
191
|
listener(get(this));
|
|
192
192
|
});
|
|
193
193
|
return () => effect.dispose();
|
|
194
194
|
}
|
|
195
|
-
}
|
|
195
|
+
}
|
|
196
196
|
|
|
197
|
-
class FlowConstant extends FlowObservable
|
|
197
|
+
class FlowConstant extends FlowObservable {
|
|
198
198
|
/**
|
|
199
199
|
* Creates a new FlowConstant instance.
|
|
200
200
|
*
|
|
@@ -264,7 +264,7 @@ class FlowState extends FlowConstant {
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
|
|
267
|
+
class FlowDerivation extends FlowObservable {
|
|
268
268
|
/**
|
|
269
269
|
* Creates a new FlowDerivation.
|
|
270
270
|
* @param compute - A function that computes the derived value. It is provided with two parameters:
|
|
@@ -334,372 +334,90 @@ let FlowDerivation$1 = class FlowDerivation extends FlowObservable$1 {
|
|
|
334
334
|
this._initLazy();
|
|
335
335
|
this._compute();
|
|
336
336
|
}
|
|
337
|
-
}
|
|
337
|
+
}
|
|
338
338
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
* Triggers the FlowSignal.
|
|
342
|
-
* Notifies all registered listeners and schedules execution of associated effects.
|
|
343
|
-
* @throws If the FlowSignal has already been disposed.
|
|
344
|
-
* @public
|
|
345
|
-
*/
|
|
346
|
-
trigger() {
|
|
347
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
348
|
-
this._notify();
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Disposes the FlowSignal.
|
|
352
|
-
* Cleans up all registered effects, listeners, and dependencies.
|
|
353
|
-
* Once disposed, further usage of the signal will throw an error.
|
|
354
|
-
* @throws If the FlowSignal is already disposed.
|
|
355
|
-
* @public
|
|
356
|
-
*/
|
|
357
|
-
dispose(options) {
|
|
358
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
359
|
-
if (options?.self) {
|
|
360
|
-
Array.from(this._effects).forEach(
|
|
361
|
-
(effect) => effect._unregisterDependency(this)
|
|
362
|
-
);
|
|
363
|
-
Array.from(this._listeners).forEach(
|
|
364
|
-
(listener) => listener._unregisterDependency(this)
|
|
365
|
-
);
|
|
366
|
-
} else {
|
|
367
|
-
Array.from(this._effects).forEach((effect) => effect.dispose());
|
|
368
|
-
Array.from(this._listeners).forEach(
|
|
369
|
-
(listener) => listener.dispose()
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
Array.from(this._dependencies).forEach((dependency) => {
|
|
373
|
-
this._unregisterDependency(dependency);
|
|
374
|
-
});
|
|
375
|
-
this._disposed = true;
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Indicates whether the FlowSignal has been disposed.
|
|
379
|
-
* @remarks Once disposed, the signal should not be used.
|
|
380
|
-
* @public
|
|
381
|
-
*/
|
|
382
|
-
get disposed() {
|
|
383
|
-
return this._disposed;
|
|
384
|
-
}
|
|
385
|
-
/* INTERNAL ------------------------------------------------------------- */
|
|
386
|
-
/*@internal*/
|
|
387
|
-
_disposed = false;
|
|
388
|
-
/*@internal*/
|
|
389
|
-
_dependencies = /* @__PURE__ */ new Set();
|
|
390
|
-
/*@internal*/
|
|
391
|
-
_listeners = /* @__PURE__ */ new Set();
|
|
392
|
-
/*@internal*/
|
|
393
|
-
_effects = /* @__PURE__ */ new Set();
|
|
394
|
-
/*@internal*/
|
|
395
|
-
_watch() {
|
|
396
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
397
|
-
}
|
|
398
|
-
/*@internal*/
|
|
399
|
-
_notify() {
|
|
400
|
-
this._listeners.forEach((listener) => listener._notify());
|
|
401
|
-
this._effects.forEach((effect) => effect._exec());
|
|
402
|
-
}
|
|
403
|
-
/*@internal*/
|
|
404
|
-
_watchFrom(listener) {
|
|
405
|
-
listener._registerDependency(this);
|
|
406
|
-
this._watch();
|
|
407
|
-
}
|
|
408
|
-
/*@internal*/
|
|
409
|
-
_registerDependency(dependency) {
|
|
410
|
-
this._dependencies.add(dependency);
|
|
411
|
-
dependency._registerListener(this);
|
|
412
|
-
}
|
|
413
|
-
/*@internal*/
|
|
414
|
-
_unregisterDependency(dependency) {
|
|
415
|
-
this._dependencies.delete(dependency);
|
|
416
|
-
dependency._unregisterListener(this);
|
|
417
|
-
}
|
|
418
|
-
/*@internal*/
|
|
419
|
-
_registerListener(signal) {
|
|
420
|
-
this._listeners.add(signal);
|
|
421
|
-
}
|
|
422
|
-
/*@internal*/
|
|
423
|
-
_unregisterListener(signal) {
|
|
424
|
-
this._listeners.delete(signal);
|
|
425
|
-
}
|
|
426
|
-
/*@internal*/
|
|
427
|
-
_registerEffect(effect) {
|
|
428
|
-
this._effects.add(effect);
|
|
429
|
-
}
|
|
430
|
-
/*@internal*/
|
|
431
|
-
_unregisterEffect(effect) {
|
|
432
|
-
this._effects.delete(effect);
|
|
433
|
-
}
|
|
339
|
+
function isDisposable(obj) {
|
|
340
|
+
return obj !== null && obj !== void 0 && typeof obj.dispose === "function";
|
|
434
341
|
}
|
|
435
342
|
|
|
436
|
-
class
|
|
343
|
+
class FlowMap extends FlowState {
|
|
437
344
|
/**
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
* @param apply - A side-effect function that receives a getter and a watcher to
|
|
441
|
-
* access and register dependencies on reactive observables and signals.
|
|
345
|
+
* A reactive state that holds the most recent key and value that were set.
|
|
442
346
|
*
|
|
443
347
|
* @remarks
|
|
444
|
-
*
|
|
445
|
-
*
|
|
348
|
+
* When a key is set via {@link FlowMap.setAt}, this state is updated with
|
|
349
|
+
* the corresponding key and value.
|
|
446
350
|
*
|
|
447
351
|
* @public
|
|
448
352
|
*/
|
|
449
|
-
|
|
450
|
-
this._trackedExec = () => apply(this._trackedGet, this._trackedWatch);
|
|
451
|
-
this._untrackedExec = () => apply(this._untrackedGet, this._untrackedWatch);
|
|
452
|
-
this._exec();
|
|
453
|
-
}
|
|
353
|
+
$lastSet = new FlowState({});
|
|
454
354
|
/**
|
|
455
|
-
*
|
|
355
|
+
* A reactive state that holds the most recent key and value that were deleted.
|
|
456
356
|
*
|
|
457
357
|
* @remarks
|
|
458
|
-
*
|
|
459
|
-
*
|
|
358
|
+
* When a key is deleted via {@link FlowMap.delete}, this state is updated with
|
|
359
|
+
* the corresponding key and its last known value.
|
|
460
360
|
*
|
|
461
361
|
* @public
|
|
462
362
|
*/
|
|
463
|
-
|
|
464
|
-
if (this._disposed) throw new Error("[PicoFlow] Effect is disposed");
|
|
465
|
-
Array.from(this._dependencies).forEach((dependency) => {
|
|
466
|
-
this._unregisterDependency(dependency);
|
|
467
|
-
});
|
|
468
|
-
this._disposed = true;
|
|
469
|
-
}
|
|
363
|
+
$lastDeleted = new FlowState({});
|
|
470
364
|
/**
|
|
471
|
-
*
|
|
365
|
+
* Sets a value at the specified key in the underlying map.
|
|
472
366
|
*
|
|
473
|
-
* @
|
|
367
|
+
* @param key - The key at which to set the value.
|
|
368
|
+
* @param value - The value to set.
|
|
369
|
+
* @throws If the FlowMap instance is disposed.
|
|
370
|
+
*
|
|
371
|
+
* @remarks
|
|
372
|
+
* Updates the internal map, emits the key-value pair via {@link FlowMap.$lastSet},
|
|
373
|
+
* and notifies all subscribers of the change.
|
|
474
374
|
*
|
|
475
375
|
* @public
|
|
476
376
|
*/
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
_initialized = false;
|
|
483
|
-
_dependencies = /* @__PURE__ */ new Set();
|
|
484
|
-
_trackedGet = (observable) => observable._getFrom(this);
|
|
485
|
-
_trackedWatch = (signal) => signal._watchFrom(this);
|
|
486
|
-
_untrackedGet = (observable) => observable.get();
|
|
487
|
-
_untrackedWatch = (signal) => signal._watch();
|
|
488
|
-
_trackedExec;
|
|
489
|
-
_untrackedExec;
|
|
490
|
-
/*@internal*/
|
|
491
|
-
_exec() {
|
|
492
|
-
if (this._disposed)
|
|
493
|
-
throw new Error("[PicoFlow] Effect is disposed");
|
|
494
|
-
if (this._initialized) this._untrackedExec();
|
|
495
|
-
else {
|
|
496
|
-
this._trackedExec();
|
|
497
|
-
this._initialized = true;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
/*@internal*/
|
|
501
|
-
_registerDependency(dependency) {
|
|
502
|
-
this._dependencies.add(dependency);
|
|
503
|
-
dependency._registerEffect(this);
|
|
504
|
-
}
|
|
505
|
-
/*@internal*/
|
|
506
|
-
_unregisterDependency(dependency) {
|
|
507
|
-
this._dependencies.delete(dependency);
|
|
508
|
-
dependency._unregisterEffect(this);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
class FlowObservable extends FlowSignal {
|
|
513
|
-
/* INTERNAL -------------------------------------------*/
|
|
514
|
-
/*@internal*/
|
|
515
|
-
_value;
|
|
516
|
-
/*@internal*/
|
|
517
|
-
_getFrom(listener) {
|
|
518
|
-
listener._registerDependency(this);
|
|
519
|
-
return this.get();
|
|
377
|
+
setAt(key, value) {
|
|
378
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
379
|
+
this._value.set(key, value);
|
|
380
|
+
this.$lastSet.set({ key, value });
|
|
381
|
+
this._notify();
|
|
520
382
|
}
|
|
521
383
|
/**
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
* @param
|
|
525
|
-
* @
|
|
384
|
+
* Deletes the value at the specified key from the underlying map.
|
|
385
|
+
*
|
|
386
|
+
* @param key - The key to delete.
|
|
387
|
+
* @throws If the FlowMap instance is disposed.
|
|
388
|
+
*
|
|
389
|
+
* @remarks
|
|
390
|
+
* Removes the key from the internal map, emits the deleted key and its value via {@link FlowMap.$lastDeleted},
|
|
391
|
+
* and notifies all subscribers of the change.
|
|
392
|
+
*
|
|
393
|
+
* @public
|
|
526
394
|
*/
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
395
|
+
delete(key) {
|
|
396
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
397
|
+
const value = this._value.get(key);
|
|
398
|
+
this._value.delete(key);
|
|
399
|
+
this.$lastDeleted.set({ key, value });
|
|
400
|
+
this._notify();
|
|
532
401
|
}
|
|
533
402
|
}
|
|
534
403
|
|
|
535
|
-
class
|
|
404
|
+
class FlowStream extends FlowObservable {
|
|
536
405
|
/**
|
|
537
|
-
* Creates a new
|
|
538
|
-
* @param
|
|
539
|
-
*
|
|
406
|
+
* Creates a new FlowStream.
|
|
407
|
+
* @param updater - A function that receives a setter to update the stream's value.
|
|
408
|
+
* It should return a disposer function that will be called upon disposal.
|
|
540
409
|
* @public
|
|
541
410
|
*/
|
|
542
|
-
constructor(
|
|
411
|
+
constructor(updater) {
|
|
543
412
|
super();
|
|
544
|
-
this.
|
|
413
|
+
this._disposer = updater((value) => {
|
|
414
|
+
this._set(value);
|
|
415
|
+
});
|
|
545
416
|
}
|
|
546
417
|
/**
|
|
547
|
-
*
|
|
548
|
-
* @returns The current
|
|
549
|
-
* @
|
|
550
|
-
* This method lazily initializes and updates the derivation if it is marked as dirty. It throws an error
|
|
551
|
-
* if the derivation has been disposed.
|
|
552
|
-
* @public
|
|
553
|
-
*/
|
|
554
|
-
get() {
|
|
555
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
556
|
-
this._initLazy();
|
|
557
|
-
this._compute();
|
|
558
|
-
return this._value;
|
|
559
|
-
}
|
|
560
|
-
/* INTERNAL --------------------------------------------------------- */
|
|
561
|
-
_initialized = false;
|
|
562
|
-
_dirty = false;
|
|
563
|
-
_trackedGet = (observable) => observable._getFrom(this);
|
|
564
|
-
_trackedWatch = (signal) => signal._watchFrom(this);
|
|
565
|
-
_untrackedGet = (observable) => observable.get();
|
|
566
|
-
_untrackedWatch = (signal) => signal._watch();
|
|
567
|
-
_trackedCompute;
|
|
568
|
-
_untrackedCompute;
|
|
569
|
-
_initEager(compute) {
|
|
570
|
-
this._trackedCompute = () => compute(this._trackedGet, this._trackedWatch);
|
|
571
|
-
this._untrackedCompute = () => compute(this._untrackedGet, this._untrackedWatch);
|
|
572
|
-
}
|
|
573
|
-
_initLazy() {
|
|
574
|
-
if (!this._initialized) {
|
|
575
|
-
this._value = this._trackedCompute();
|
|
576
|
-
this._initialized = true;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
/* @internal */
|
|
580
|
-
_compute() {
|
|
581
|
-
if (this._dirty) {
|
|
582
|
-
this._value = this._untrackedCompute();
|
|
583
|
-
this._dirty = false;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
/* @internal */
|
|
587
|
-
_notify() {
|
|
588
|
-
this._dirty = true;
|
|
589
|
-
super._notify();
|
|
590
|
-
}
|
|
591
|
-
/* @internal */
|
|
592
|
-
_watch() {
|
|
593
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
594
|
-
this._initLazy();
|
|
595
|
-
this._compute();
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
class FlowDerivationAsync extends FlowDerivation {
|
|
600
|
-
/**
|
|
601
|
-
* Creates a new FlowDerivation.
|
|
602
|
-
* @param compute - A function that computes the derived value. It is provided with two parameters:
|
|
603
|
-
* a getter and a watcher that respect dependency tracking.
|
|
604
|
-
* @public
|
|
605
|
-
*/
|
|
606
|
-
// biome-ignore lint/complexity/noUselessConstructor: <explanation>
|
|
607
|
-
constructor(compute) {
|
|
608
|
-
super(compute);
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Retrieves the current resource value.
|
|
612
|
-
* @returns The current value, or undefined if the resource has not been fetched yet.
|
|
613
|
-
* @throws Error if the resource is disposed.
|
|
614
|
-
* @public
|
|
615
|
-
*/
|
|
616
|
-
get() {
|
|
617
|
-
return super.get();
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
function isDisposable(obj) {
|
|
622
|
-
return obj !== null && obj !== void 0 && typeof obj.dispose === "function";
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
class FlowMap extends FlowState {
|
|
626
|
-
/**
|
|
627
|
-
* A reactive state that holds the most recent key and value that were set.
|
|
628
|
-
*
|
|
629
|
-
* @remarks
|
|
630
|
-
* When a key is set via {@link FlowMap.setAt}, this state is updated with
|
|
631
|
-
* the corresponding key and value.
|
|
632
|
-
*
|
|
633
|
-
* @public
|
|
634
|
-
*/
|
|
635
|
-
$lastSet = new FlowState({});
|
|
636
|
-
/**
|
|
637
|
-
* A reactive state that holds the most recent key and value that were deleted.
|
|
638
|
-
*
|
|
639
|
-
* @remarks
|
|
640
|
-
* When a key is deleted via {@link FlowMap.delete}, this state is updated with
|
|
641
|
-
* the corresponding key and its last known value.
|
|
642
|
-
*
|
|
643
|
-
* @public
|
|
644
|
-
*/
|
|
645
|
-
$lastDeleted = new FlowState({});
|
|
646
|
-
/**
|
|
647
|
-
* Sets a value at the specified key in the underlying map.
|
|
648
|
-
*
|
|
649
|
-
* @param key - The key at which to set the value.
|
|
650
|
-
* @param value - The value to set.
|
|
651
|
-
* @throws If the FlowMap instance is disposed.
|
|
652
|
-
*
|
|
653
|
-
* @remarks
|
|
654
|
-
* Updates the internal map, emits the key-value pair via {@link FlowMap.$lastSet},
|
|
655
|
-
* and notifies all subscribers of the change.
|
|
656
|
-
*
|
|
657
|
-
* @public
|
|
658
|
-
*/
|
|
659
|
-
setAt(key, value) {
|
|
660
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
661
|
-
this._value.set(key, value);
|
|
662
|
-
this.$lastSet.set({ key, value });
|
|
663
|
-
this._notify();
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Deletes the value at the specified key from the underlying map.
|
|
667
|
-
*
|
|
668
|
-
* @param key - The key to delete.
|
|
669
|
-
* @throws If the FlowMap instance is disposed.
|
|
670
|
-
*
|
|
671
|
-
* @remarks
|
|
672
|
-
* Removes the key from the internal map, emits the deleted key and its value via {@link FlowMap.$lastDeleted},
|
|
673
|
-
* and notifies all subscribers of the change.
|
|
674
|
-
*
|
|
675
|
-
* @public
|
|
676
|
-
*/
|
|
677
|
-
delete(key) {
|
|
678
|
-
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
679
|
-
const value = this._value.get(key);
|
|
680
|
-
this._value.delete(key);
|
|
681
|
-
this.$lastDeleted.set({ key, value });
|
|
682
|
-
this._notify();
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
class FlowStream extends FlowObservable$1 {
|
|
687
|
-
/**
|
|
688
|
-
* Creates a new FlowStream.
|
|
689
|
-
* @param updater - A function that receives a setter to update the stream's value.
|
|
690
|
-
* It should return a disposer function that will be called upon disposal.
|
|
691
|
-
* @public
|
|
692
|
-
*/
|
|
693
|
-
constructor(updater) {
|
|
694
|
-
super();
|
|
695
|
-
this._disposer = updater((value) => {
|
|
696
|
-
this._set(value);
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Retrieves the current value of the stream.
|
|
701
|
-
* @returns The current value, or undefined if no value has been set yet.
|
|
702
|
-
* @throws Error if the stream is disposed.
|
|
418
|
+
* Retrieves the current value of the stream.
|
|
419
|
+
* @returns The current value, or undefined if no value has been set yet.
|
|
420
|
+
* @throws Error if the stream is disposed.
|
|
703
421
|
* @public
|
|
704
422
|
*/
|
|
705
423
|
get() {
|
|
@@ -727,7 +445,7 @@ class FlowStream extends FlowObservable$1 {
|
|
|
727
445
|
}
|
|
728
446
|
}
|
|
729
447
|
|
|
730
|
-
class FlowStreamAsync extends FlowObservable
|
|
448
|
+
class FlowStreamAsync extends FlowObservable {
|
|
731
449
|
/**
|
|
732
450
|
* Creates a new asynchronous FlowStream.
|
|
733
451
|
* @param updater - A function that receives a setter to update the stream's value.
|
|
@@ -785,7 +503,7 @@ class FlowStreamAsync extends FlowObservable$1 {
|
|
|
785
503
|
}
|
|
786
504
|
}
|
|
787
505
|
|
|
788
|
-
class FlowResource extends FlowObservable
|
|
506
|
+
class FlowResource extends FlowObservable {
|
|
789
507
|
/**
|
|
790
508
|
* Creates a new FlowResource.
|
|
791
509
|
* @param fetch - An asynchronous function that retrieves the resource's value.
|
|
@@ -826,7 +544,7 @@ class FlowResource extends FlowObservable$1 {
|
|
|
826
544
|
_fetch;
|
|
827
545
|
}
|
|
828
546
|
|
|
829
|
-
class FlowResourceAsync extends FlowObservable
|
|
547
|
+
class FlowResourceAsync extends FlowObservable {
|
|
830
548
|
/**
|
|
831
549
|
* Creates a new FlowResource.
|
|
832
550
|
* @param fetch - An asynchronous function that retrieves the resource's value.
|
|
@@ -865,7 +583,7 @@ class FlowResourceAsync extends FlowObservable$1 {
|
|
|
865
583
|
_fetch;
|
|
866
584
|
}
|
|
867
585
|
|
|
868
|
-
class FlowArray extends FlowObservable
|
|
586
|
+
class FlowArray extends FlowObservable {
|
|
869
587
|
/**
|
|
870
588
|
* Last action performed on the FlowArray.
|
|
871
589
|
* @public
|
|
@@ -1032,7 +750,7 @@ class FlowArray extends FlowObservable$1 {
|
|
|
1032
750
|
}
|
|
1033
751
|
|
|
1034
752
|
function signal() {
|
|
1035
|
-
return new FlowSignal
|
|
753
|
+
return new FlowSignal();
|
|
1036
754
|
}
|
|
1037
755
|
function constant(value) {
|
|
1038
756
|
return new FlowConstant(value);
|
|
@@ -1053,10 +771,10 @@ function streamAsync(updater) {
|
|
|
1053
771
|
return new FlowStreamAsync(updater);
|
|
1054
772
|
}
|
|
1055
773
|
function derivation(fn) {
|
|
1056
|
-
return new FlowDerivation
|
|
774
|
+
return new FlowDerivation(fn);
|
|
1057
775
|
}
|
|
1058
776
|
function effect(fn) {
|
|
1059
|
-
return new FlowEffect
|
|
777
|
+
return new FlowEffect(fn);
|
|
1060
778
|
}
|
|
1061
779
|
function map(initial) {
|
|
1062
780
|
return new FlowMap(
|
|
@@ -1067,4 +785,838 @@ function array(initial) {
|
|
|
1067
785
|
return new FlowArray(initial);
|
|
1068
786
|
}
|
|
1069
787
|
|
|
1070
|
-
|
|
788
|
+
let FlowSignal$1 = class FlowSignal {
|
|
789
|
+
/**
|
|
790
|
+
* Triggers the FlowSignal.
|
|
791
|
+
* Notifies all registered listeners and schedules execution of associated effects.
|
|
792
|
+
* @throws If the FlowSignal has already been disposed.
|
|
793
|
+
* @public
|
|
794
|
+
*/
|
|
795
|
+
trigger() {
|
|
796
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
797
|
+
this._notify();
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Disposes the FlowSignal.
|
|
801
|
+
* Cleans up all registered effects, listeners, and dependencies.
|
|
802
|
+
* Once disposed, further usage of the signal will throw an error.
|
|
803
|
+
* @throws If the FlowSignal is already disposed.
|
|
804
|
+
* @public
|
|
805
|
+
*/
|
|
806
|
+
dispose(options) {
|
|
807
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
808
|
+
if (options?.self) {
|
|
809
|
+
Array.from(this._effects).forEach(
|
|
810
|
+
(effect) => effect._unregisterDependency(this)
|
|
811
|
+
);
|
|
812
|
+
Array.from(this._listeners).forEach(
|
|
813
|
+
(listener) => listener._unregisterDependency(this)
|
|
814
|
+
);
|
|
815
|
+
} else {
|
|
816
|
+
Array.from(this._effects).forEach((effect) => effect.dispose());
|
|
817
|
+
Array.from(this._listeners).forEach(
|
|
818
|
+
(listener) => listener.dispose()
|
|
819
|
+
);
|
|
820
|
+
}
|
|
821
|
+
Array.from(this._dependencies).forEach((dependency) => {
|
|
822
|
+
this._unregisterDependency(dependency);
|
|
823
|
+
});
|
|
824
|
+
this._disposed = true;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Indicates whether the FlowSignal has been disposed.
|
|
828
|
+
* @remarks Once disposed, the signal should not be used.
|
|
829
|
+
* @public
|
|
830
|
+
*/
|
|
831
|
+
get disposed() {
|
|
832
|
+
return this._disposed;
|
|
833
|
+
}
|
|
834
|
+
/* INTERNAL ------------------------------------------------------------- */
|
|
835
|
+
/*@internal*/
|
|
836
|
+
_disposed = false;
|
|
837
|
+
/*@internal*/
|
|
838
|
+
_dependencies = /* @__PURE__ */ new Set();
|
|
839
|
+
/*@internal*/
|
|
840
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
841
|
+
/*@internal*/
|
|
842
|
+
_effects = /* @__PURE__ */ new Set();
|
|
843
|
+
/*@internal*/
|
|
844
|
+
_watch() {
|
|
845
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
846
|
+
}
|
|
847
|
+
/*@internal*/
|
|
848
|
+
_notify() {
|
|
849
|
+
this._listeners.forEach((listener) => listener._notify());
|
|
850
|
+
this._effects.forEach((effect) => effect._exec());
|
|
851
|
+
}
|
|
852
|
+
/*@internal*/
|
|
853
|
+
_watchFrom(listener) {
|
|
854
|
+
listener._registerDependency(this);
|
|
855
|
+
this._watch();
|
|
856
|
+
}
|
|
857
|
+
/*@internal*/
|
|
858
|
+
_registerDependency(dependency) {
|
|
859
|
+
this._dependencies.add(dependency);
|
|
860
|
+
dependency._registerListener(this);
|
|
861
|
+
}
|
|
862
|
+
/*@internal*/
|
|
863
|
+
_unregisterDependency(dependency) {
|
|
864
|
+
this._dependencies.delete(dependency);
|
|
865
|
+
dependency._unregisterListener(this);
|
|
866
|
+
}
|
|
867
|
+
/*@internal*/
|
|
868
|
+
_registerListener(signal) {
|
|
869
|
+
this._listeners.add(signal);
|
|
870
|
+
}
|
|
871
|
+
/*@internal*/
|
|
872
|
+
_unregisterListener(signal) {
|
|
873
|
+
this._listeners.delete(signal);
|
|
874
|
+
}
|
|
875
|
+
/*@internal*/
|
|
876
|
+
_registerEffect(effect) {
|
|
877
|
+
this._effects.add(effect);
|
|
878
|
+
}
|
|
879
|
+
/*@internal*/
|
|
880
|
+
_unregisterEffect(effect) {
|
|
881
|
+
this._effects.delete(effect);
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
let FlowEffect$1 = class FlowEffect {
|
|
886
|
+
/**
|
|
887
|
+
* Creates a new FlowEffect.
|
|
888
|
+
*
|
|
889
|
+
* @param apply - A side-effect function that receives a getter and a watcher to
|
|
890
|
+
* access and register dependencies on reactive observables and signals.
|
|
891
|
+
*
|
|
892
|
+
* @remarks
|
|
893
|
+
* The provided function is executed immediately in a tracked mode to collect dependencies.
|
|
894
|
+
* On subsequent executions, it runs in an untracked mode.
|
|
895
|
+
*
|
|
896
|
+
* @public
|
|
897
|
+
*/
|
|
898
|
+
constructor(apply) {
|
|
899
|
+
this._trackedExec = () => apply(this._trackedGet, this._trackedWatch);
|
|
900
|
+
this._untrackedExec = () => apply(this._untrackedGet, this._untrackedWatch);
|
|
901
|
+
this._exec();
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Disposes the effect, unregistering all its tracked dependencies.
|
|
905
|
+
*
|
|
906
|
+
* @remarks
|
|
907
|
+
* Once disposed, the effect must no longer be used. Trying to dispose an effect
|
|
908
|
+
* that is already disposed will throw an error.
|
|
909
|
+
*
|
|
910
|
+
* @public
|
|
911
|
+
*/
|
|
912
|
+
dispose() {
|
|
913
|
+
if (this._disposed) throw new Error("[PicoFlow] Effect is disposed");
|
|
914
|
+
Array.from(this._dependencies).forEach((dependency) => {
|
|
915
|
+
this._unregisterDependency(dependency);
|
|
916
|
+
});
|
|
917
|
+
this._disposed = true;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Indicates whether this effect has been disposed.
|
|
921
|
+
*
|
|
922
|
+
* @returns A boolean value that is true if the effect is disposed, false otherwise.
|
|
923
|
+
*
|
|
924
|
+
* @public
|
|
925
|
+
*/
|
|
926
|
+
get disposed() {
|
|
927
|
+
return this._disposed;
|
|
928
|
+
}
|
|
929
|
+
/* INTERNAL ------------------------------------------------------------ */
|
|
930
|
+
_disposed = false;
|
|
931
|
+
_initialized = false;
|
|
932
|
+
_dependencies = /* @__PURE__ */ new Set();
|
|
933
|
+
_trackedGet = (observable) => observable._getFrom(this);
|
|
934
|
+
_trackedWatch = (signal) => signal._watchFrom(this);
|
|
935
|
+
_untrackedGet = (observable) => observable.get();
|
|
936
|
+
_untrackedWatch = (signal) => signal._watch();
|
|
937
|
+
_trackedExec;
|
|
938
|
+
_untrackedExec;
|
|
939
|
+
/*@internal*/
|
|
940
|
+
_exec() {
|
|
941
|
+
if (this._disposed)
|
|
942
|
+
throw new Error("[PicoFlow] Effect is disposed");
|
|
943
|
+
if (this._initialized) this._untrackedExec();
|
|
944
|
+
else {
|
|
945
|
+
this._trackedExec();
|
|
946
|
+
this._initialized = true;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
/*@internal*/
|
|
950
|
+
_registerDependency(dependency) {
|
|
951
|
+
this._dependencies.add(dependency);
|
|
952
|
+
dependency._registerEffect(this);
|
|
953
|
+
}
|
|
954
|
+
/*@internal*/
|
|
955
|
+
_unregisterDependency(dependency) {
|
|
956
|
+
this._dependencies.delete(dependency);
|
|
957
|
+
dependency._unregisterEffect(this);
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
let FlowObservable$1 = class FlowObservable extends FlowSignal$1 {
|
|
962
|
+
/* INTERNAL -------------------------------------------*/
|
|
963
|
+
/*@internal*/
|
|
964
|
+
_value;
|
|
965
|
+
/*@internal*/
|
|
966
|
+
_getFrom(listener) {
|
|
967
|
+
listener._registerDependency(this);
|
|
968
|
+
return this.get();
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Subscribes a listener function to changes of the observable.
|
|
972
|
+
* The listener is executed immediately with the current value and on subsequent updates.
|
|
973
|
+
* @param listener - A callback function that receives the new value.
|
|
974
|
+
* @returns A disposer function to cancel the subscription.
|
|
975
|
+
*/
|
|
976
|
+
subscribe(listener) {
|
|
977
|
+
const effect = new FlowEffect$1((get) => {
|
|
978
|
+
listener(get(this));
|
|
979
|
+
});
|
|
980
|
+
return () => effect.dispose();
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
let FlowDerivation$1 = class FlowDerivation extends FlowObservable$1 {
|
|
985
|
+
/**
|
|
986
|
+
* Creates a new FlowDerivation.
|
|
987
|
+
* @param compute - A function that computes the derived value. It is provided with two parameters:
|
|
988
|
+
* a getter and a watcher that respect dependency tracking.
|
|
989
|
+
* @public
|
|
990
|
+
*/
|
|
991
|
+
constructor(compute) {
|
|
992
|
+
super();
|
|
993
|
+
this._initEager(compute);
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Gets the current derived value.
|
|
997
|
+
* @returns The current computed value.
|
|
998
|
+
* @remarks
|
|
999
|
+
* This method lazily initializes and updates the derivation if it is marked as dirty. It throws an error
|
|
1000
|
+
* if the derivation has been disposed.
|
|
1001
|
+
* @public
|
|
1002
|
+
*/
|
|
1003
|
+
get() {
|
|
1004
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
1005
|
+
this._initLazy();
|
|
1006
|
+
this._compute();
|
|
1007
|
+
return this._value;
|
|
1008
|
+
}
|
|
1009
|
+
/* INTERNAL --------------------------------------------------------- */
|
|
1010
|
+
_initialized = false;
|
|
1011
|
+
_dirty = false;
|
|
1012
|
+
_trackedGet = (observable) => observable._getFrom(this);
|
|
1013
|
+
_trackedWatch = (signal) => signal._watchFrom(this);
|
|
1014
|
+
_untrackedGet = (observable) => observable.get();
|
|
1015
|
+
_untrackedWatch = (signal) => signal._watch();
|
|
1016
|
+
_trackedCompute;
|
|
1017
|
+
_untrackedCompute;
|
|
1018
|
+
_initEager(compute) {
|
|
1019
|
+
this._trackedCompute = () => compute(this._trackedGet, this._trackedWatch);
|
|
1020
|
+
this._untrackedCompute = () => compute(this._untrackedGet, this._untrackedWatch);
|
|
1021
|
+
}
|
|
1022
|
+
_initLazy() {
|
|
1023
|
+
if (!this._initialized) {
|
|
1024
|
+
this._value = this._trackedCompute();
|
|
1025
|
+
this._initialized = true;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
/* @internal */
|
|
1029
|
+
_compute() {
|
|
1030
|
+
if (this._dirty) {
|
|
1031
|
+
const dependencies = [...this._dependencies];
|
|
1032
|
+
this._dependencies.clear();
|
|
1033
|
+
this._value = this._trackedCompute();
|
|
1034
|
+
const dependenciesToRemove = dependencies.filter(
|
|
1035
|
+
(dependency) => !this._dependencies.has(dependency)
|
|
1036
|
+
);
|
|
1037
|
+
dependenciesToRemove.forEach(
|
|
1038
|
+
(dependency) => dependency._unregisterDependency(this)
|
|
1039
|
+
);
|
|
1040
|
+
this._dirty = false;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
/* @internal */
|
|
1044
|
+
_notify() {
|
|
1045
|
+
this._dirty = true;
|
|
1046
|
+
super._notify();
|
|
1047
|
+
}
|
|
1048
|
+
/* @internal */
|
|
1049
|
+
_watch() {
|
|
1050
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
1051
|
+
this._initLazy();
|
|
1052
|
+
this._compute();
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
const IS_DEV = false;
|
|
1057
|
+
const equalFn = (a, b) => a === b;
|
|
1058
|
+
const signalOptions = {
|
|
1059
|
+
equals: equalFn
|
|
1060
|
+
};
|
|
1061
|
+
let runEffects = runQueue;
|
|
1062
|
+
const STALE = 1;
|
|
1063
|
+
const PENDING = 2;
|
|
1064
|
+
const UNOWNED = {
|
|
1065
|
+
};
|
|
1066
|
+
const NO_INIT = {};
|
|
1067
|
+
var Owner = null;
|
|
1068
|
+
let Transition = null;
|
|
1069
|
+
let ExternalSourceConfig = null;
|
|
1070
|
+
let Listener = null;
|
|
1071
|
+
let Updates = null;
|
|
1072
|
+
let Effects = null;
|
|
1073
|
+
let ExecCount = 0;
|
|
1074
|
+
function createSignal(value, options) {
|
|
1075
|
+
options = options ? Object.assign({}, signalOptions, options) : signalOptions;
|
|
1076
|
+
const s = {
|
|
1077
|
+
value,
|
|
1078
|
+
observers: null,
|
|
1079
|
+
observerSlots: null,
|
|
1080
|
+
comparator: options.equals || undefined
|
|
1081
|
+
};
|
|
1082
|
+
const setter = value => {
|
|
1083
|
+
if (typeof value === "function") {
|
|
1084
|
+
value = value(s.value);
|
|
1085
|
+
}
|
|
1086
|
+
return writeSignal(s, value);
|
|
1087
|
+
};
|
|
1088
|
+
return [readSignal.bind(s), setter];
|
|
1089
|
+
}
|
|
1090
|
+
function createComputed(fn, value, options) {
|
|
1091
|
+
const c = createComputation(fn, value, true, STALE);
|
|
1092
|
+
updateComputation(c);
|
|
1093
|
+
}
|
|
1094
|
+
function createEffect(fn, value, options) {
|
|
1095
|
+
runEffects = runUserEffects;
|
|
1096
|
+
const c = createComputation(fn, value, false, STALE);
|
|
1097
|
+
c.user = true;
|
|
1098
|
+
Effects ? Effects.push(c) : updateComputation(c);
|
|
1099
|
+
}
|
|
1100
|
+
function createMemo(fn, value, options) {
|
|
1101
|
+
options = options ? Object.assign({}, signalOptions, options) : signalOptions;
|
|
1102
|
+
const c = createComputation(fn, value, true, 0);
|
|
1103
|
+
c.observers = null;
|
|
1104
|
+
c.observerSlots = null;
|
|
1105
|
+
c.comparator = options.equals || undefined;
|
|
1106
|
+
updateComputation(c);
|
|
1107
|
+
return readSignal.bind(c);
|
|
1108
|
+
}
|
|
1109
|
+
function isPromise(v) {
|
|
1110
|
+
return v && typeof v === "object" && "then" in v;
|
|
1111
|
+
}
|
|
1112
|
+
function createResource(pSource, pFetcher, pOptions) {
|
|
1113
|
+
let source;
|
|
1114
|
+
let fetcher;
|
|
1115
|
+
let options;
|
|
1116
|
+
{
|
|
1117
|
+
source = true;
|
|
1118
|
+
fetcher = pSource;
|
|
1119
|
+
options = {};
|
|
1120
|
+
}
|
|
1121
|
+
let pr = null,
|
|
1122
|
+
initP = NO_INIT,
|
|
1123
|
+
scheduled = false,
|
|
1124
|
+
resolved = "initialValue" in options,
|
|
1125
|
+
dynamic = typeof source === "function" && createMemo(source);
|
|
1126
|
+
const contexts = new Set(),
|
|
1127
|
+
[value, setValue] = (options.storage || createSignal)(options.initialValue),
|
|
1128
|
+
[error, setError] = createSignal(undefined),
|
|
1129
|
+
[track, trigger] = createSignal(undefined, {
|
|
1130
|
+
equals: false
|
|
1131
|
+
}),
|
|
1132
|
+
[state, setState] = createSignal(resolved ? "ready" : "unresolved");
|
|
1133
|
+
function loadEnd(p, v, error, key) {
|
|
1134
|
+
if (pr === p) {
|
|
1135
|
+
pr = null;
|
|
1136
|
+
key !== undefined && (resolved = true);
|
|
1137
|
+
if ((p === initP || v === initP) && options.onHydrated) queueMicrotask(() => options.onHydrated(key, {
|
|
1138
|
+
value: v
|
|
1139
|
+
}));
|
|
1140
|
+
initP = NO_INIT;
|
|
1141
|
+
completeLoad(v, error);
|
|
1142
|
+
}
|
|
1143
|
+
return v;
|
|
1144
|
+
}
|
|
1145
|
+
function completeLoad(v, err) {
|
|
1146
|
+
runUpdates(() => {
|
|
1147
|
+
if (err === undefined) setValue(() => v);
|
|
1148
|
+
setState(err !== undefined ? "errored" : resolved ? "ready" : "unresolved");
|
|
1149
|
+
setError(err);
|
|
1150
|
+
for (const c of contexts.keys()) c.decrement();
|
|
1151
|
+
contexts.clear();
|
|
1152
|
+
}, false);
|
|
1153
|
+
}
|
|
1154
|
+
function read() {
|
|
1155
|
+
const c = SuspenseContext,
|
|
1156
|
+
v = value(),
|
|
1157
|
+
err = error();
|
|
1158
|
+
if (err !== undefined && !pr) throw err;
|
|
1159
|
+
if (Listener && !Listener.user && c) {
|
|
1160
|
+
createComputed(() => {
|
|
1161
|
+
track();
|
|
1162
|
+
if (pr) {
|
|
1163
|
+
if (c.resolved && Transition) ;else if (!contexts.has(c)) {
|
|
1164
|
+
c.increment();
|
|
1165
|
+
contexts.add(c);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
return v;
|
|
1171
|
+
}
|
|
1172
|
+
function load(refetching = true) {
|
|
1173
|
+
if (refetching !== false && scheduled) return;
|
|
1174
|
+
scheduled = false;
|
|
1175
|
+
const lookup = dynamic ? dynamic() : source;
|
|
1176
|
+
if (lookup == null || lookup === false) {
|
|
1177
|
+
loadEnd(pr, untrack(value));
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
let error;
|
|
1181
|
+
const p = initP !== NO_INIT ? initP : untrack(() => {
|
|
1182
|
+
try {
|
|
1183
|
+
return fetcher(lookup, {
|
|
1184
|
+
value: value(),
|
|
1185
|
+
refetching
|
|
1186
|
+
});
|
|
1187
|
+
} catch (fetcherError) {
|
|
1188
|
+
error = fetcherError;
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
if (error !== undefined) {
|
|
1192
|
+
loadEnd(pr, undefined, castError(error), lookup);
|
|
1193
|
+
return;
|
|
1194
|
+
} else if (!isPromise(p)) {
|
|
1195
|
+
loadEnd(pr, p, undefined, lookup);
|
|
1196
|
+
return p;
|
|
1197
|
+
}
|
|
1198
|
+
pr = p;
|
|
1199
|
+
if ("v" in p) {
|
|
1200
|
+
if (p.s === 1) loadEnd(pr, p.v, undefined, lookup);else loadEnd(pr, undefined, castError(p.v), lookup);
|
|
1201
|
+
return p;
|
|
1202
|
+
}
|
|
1203
|
+
scheduled = true;
|
|
1204
|
+
queueMicrotask(() => scheduled = false);
|
|
1205
|
+
runUpdates(() => {
|
|
1206
|
+
setState(resolved ? "refreshing" : "pending");
|
|
1207
|
+
trigger();
|
|
1208
|
+
}, false);
|
|
1209
|
+
return p.then(v => loadEnd(p, v, undefined, lookup), e => loadEnd(p, undefined, castError(e), lookup));
|
|
1210
|
+
}
|
|
1211
|
+
Object.defineProperties(read, {
|
|
1212
|
+
state: {
|
|
1213
|
+
get: () => state()
|
|
1214
|
+
},
|
|
1215
|
+
error: {
|
|
1216
|
+
get: () => error()
|
|
1217
|
+
},
|
|
1218
|
+
loading: {
|
|
1219
|
+
get() {
|
|
1220
|
+
const s = state();
|
|
1221
|
+
return s === "pending" || s === "refreshing";
|
|
1222
|
+
}
|
|
1223
|
+
},
|
|
1224
|
+
latest: {
|
|
1225
|
+
get() {
|
|
1226
|
+
if (!resolved) return read();
|
|
1227
|
+
const err = error();
|
|
1228
|
+
if (err && !pr) throw err;
|
|
1229
|
+
return value();
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
let owner = Owner;
|
|
1234
|
+
if (dynamic) createComputed(() => (owner = Owner, load(false)));else load(false);
|
|
1235
|
+
return [read, {
|
|
1236
|
+
refetch: info => runWithOwner(owner, () => load(info)),
|
|
1237
|
+
mutate: setValue
|
|
1238
|
+
}];
|
|
1239
|
+
}
|
|
1240
|
+
function untrack(fn) {
|
|
1241
|
+
if (Listener === null) return fn();
|
|
1242
|
+
const listener = Listener;
|
|
1243
|
+
Listener = null;
|
|
1244
|
+
try {
|
|
1245
|
+
if (ExternalSourceConfig) ;
|
|
1246
|
+
return fn();
|
|
1247
|
+
} finally {
|
|
1248
|
+
Listener = listener;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
function onMount(fn) {
|
|
1252
|
+
createEffect(() => untrack(fn));
|
|
1253
|
+
}
|
|
1254
|
+
function onCleanup(fn) {
|
|
1255
|
+
if (Owner === null) ;else if (Owner.cleanups === null) Owner.cleanups = [fn];else Owner.cleanups.push(fn);
|
|
1256
|
+
return fn;
|
|
1257
|
+
}
|
|
1258
|
+
function runWithOwner(o, fn) {
|
|
1259
|
+
const prev = Owner;
|
|
1260
|
+
const prevListener = Listener;
|
|
1261
|
+
Owner = o;
|
|
1262
|
+
Listener = null;
|
|
1263
|
+
try {
|
|
1264
|
+
return runUpdates(fn, true);
|
|
1265
|
+
} catch (err) {
|
|
1266
|
+
handleError(err);
|
|
1267
|
+
} finally {
|
|
1268
|
+
Owner = prev;
|
|
1269
|
+
Listener = prevListener;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
|
|
1273
|
+
let SuspenseContext;
|
|
1274
|
+
function readSignal() {
|
|
1275
|
+
if (this.sources && (this.state)) {
|
|
1276
|
+
if ((this.state) === STALE) updateComputation(this);else {
|
|
1277
|
+
const updates = Updates;
|
|
1278
|
+
Updates = null;
|
|
1279
|
+
runUpdates(() => lookUpstream(this), false);
|
|
1280
|
+
Updates = updates;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
if (Listener) {
|
|
1284
|
+
const sSlot = this.observers ? this.observers.length : 0;
|
|
1285
|
+
if (!Listener.sources) {
|
|
1286
|
+
Listener.sources = [this];
|
|
1287
|
+
Listener.sourceSlots = [sSlot];
|
|
1288
|
+
} else {
|
|
1289
|
+
Listener.sources.push(this);
|
|
1290
|
+
Listener.sourceSlots.push(sSlot);
|
|
1291
|
+
}
|
|
1292
|
+
if (!this.observers) {
|
|
1293
|
+
this.observers = [Listener];
|
|
1294
|
+
this.observerSlots = [Listener.sources.length - 1];
|
|
1295
|
+
} else {
|
|
1296
|
+
this.observers.push(Listener);
|
|
1297
|
+
this.observerSlots.push(Listener.sources.length - 1);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
return this.value;
|
|
1301
|
+
}
|
|
1302
|
+
function writeSignal(node, value, isComp) {
|
|
1303
|
+
let current = node.value;
|
|
1304
|
+
if (!node.comparator || !node.comparator(current, value)) {
|
|
1305
|
+
node.value = value;
|
|
1306
|
+
if (node.observers && node.observers.length) {
|
|
1307
|
+
runUpdates(() => {
|
|
1308
|
+
for (let i = 0; i < node.observers.length; i += 1) {
|
|
1309
|
+
const o = node.observers[i];
|
|
1310
|
+
const TransitionRunning = Transition && Transition.running;
|
|
1311
|
+
if (TransitionRunning && Transition.disposed.has(o)) ;
|
|
1312
|
+
if (TransitionRunning ? !o.tState : !o.state) {
|
|
1313
|
+
if (o.pure) Updates.push(o);else Effects.push(o);
|
|
1314
|
+
if (o.observers) markDownstream(o);
|
|
1315
|
+
}
|
|
1316
|
+
if (!TransitionRunning) o.state = STALE;
|
|
1317
|
+
}
|
|
1318
|
+
if (Updates.length > 10e5) {
|
|
1319
|
+
Updates = [];
|
|
1320
|
+
if (IS_DEV) ;
|
|
1321
|
+
throw new Error();
|
|
1322
|
+
}
|
|
1323
|
+
}, false);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
return value;
|
|
1327
|
+
}
|
|
1328
|
+
function updateComputation(node) {
|
|
1329
|
+
if (!node.fn) return;
|
|
1330
|
+
cleanNode(node);
|
|
1331
|
+
const time = ExecCount;
|
|
1332
|
+
runComputation(node, node.value, time);
|
|
1333
|
+
}
|
|
1334
|
+
function runComputation(node, value, time) {
|
|
1335
|
+
let nextValue;
|
|
1336
|
+
const owner = Owner,
|
|
1337
|
+
listener = Listener;
|
|
1338
|
+
Listener = Owner = node;
|
|
1339
|
+
try {
|
|
1340
|
+
nextValue = node.fn(value);
|
|
1341
|
+
} catch (err) {
|
|
1342
|
+
if (node.pure) {
|
|
1343
|
+
{
|
|
1344
|
+
node.state = STALE;
|
|
1345
|
+
node.owned && node.owned.forEach(cleanNode);
|
|
1346
|
+
node.owned = null;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
node.updatedAt = time + 1;
|
|
1350
|
+
return handleError(err);
|
|
1351
|
+
} finally {
|
|
1352
|
+
Listener = listener;
|
|
1353
|
+
Owner = owner;
|
|
1354
|
+
}
|
|
1355
|
+
if (!node.updatedAt || node.updatedAt <= time) {
|
|
1356
|
+
if (node.updatedAt != null && "observers" in node) {
|
|
1357
|
+
writeSignal(node, nextValue);
|
|
1358
|
+
} else node.value = nextValue;
|
|
1359
|
+
node.updatedAt = time;
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
function createComputation(fn, init, pure, state = STALE, options) {
|
|
1363
|
+
const c = {
|
|
1364
|
+
fn,
|
|
1365
|
+
state: state,
|
|
1366
|
+
updatedAt: null,
|
|
1367
|
+
owned: null,
|
|
1368
|
+
sources: null,
|
|
1369
|
+
sourceSlots: null,
|
|
1370
|
+
cleanups: null,
|
|
1371
|
+
value: init,
|
|
1372
|
+
owner: Owner,
|
|
1373
|
+
context: Owner ? Owner.context : null,
|
|
1374
|
+
pure
|
|
1375
|
+
};
|
|
1376
|
+
if (Owner === null) ;else if (Owner !== UNOWNED) {
|
|
1377
|
+
{
|
|
1378
|
+
if (!Owner.owned) Owner.owned = [c];else Owner.owned.push(c);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
return c;
|
|
1382
|
+
}
|
|
1383
|
+
function runTop(node) {
|
|
1384
|
+
if ((node.state) === 0) return;
|
|
1385
|
+
if ((node.state) === PENDING) return lookUpstream(node);
|
|
1386
|
+
if (node.suspense && untrack(node.suspense.inFallback)) return node.suspense.effects.push(node);
|
|
1387
|
+
const ancestors = [node];
|
|
1388
|
+
while ((node = node.owner) && (!node.updatedAt || node.updatedAt < ExecCount)) {
|
|
1389
|
+
if (node.state) ancestors.push(node);
|
|
1390
|
+
}
|
|
1391
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
1392
|
+
node = ancestors[i];
|
|
1393
|
+
if ((node.state) === STALE) {
|
|
1394
|
+
updateComputation(node);
|
|
1395
|
+
} else if ((node.state) === PENDING) {
|
|
1396
|
+
const updates = Updates;
|
|
1397
|
+
Updates = null;
|
|
1398
|
+
runUpdates(() => lookUpstream(node, ancestors[0]), false);
|
|
1399
|
+
Updates = updates;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
function runUpdates(fn, init) {
|
|
1404
|
+
if (Updates) return fn();
|
|
1405
|
+
let wait = false;
|
|
1406
|
+
if (!init) Updates = [];
|
|
1407
|
+
if (Effects) wait = true;else Effects = [];
|
|
1408
|
+
ExecCount++;
|
|
1409
|
+
try {
|
|
1410
|
+
const res = fn();
|
|
1411
|
+
completeUpdates(wait);
|
|
1412
|
+
return res;
|
|
1413
|
+
} catch (err) {
|
|
1414
|
+
if (!wait) Effects = null;
|
|
1415
|
+
Updates = null;
|
|
1416
|
+
handleError(err);
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
function completeUpdates(wait) {
|
|
1420
|
+
if (Updates) {
|
|
1421
|
+
runQueue(Updates);
|
|
1422
|
+
Updates = null;
|
|
1423
|
+
}
|
|
1424
|
+
if (wait) return;
|
|
1425
|
+
const e = Effects;
|
|
1426
|
+
Effects = null;
|
|
1427
|
+
if (e.length) runUpdates(() => runEffects(e), false);
|
|
1428
|
+
}
|
|
1429
|
+
function runQueue(queue) {
|
|
1430
|
+
for (let i = 0; i < queue.length; i++) runTop(queue[i]);
|
|
1431
|
+
}
|
|
1432
|
+
function runUserEffects(queue) {
|
|
1433
|
+
let i,
|
|
1434
|
+
userLength = 0;
|
|
1435
|
+
for (i = 0; i < queue.length; i++) {
|
|
1436
|
+
const e = queue[i];
|
|
1437
|
+
if (!e.user) runTop(e);else queue[userLength++] = e;
|
|
1438
|
+
}
|
|
1439
|
+
for (i = 0; i < userLength; i++) runTop(queue[i]);
|
|
1440
|
+
}
|
|
1441
|
+
function lookUpstream(node, ignore) {
|
|
1442
|
+
node.state = 0;
|
|
1443
|
+
for (let i = 0; i < node.sources.length; i += 1) {
|
|
1444
|
+
const source = node.sources[i];
|
|
1445
|
+
if (source.sources) {
|
|
1446
|
+
const state = source.state;
|
|
1447
|
+
if (state === STALE) {
|
|
1448
|
+
if (source !== ignore && (!source.updatedAt || source.updatedAt < ExecCount)) runTop(source);
|
|
1449
|
+
} else if (state === PENDING) lookUpstream(source, ignore);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
function markDownstream(node) {
|
|
1454
|
+
for (let i = 0; i < node.observers.length; i += 1) {
|
|
1455
|
+
const o = node.observers[i];
|
|
1456
|
+
if (!o.state) {
|
|
1457
|
+
o.state = PENDING;
|
|
1458
|
+
if (o.pure) Updates.push(o);else Effects.push(o);
|
|
1459
|
+
o.observers && markDownstream(o);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
function cleanNode(node) {
|
|
1464
|
+
let i;
|
|
1465
|
+
if (node.sources) {
|
|
1466
|
+
while (node.sources.length) {
|
|
1467
|
+
const source = node.sources.pop(),
|
|
1468
|
+
index = node.sourceSlots.pop(),
|
|
1469
|
+
obs = source.observers;
|
|
1470
|
+
if (obs && obs.length) {
|
|
1471
|
+
const n = obs.pop(),
|
|
1472
|
+
s = source.observerSlots.pop();
|
|
1473
|
+
if (index < obs.length) {
|
|
1474
|
+
n.sourceSlots[s] = index;
|
|
1475
|
+
obs[index] = n;
|
|
1476
|
+
source.observerSlots[index] = s;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
if (node.tOwned) {
|
|
1482
|
+
for (i = node.tOwned.length - 1; i >= 0; i--) cleanNode(node.tOwned[i]);
|
|
1483
|
+
delete node.tOwned;
|
|
1484
|
+
}
|
|
1485
|
+
if (node.owned) {
|
|
1486
|
+
for (i = node.owned.length - 1; i >= 0; i--) cleanNode(node.owned[i]);
|
|
1487
|
+
node.owned = null;
|
|
1488
|
+
}
|
|
1489
|
+
if (node.cleanups) {
|
|
1490
|
+
for (i = node.cleanups.length - 1; i >= 0; i--) node.cleanups[i]();
|
|
1491
|
+
node.cleanups = null;
|
|
1492
|
+
}
|
|
1493
|
+
node.state = 0;
|
|
1494
|
+
}
|
|
1495
|
+
function castError(err) {
|
|
1496
|
+
if (err instanceof Error) return err;
|
|
1497
|
+
return new Error(typeof err === "string" ? err : "Unknown error", {
|
|
1498
|
+
cause: err
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
function handleError(err, owner = Owner) {
|
|
1502
|
+
const error = castError(err);
|
|
1503
|
+
throw error;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
class SolidState {
|
|
1507
|
+
/**
|
|
1508
|
+
* Returns the current value.
|
|
1509
|
+
*/
|
|
1510
|
+
get;
|
|
1511
|
+
/**
|
|
1512
|
+
* Sets the value or updates it using a getter function.
|
|
1513
|
+
*/
|
|
1514
|
+
set;
|
|
1515
|
+
/**
|
|
1516
|
+
* Creates a new SolidState with the given initial value.
|
|
1517
|
+
* @param initialValue - The initial value.
|
|
1518
|
+
*/
|
|
1519
|
+
constructor(initialValue) {
|
|
1520
|
+
const [get, set] = createSignal(initialValue);
|
|
1521
|
+
this.get = get;
|
|
1522
|
+
this.set = set;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
class SolidDerivation {
|
|
1526
|
+
/**
|
|
1527
|
+
* Returns the current derived value.
|
|
1528
|
+
*/
|
|
1529
|
+
get;
|
|
1530
|
+
/**
|
|
1531
|
+
* Creates a new SolidDerivation from a getter function or value.
|
|
1532
|
+
* @param calculator - The getter function or value.
|
|
1533
|
+
*/
|
|
1534
|
+
constructor(calculator) {
|
|
1535
|
+
const get = createMemo(calculator);
|
|
1536
|
+
this.get = get;
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
class SolidResource {
|
|
1540
|
+
/**
|
|
1541
|
+
* Returns the current value (or undefined if not yet loaded).
|
|
1542
|
+
*/
|
|
1543
|
+
get;
|
|
1544
|
+
/**
|
|
1545
|
+
* Returns the current resource state.
|
|
1546
|
+
*/
|
|
1547
|
+
state;
|
|
1548
|
+
/**
|
|
1549
|
+
* Returns the latest successfully loaded value (or undefined).
|
|
1550
|
+
*/
|
|
1551
|
+
latest;
|
|
1552
|
+
/**
|
|
1553
|
+
* Triggers a refetch of the resource.
|
|
1554
|
+
*/
|
|
1555
|
+
refetch;
|
|
1556
|
+
/**
|
|
1557
|
+
* Creates a new SolidResource from a fetcher function.
|
|
1558
|
+
* @param fetcher - The async fetcher function.
|
|
1559
|
+
*/
|
|
1560
|
+
constructor(fetcher) {
|
|
1561
|
+
const [get, set] = createResource(fetcher);
|
|
1562
|
+
this.get = get;
|
|
1563
|
+
this.state = () => get.state;
|
|
1564
|
+
this.latest = () => get.latest;
|
|
1565
|
+
this.refetch = () => set.refetch();
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
function fromSync(state) {
|
|
1570
|
+
const solidState = new SolidState(state.get());
|
|
1571
|
+
let fx;
|
|
1572
|
+
onMount(() => {
|
|
1573
|
+
fx = new FlowEffect$1((get) => {
|
|
1574
|
+
const value = get(state);
|
|
1575
|
+
solidState.set(() => value);
|
|
1576
|
+
});
|
|
1577
|
+
});
|
|
1578
|
+
onCleanup(() => fx.dispose());
|
|
1579
|
+
return solidState;
|
|
1580
|
+
}
|
|
1581
|
+
function fromAsync(derivation) {
|
|
1582
|
+
const solidResource = new SolidResource(async () => {
|
|
1583
|
+
const value = await derivation.get();
|
|
1584
|
+
return value;
|
|
1585
|
+
});
|
|
1586
|
+
let fx;
|
|
1587
|
+
onMount(() => {
|
|
1588
|
+
fx = new FlowEffect$1(async (get) => {
|
|
1589
|
+
await get(derivation);
|
|
1590
|
+
solidResource.refetch();
|
|
1591
|
+
});
|
|
1592
|
+
});
|
|
1593
|
+
onCleanup(() => fx.dispose());
|
|
1594
|
+
return solidResource;
|
|
1595
|
+
}
|
|
1596
|
+
function shallowFrom(flow) {
|
|
1597
|
+
const initialValue = flow.get();
|
|
1598
|
+
const isAsync = initialValue instanceof Promise;
|
|
1599
|
+
if (isAsync) {
|
|
1600
|
+
return fromAsync(flow);
|
|
1601
|
+
}
|
|
1602
|
+
return fromSync(flow);
|
|
1603
|
+
}
|
|
1604
|
+
function deepFrom(getter) {
|
|
1605
|
+
const derivation = new FlowDerivation$1((get) => {
|
|
1606
|
+
return getter(get);
|
|
1607
|
+
});
|
|
1608
|
+
const initialValue = derivation.get();
|
|
1609
|
+
const isAsync = initialValue instanceof Promise;
|
|
1610
|
+
if (isAsync) {
|
|
1611
|
+
return fromAsync(derivation);
|
|
1612
|
+
}
|
|
1613
|
+
return fromSync(derivation);
|
|
1614
|
+
}
|
|
1615
|
+
function from(flow) {
|
|
1616
|
+
if (flow instanceof FlowObservable$1) {
|
|
1617
|
+
return shallowFrom(flow);
|
|
1618
|
+
}
|
|
1619
|
+
return deepFrom(flow);
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
export { FlowArray, FlowConstant, FlowDerivation, FlowEffect, FlowMap, FlowObservable, FlowResource, FlowResourceAsync, FlowSignal, FlowState, FlowStream, FlowStreamAsync, SolidDerivation, SolidResource, SolidState, array, constant, derivation, effect, from, isDisposable, map, resource, resourceAsync, signal, state, stream, streamAsync };
|