@ersbeth/picoflow 1.1.0 → 1.1.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.
- package/dist/picoflow.js +106 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/solid/converters.d.ts +0 -1
- package/dist/types/solid/converters.d.ts.map +1 -1
- package/dist/types/solid/index.d.ts +2 -2
- package/dist/types/solid/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/solid/converters.ts +1 -1
- package/src/solid/index.ts +2 -8
package/dist/picoflow.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createSignal, createMemo, createResource, onMount, onCleanup } from 'solid-js';
|
|
2
|
+
|
|
1
3
|
function isDisposable(obj) {
|
|
2
4
|
return obj !== null && obj !== void 0 && typeof obj.dispose === "function";
|
|
3
5
|
}
|
|
@@ -1545,4 +1547,107 @@ function map(initial) {
|
|
|
1545
1547
|
);
|
|
1546
1548
|
}
|
|
1547
1549
|
|
|
1548
|
-
|
|
1550
|
+
class SolidState {
|
|
1551
|
+
/**
|
|
1552
|
+
* Returns the current value.
|
|
1553
|
+
*/
|
|
1554
|
+
get;
|
|
1555
|
+
/**
|
|
1556
|
+
* Sets the value or updates it using a getter function.
|
|
1557
|
+
*/
|
|
1558
|
+
set;
|
|
1559
|
+
/**
|
|
1560
|
+
* Creates a new SolidState with the given initial value.
|
|
1561
|
+
* @param initialValue - The initial value.
|
|
1562
|
+
*/
|
|
1563
|
+
constructor(initialValue) {
|
|
1564
|
+
const [get, set] = createSignal(initialValue);
|
|
1565
|
+
this.get = get;
|
|
1566
|
+
this.set = set;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
class SolidDerivation {
|
|
1570
|
+
/**
|
|
1571
|
+
* Returns the current derived value.
|
|
1572
|
+
*/
|
|
1573
|
+
get;
|
|
1574
|
+
/**
|
|
1575
|
+
* Creates a new SolidDerivation from a getter function or value.
|
|
1576
|
+
* @param calculator - The getter function or value.
|
|
1577
|
+
*/
|
|
1578
|
+
constructor(calculator) {
|
|
1579
|
+
const get = createMemo(calculator);
|
|
1580
|
+
this.get = get;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
class SolidResource {
|
|
1584
|
+
/**
|
|
1585
|
+
* Returns the current value (or undefined if not yet loaded).
|
|
1586
|
+
*/
|
|
1587
|
+
get;
|
|
1588
|
+
/**
|
|
1589
|
+
* Returns the current resource state.
|
|
1590
|
+
*/
|
|
1591
|
+
state;
|
|
1592
|
+
/**
|
|
1593
|
+
* Returns the latest successfully loaded value (or undefined).
|
|
1594
|
+
*/
|
|
1595
|
+
latest;
|
|
1596
|
+
/**
|
|
1597
|
+
* Triggers a refetch of the resource.
|
|
1598
|
+
*/
|
|
1599
|
+
refetch;
|
|
1600
|
+
set;
|
|
1601
|
+
/**
|
|
1602
|
+
* Creates a new SolidResource from a fetcher function.
|
|
1603
|
+
* @param fetcher - The async fetcher function.
|
|
1604
|
+
*/
|
|
1605
|
+
constructor(fetcher) {
|
|
1606
|
+
const [get, set] = createResource(fetcher);
|
|
1607
|
+
this.get = get;
|
|
1608
|
+
this.state = () => get.state;
|
|
1609
|
+
this.latest = () => get.latest;
|
|
1610
|
+
this.refetch = () => set.refetch();
|
|
1611
|
+
this.set = (value) => set.mutate(value);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
function fromNode(node) {
|
|
1616
|
+
let initialized = false;
|
|
1617
|
+
const solidResource = new SolidResource(async () => {
|
|
1618
|
+
let value;
|
|
1619
|
+
if (initialized) {
|
|
1620
|
+
value = await node.get(null);
|
|
1621
|
+
} else {
|
|
1622
|
+
value = await node.pick();
|
|
1623
|
+
initialized = true;
|
|
1624
|
+
}
|
|
1625
|
+
return value;
|
|
1626
|
+
});
|
|
1627
|
+
let fx;
|
|
1628
|
+
onMount(() => {
|
|
1629
|
+
fx = new FlowEffect(async (t) => {
|
|
1630
|
+
node.watch(t);
|
|
1631
|
+
solidResource.refetch();
|
|
1632
|
+
});
|
|
1633
|
+
});
|
|
1634
|
+
onCleanup(() => fx.dispose());
|
|
1635
|
+
return solidResource;
|
|
1636
|
+
}
|
|
1637
|
+
function fromGetter(getter) {
|
|
1638
|
+
const derivation = new FlowNodeAsync(async (t) => {
|
|
1639
|
+
return getter(t);
|
|
1640
|
+
});
|
|
1641
|
+
return fromNode(derivation);
|
|
1642
|
+
}
|
|
1643
|
+
function from(flow) {
|
|
1644
|
+
if (flow instanceof FlowNodeAsync || flow instanceof FlowNode) {
|
|
1645
|
+
return fromNode(flow);
|
|
1646
|
+
}
|
|
1647
|
+
if (typeof flow === "function") {
|
|
1648
|
+
return fromGetter(flow);
|
|
1649
|
+
}
|
|
1650
|
+
throw new Error("Invalid flow type");
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
export { FlowArray, FlowEffect, FlowGraph, FlowMap, FlowNode, FlowNodeAsync, FlowSignal, SolidDerivation, SolidResource, SolidState, array, constant, constantAsync, derivation, derivationAsync, effect, from, isDisposable, map, signal, state, stateAsync };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/solid/converters.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAmE7C;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/solid/converters.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAmE7C;;;;;GAKG;AAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACrB,IAAI,EACD,iBAAiB,CAAC,CAAC,CAAC,GACpB,YAAY,CAAC,CAAC,CAAC,GACf,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,CAAC,CAAC,GACvB,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,GACjC,aAAa,CAAC,CAAC,CAAC,CAUlB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './converters';
|
|
2
|
+
export * from './primitives';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/solid/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/solid/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/solid/converters.ts
CHANGED
|
@@ -76,7 +76,7 @@ function fromGetter<T>(
|
|
|
76
76
|
*
|
|
77
77
|
* @public
|
|
78
78
|
*/
|
|
79
|
-
export type NotPromise<T> = T extends Promise<unknown> ? never : T;
|
|
79
|
+
// export type NotPromise<T> = T extends Promise<unknown> ? never : T;
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* Converts a FlowNode, FlowNodeAsync, or getter function into a SolidResource.
|
package/src/solid/index.ts
CHANGED