@ersbeth/picoflow 0.2.2 → 0.2.4
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 +136 -300
- 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/vite.config.ts +3 -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,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { createSignal, createResource, createMemo, onMount, onCleanup } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
class FlowSignal {
|
|
2
4
|
/**
|
|
3
5
|
* Triggers the FlowSignal.
|
|
4
6
|
* Notifies all registered listeners and schedules execution of associated effects.
|
|
@@ -93,9 +95,9 @@ let FlowSignal$1 = class FlowSignal {
|
|
|
93
95
|
_unregisterEffect(effect) {
|
|
94
96
|
this._effects.delete(effect);
|
|
95
97
|
}
|
|
96
|
-
}
|
|
98
|
+
}
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
class FlowEffect {
|
|
99
101
|
/**
|
|
100
102
|
* Creates a new FlowEffect.
|
|
101
103
|
*
|
|
@@ -169,9 +171,9 @@ let FlowEffect$1 = class FlowEffect {
|
|
|
169
171
|
this._dependencies.delete(dependency);
|
|
170
172
|
dependency._unregisterEffect(this);
|
|
171
173
|
}
|
|
172
|
-
}
|
|
174
|
+
}
|
|
173
175
|
|
|
174
|
-
|
|
176
|
+
class FlowObservable extends FlowSignal {
|
|
175
177
|
/* INTERNAL -------------------------------------------*/
|
|
176
178
|
/*@internal*/
|
|
177
179
|
_value;
|
|
@@ -187,14 +189,14 @@ let FlowObservable$1 = class FlowObservable extends FlowSignal$1 {
|
|
|
187
189
|
* @returns A disposer function to cancel the subscription.
|
|
188
190
|
*/
|
|
189
191
|
subscribe(listener) {
|
|
190
|
-
const effect = new FlowEffect
|
|
192
|
+
const effect = new FlowEffect((get) => {
|
|
191
193
|
listener(get(this));
|
|
192
194
|
});
|
|
193
195
|
return () => effect.dispose();
|
|
194
196
|
}
|
|
195
|
-
}
|
|
197
|
+
}
|
|
196
198
|
|
|
197
|
-
class FlowConstant extends FlowObservable
|
|
199
|
+
class FlowConstant extends FlowObservable {
|
|
198
200
|
/**
|
|
199
201
|
* Creates a new FlowConstant instance.
|
|
200
202
|
*
|
|
@@ -264,7 +266,7 @@ class FlowState extends FlowConstant {
|
|
|
264
266
|
}
|
|
265
267
|
}
|
|
266
268
|
|
|
267
|
-
|
|
269
|
+
class FlowDerivation extends FlowObservable {
|
|
268
270
|
/**
|
|
269
271
|
* Creates a new FlowDerivation.
|
|
270
272
|
* @param compute - A function that computes the derived value. It is provided with two parameters:
|
|
@@ -334,288 +336,6 @@ let FlowDerivation$1 = class FlowDerivation extends FlowObservable$1 {
|
|
|
334
336
|
this._initLazy();
|
|
335
337
|
this._compute();
|
|
336
338
|
}
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
class FlowSignal {
|
|
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
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
class FlowEffect {
|
|
437
|
-
/**
|
|
438
|
-
* Creates a new FlowEffect.
|
|
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.
|
|
442
|
-
*
|
|
443
|
-
* @remarks
|
|
444
|
-
* The provided function is executed immediately in a tracked mode to collect dependencies.
|
|
445
|
-
* On subsequent executions, it runs in an untracked mode.
|
|
446
|
-
*
|
|
447
|
-
* @public
|
|
448
|
-
*/
|
|
449
|
-
constructor(apply) {
|
|
450
|
-
this._trackedExec = () => apply(this._trackedGet, this._trackedWatch);
|
|
451
|
-
this._untrackedExec = () => apply(this._untrackedGet, this._untrackedWatch);
|
|
452
|
-
this._exec();
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Disposes the effect, unregistering all its tracked dependencies.
|
|
456
|
-
*
|
|
457
|
-
* @remarks
|
|
458
|
-
* Once disposed, the effect must no longer be used. Trying to dispose an effect
|
|
459
|
-
* that is already disposed will throw an error.
|
|
460
|
-
*
|
|
461
|
-
* @public
|
|
462
|
-
*/
|
|
463
|
-
dispose() {
|
|
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
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Indicates whether this effect has been disposed.
|
|
472
|
-
*
|
|
473
|
-
* @returns A boolean value that is true if the effect is disposed, false otherwise.
|
|
474
|
-
*
|
|
475
|
-
* @public
|
|
476
|
-
*/
|
|
477
|
-
get disposed() {
|
|
478
|
-
return this._disposed;
|
|
479
|
-
}
|
|
480
|
-
/* INTERNAL ------------------------------------------------------------ */
|
|
481
|
-
_disposed = false;
|
|
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();
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Subscribes a listener function to changes of the observable.
|
|
523
|
-
* The listener is executed immediately with the current value and on subsequent updates.
|
|
524
|
-
* @param listener - A callback function that receives the new value.
|
|
525
|
-
* @returns A disposer function to cancel the subscription.
|
|
526
|
-
*/
|
|
527
|
-
subscribe(listener) {
|
|
528
|
-
const effect = new FlowEffect((get) => {
|
|
529
|
-
listener(get(this));
|
|
530
|
-
});
|
|
531
|
-
return () => effect.dispose();
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
class FlowDerivation extends FlowObservable {
|
|
536
|
-
/**
|
|
537
|
-
* Creates a new FlowDerivation.
|
|
538
|
-
* @param compute - A function that computes the derived value. It is provided with two parameters:
|
|
539
|
-
* a getter and a watcher that respect dependency tracking.
|
|
540
|
-
* @public
|
|
541
|
-
*/
|
|
542
|
-
constructor(compute) {
|
|
543
|
-
super();
|
|
544
|
-
this._initEager(compute);
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Gets the current derived value.
|
|
548
|
-
* @returns The current computed value.
|
|
549
|
-
* @remarks
|
|
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
339
|
}
|
|
620
340
|
|
|
621
341
|
function isDisposable(obj) {
|
|
@@ -683,7 +403,7 @@ class FlowMap extends FlowState {
|
|
|
683
403
|
}
|
|
684
404
|
}
|
|
685
405
|
|
|
686
|
-
class FlowStream extends FlowObservable
|
|
406
|
+
class FlowStream extends FlowObservable {
|
|
687
407
|
/**
|
|
688
408
|
* Creates a new FlowStream.
|
|
689
409
|
* @param updater - A function that receives a setter to update the stream's value.
|
|
@@ -727,7 +447,7 @@ class FlowStream extends FlowObservable$1 {
|
|
|
727
447
|
}
|
|
728
448
|
}
|
|
729
449
|
|
|
730
|
-
class FlowStreamAsync extends FlowObservable
|
|
450
|
+
class FlowStreamAsync extends FlowObservable {
|
|
731
451
|
/**
|
|
732
452
|
* Creates a new asynchronous FlowStream.
|
|
733
453
|
* @param updater - A function that receives a setter to update the stream's value.
|
|
@@ -785,7 +505,7 @@ class FlowStreamAsync extends FlowObservable$1 {
|
|
|
785
505
|
}
|
|
786
506
|
}
|
|
787
507
|
|
|
788
|
-
class FlowResource extends FlowObservable
|
|
508
|
+
class FlowResource extends FlowObservable {
|
|
789
509
|
/**
|
|
790
510
|
* Creates a new FlowResource.
|
|
791
511
|
* @param fetch - An asynchronous function that retrieves the resource's value.
|
|
@@ -826,7 +546,7 @@ class FlowResource extends FlowObservable$1 {
|
|
|
826
546
|
_fetch;
|
|
827
547
|
}
|
|
828
548
|
|
|
829
|
-
class FlowResourceAsync extends FlowObservable
|
|
549
|
+
class FlowResourceAsync extends FlowObservable {
|
|
830
550
|
/**
|
|
831
551
|
* Creates a new FlowResource.
|
|
832
552
|
* @param fetch - An asynchronous function that retrieves the resource's value.
|
|
@@ -865,7 +585,7 @@ class FlowResourceAsync extends FlowObservable$1 {
|
|
|
865
585
|
_fetch;
|
|
866
586
|
}
|
|
867
587
|
|
|
868
|
-
class FlowArray extends FlowObservable
|
|
588
|
+
class FlowArray extends FlowObservable {
|
|
869
589
|
/**
|
|
870
590
|
* Last action performed on the FlowArray.
|
|
871
591
|
* @public
|
|
@@ -1032,7 +752,7 @@ class FlowArray extends FlowObservable$1 {
|
|
|
1032
752
|
}
|
|
1033
753
|
|
|
1034
754
|
function signal() {
|
|
1035
|
-
return new FlowSignal
|
|
755
|
+
return new FlowSignal();
|
|
1036
756
|
}
|
|
1037
757
|
function constant(value) {
|
|
1038
758
|
return new FlowConstant(value);
|
|
@@ -1053,10 +773,10 @@ function streamAsync(updater) {
|
|
|
1053
773
|
return new FlowStreamAsync(updater);
|
|
1054
774
|
}
|
|
1055
775
|
function derivation(fn) {
|
|
1056
|
-
return new FlowDerivation
|
|
776
|
+
return new FlowDerivation(fn);
|
|
1057
777
|
}
|
|
1058
778
|
function effect(fn) {
|
|
1059
|
-
return new FlowEffect
|
|
779
|
+
return new FlowEffect(fn);
|
|
1060
780
|
}
|
|
1061
781
|
function map(initial) {
|
|
1062
782
|
return new FlowMap(
|
|
@@ -1067,4 +787,120 @@ function array(initial) {
|
|
|
1067
787
|
return new FlowArray(initial);
|
|
1068
788
|
}
|
|
1069
789
|
|
|
1070
|
-
|
|
790
|
+
class SolidState {
|
|
791
|
+
/**
|
|
792
|
+
* Returns the current value.
|
|
793
|
+
*/
|
|
794
|
+
get;
|
|
795
|
+
/**
|
|
796
|
+
* Sets the value or updates it using a getter function.
|
|
797
|
+
*/
|
|
798
|
+
set;
|
|
799
|
+
/**
|
|
800
|
+
* Creates a new SolidState with the given initial value.
|
|
801
|
+
* @param initialValue - The initial value.
|
|
802
|
+
*/
|
|
803
|
+
constructor(initialValue) {
|
|
804
|
+
const [get, set] = createSignal(initialValue);
|
|
805
|
+
this.get = get;
|
|
806
|
+
this.set = set;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
class SolidDerivation {
|
|
810
|
+
/**
|
|
811
|
+
* Returns the current derived value.
|
|
812
|
+
*/
|
|
813
|
+
get;
|
|
814
|
+
/**
|
|
815
|
+
* Creates a new SolidDerivation from a getter function or value.
|
|
816
|
+
* @param calculator - The getter function or value.
|
|
817
|
+
*/
|
|
818
|
+
constructor(calculator) {
|
|
819
|
+
const get = createMemo(calculator);
|
|
820
|
+
this.get = get;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
class SolidResource {
|
|
824
|
+
/**
|
|
825
|
+
* Returns the current value (or undefined if not yet loaded).
|
|
826
|
+
*/
|
|
827
|
+
get;
|
|
828
|
+
/**
|
|
829
|
+
* Returns the current resource state.
|
|
830
|
+
*/
|
|
831
|
+
state;
|
|
832
|
+
/**
|
|
833
|
+
* Returns the latest successfully loaded value (or undefined).
|
|
834
|
+
*/
|
|
835
|
+
latest;
|
|
836
|
+
/**
|
|
837
|
+
* Triggers a refetch of the resource.
|
|
838
|
+
*/
|
|
839
|
+
refetch;
|
|
840
|
+
/**
|
|
841
|
+
* Creates a new SolidResource from a fetcher function.
|
|
842
|
+
* @param fetcher - The async fetcher function.
|
|
843
|
+
*/
|
|
844
|
+
constructor(fetcher) {
|
|
845
|
+
const [get, set] = createResource(fetcher);
|
|
846
|
+
this.get = get;
|
|
847
|
+
this.state = () => get.state;
|
|
848
|
+
this.latest = () => get.latest;
|
|
849
|
+
this.refetch = () => set.refetch();
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
function fromSync(state) {
|
|
854
|
+
const solidState = new SolidState(state.get());
|
|
855
|
+
let fx;
|
|
856
|
+
onMount(() => {
|
|
857
|
+
fx = new FlowEffect((get) => {
|
|
858
|
+
const value = get(state);
|
|
859
|
+
solidState.set(() => value);
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
onCleanup(() => fx.dispose());
|
|
863
|
+
return solidState;
|
|
864
|
+
}
|
|
865
|
+
function fromAsync(derivation) {
|
|
866
|
+
const solidResource = new SolidResource(async () => {
|
|
867
|
+
const value = await derivation.get();
|
|
868
|
+
return value;
|
|
869
|
+
});
|
|
870
|
+
let fx;
|
|
871
|
+
onMount(() => {
|
|
872
|
+
fx = new FlowEffect(async (get) => {
|
|
873
|
+
await get(derivation);
|
|
874
|
+
solidResource.refetch();
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
onCleanup(() => fx.dispose());
|
|
878
|
+
return solidResource;
|
|
879
|
+
}
|
|
880
|
+
function shallowFrom(flow) {
|
|
881
|
+
const initialValue = flow.get();
|
|
882
|
+
const isAsync = initialValue instanceof Promise;
|
|
883
|
+
if (isAsync) {
|
|
884
|
+
return fromAsync(flow);
|
|
885
|
+
}
|
|
886
|
+
return fromSync(flow);
|
|
887
|
+
}
|
|
888
|
+
function deepFrom(getter) {
|
|
889
|
+
const derivation = new FlowDerivation((get) => {
|
|
890
|
+
return getter(get);
|
|
891
|
+
});
|
|
892
|
+
const initialValue = derivation.get();
|
|
893
|
+
const isAsync = initialValue instanceof Promise;
|
|
894
|
+
if (isAsync) {
|
|
895
|
+
return fromAsync(derivation);
|
|
896
|
+
}
|
|
897
|
+
return fromSync(derivation);
|
|
898
|
+
}
|
|
899
|
+
function from(flow) {
|
|
900
|
+
if (flow instanceof FlowObservable) {
|
|
901
|
+
return shallowFrom(flow);
|
|
902
|
+
}
|
|
903
|
+
return deepFrom(flow);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
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 };
|
|
@@ -2,7 +2,6 @@ export { FlowSignal } from './signal';
|
|
|
2
2
|
export { FlowState } from './state';
|
|
3
3
|
export { FlowObservable } from './observable';
|
|
4
4
|
export { FlowDerivation } from './derivation';
|
|
5
|
-
export { FlowDerivationAsync } from './derivationAsync';
|
|
6
5
|
export { FlowEffect } from './effect';
|
|
7
6
|
export { FlowConstant } from './constant';
|
|
8
7
|
export { isDisposable } from './disposable';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/basic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/basic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,9 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
export { signal, state, constant, resource, stream, derivation, effect, map, array, streamAsync, resourceAsync, } from './creators';
|
|
10
|
-
export { isDisposable } from './basic';
|
|
11
|
-
export {
|
|
12
|
-
export
|
|
13
|
-
export { FlowResource, FlowMap, FlowResourceAsync, FlowStreamAsync, FlowStream, FlowArray, } from './advanced/';
|
|
14
|
-
export type { FlowStreamDisposer, FlowStreamSetter, FlowStreamUpdater, FlowArrayAction, } from './advanced/';
|
|
10
|
+
export { isDisposable, FlowDerivation, FlowEffect, FlowObservable, FlowSignal, FlowState, FlowConstant, type FlowGetter, type FlowWatcher, type FlowDisposable, } from './basic/';
|
|
11
|
+
export { FlowResource, FlowMap, FlowResourceAsync, FlowStreamAsync, FlowStream, FlowArray, type FlowStreamDisposer, type FlowStreamSetter, type FlowStreamUpdater, type FlowArrayAction, } from './advanced/';
|
|
12
|
+
export { from, SolidState, SolidResource, SolidDerivation, type SolidObservable, type SolidGetter, } from './solid/';
|
|
15
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACH,MAAM,EACN,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,UAAU,EACV,MAAM,EACN,GAAG,EACH,KAAK,EACL,WAAW,EACX,aAAa,GAChB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACH,MAAM,EACN,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,UAAU,EACV,MAAM,EACN,GAAG,EACH,KAAK,EACL,WAAW,EACX,aAAa,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACH,YAAY,EACZ,cAAc,EACd,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,EACT,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,cAAc,GACtB,MAAM,UAAU,CAAC;AAElB,OAAO,EACH,YAAY,EACZ,OAAO,EACP,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,SAAS,EACT,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,eAAe,GACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EACH,IAAI,EACJ,UAAU,EACV,aAAa,EACb,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,WAAW,GACnB,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { SolidResource, SolidDerivation } from './primitives';
|
|
2
|
+
import { FlowObservable, FlowGetter } from '../basic';
|
|
3
|
+
/**
|
|
4
|
+
* Utility type that excludes Promise types from T.
|
|
5
|
+
* Used to ensure type safety for synchronous derivations/resources.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export type NotPromise<T> = T extends Promise<unknown> ? never : T;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a FlowObservable of a Promise value into a SolidResource.
|
|
12
|
+
*
|
|
13
|
+
* @param flow - The FlowObservable to convert.
|
|
14
|
+
* @returns A SolidResource wrapping the observable.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export declare function from<T>(flow: FlowObservable<Promise<NotPromise<T>>>): SolidResource<NotPromise<T>>;
|
|
19
|
+
/**
|
|
20
|
+
* Converts a FlowObservable of a non-Promise value into a SolidDerivation.
|
|
21
|
+
*
|
|
22
|
+
* @param flow - The FlowObservable to convert.
|
|
23
|
+
* @returns A SolidDerivation wrapping the observable.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare function from<T>(flow: FlowObservable<NotPromise<T>>): SolidDerivation<NotPromise<T>>;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a FlowObservable into a Solid derivation or resource, depending on whether the value is synchronous or asynchronous.
|
|
30
|
+
*
|
|
31
|
+
* @param flow - The FlowObservable to convert.
|
|
32
|
+
* @returns A SolidDerivation or SolidResource, depending on the input type.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare function from<T>(flow: FlowObservable<Promise<NotPromise<T>>> | FlowObservable<NotPromise<T>>): SolidDerivation<NotPromise<T>> | SolidResource<NotPromise<T>>;
|
|
37
|
+
/**
|
|
38
|
+
* Converts a getter function returning a non-Promise value into a SolidDerivation.
|
|
39
|
+
*
|
|
40
|
+
* @param flow - The getter function to convert.
|
|
41
|
+
* @returns A SolidDerivation wrapping the getter.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export declare function from<T>(flow: (get: FlowGetter) => NotPromise<T>): SolidDerivation<NotPromise<T>>;
|
|
46
|
+
/**
|
|
47
|
+
* Converts a getter function returning a Promise into a SolidResource.
|
|
48
|
+
*
|
|
49
|
+
* @param flow - The getter function to convert.
|
|
50
|
+
* @returns A SolidResource wrapping the getter.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export declare function from<T>(flow: (get: FlowGetter) => Promise<NotPromise<T>>): SolidResource<NotPromise<T>>;
|
|
55
|
+
/**
|
|
56
|
+
* Converts a getter function into a Solid derivation or resource, depending on whether the returned value is synchronous or asynchronous.
|
|
57
|
+
*
|
|
58
|
+
* @param flow - The getter function to convert.
|
|
59
|
+
* @returns A SolidDerivation or SolidResource, depending on the input type.
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export declare function from<T>(flow: ((get: FlowGetter) => NotPromise<T>) | ((get: FlowGetter) => Promise<NotPromise<T>>)): SolidDerivation<T> | SolidResource<T>;
|
|
64
|
+
//# sourceMappingURL=converters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/solid/converters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAc,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAc,cAAc,EAAE,KAAK,UAAU,EAAkB,MAAM,UAAU,CAAC;AAsEvF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;AAEnE;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACpG;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7F;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAClB,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAC7E,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAClG;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACzG;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAClB,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAC3F,eAAe,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/solid/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC"}
|