solid-ctrl-flow 1.0.24 → 1.0.26
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/index.d.ts +8 -0
- package/dist/index.mjs +7 -3
- package/dist/index.umd.js +6 -2
- package/package.json +1 -1
- package/readMe.md +3 -0
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,14 @@ export declare function Case(props: {
|
|
|
64
64
|
children: JSX.Element;
|
|
65
65
|
}): JSX.Element;
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Returns a {@link Signal} that applies the `??=` operator to the input one.
|
|
69
|
+
* If the getter of {@link param0} is like "x", then the result one is like "(x ??= {@link f}())"
|
|
70
|
+
* @param param0 The {@link Signal} to which to coalesce the getter
|
|
71
|
+
* @param f A function that creates a new {@link T}
|
|
72
|
+
*/
|
|
73
|
+
export declare function coalesceSignal<T>([get, set]: Signal<T | undefined>, f: Accessor<T>): Signal<T>;
|
|
74
|
+
|
|
67
75
|
/** Conversion function for bindings */
|
|
68
76
|
export declare type Convert<S, D> = (x: S, prev: D) => D;
|
|
69
77
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { untrack, createMemo, splitProps, createEffect, on, createResource, createContext, createRoot, getOwner, createComponent, useContext, onCleanup, Match, mergeProps, For, Show } from "solid-js";
|
|
1
|
+
import { untrack, createMemo, splitProps, createEffect, on, createResource, createContext, createRoot, getOwner, createComponent, useContext, createRenderEffect, onCleanup, Match, mergeProps, For, Show } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
function untrackCall(f, ...args) {
|
|
4
4
|
return untrack(() => f.apply(this, args));
|
|
@@ -59,8 +59,8 @@ function runWithContext(ctx2, value, f) {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
const IDENTITY = (x) => x;
|
|
62
|
-
function bind(
|
|
63
|
-
const d = createRoot((d2) => (
|
|
62
|
+
function bind([get], [, set], to = IDENTITY) {
|
|
63
|
+
const d = createRoot((d2) => (createRenderEffect(on(get, (x) => set((prev) => to(x, prev)))), d2));
|
|
64
64
|
return onCleanup(d), d;
|
|
65
65
|
}
|
|
66
66
|
function bindTwoWay(source, dest, to = IDENTITY, from = IDENTITY) {
|
|
@@ -78,6 +78,9 @@ function toSignal(obj, k) {
|
|
|
78
78
|
const get = () => obj()[k()];
|
|
79
79
|
return [get, toSetter(get, (v) => obj()[k()] = v)];
|
|
80
80
|
}
|
|
81
|
+
function coalesceSignal([get, set], f) {
|
|
82
|
+
return [() => get() ?? set(f), set];
|
|
83
|
+
}
|
|
81
84
|
function unwrapSignal(f) {
|
|
82
85
|
return [() => f()[0](), (x) => f()[1](x)];
|
|
83
86
|
}
|
|
@@ -183,6 +186,7 @@ export {
|
|
|
183
186
|
When,
|
|
184
187
|
bind,
|
|
185
188
|
bindTwoWay,
|
|
189
|
+
coalesceSignal,
|
|
186
190
|
createExtractor,
|
|
187
191
|
createOption,
|
|
188
192
|
createReactiveResource,
|
package/dist/index.umd.js
CHANGED
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
const IDENTITY = (x) => x;
|
|
64
|
-
function bind(
|
|
65
|
-
const d = solidJs.createRoot((d2) => (solidJs.
|
|
64
|
+
function bind([get], [, set], to = IDENTITY) {
|
|
65
|
+
const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(get, (x) => set((prev) => to(x, prev)))), d2));
|
|
66
66
|
return solidJs.onCleanup(d), d;
|
|
67
67
|
}
|
|
68
68
|
function bindTwoWay(source, dest, to = IDENTITY, from = IDENTITY) {
|
|
@@ -80,6 +80,9 @@
|
|
|
80
80
|
const get = () => obj()[k()];
|
|
81
81
|
return [get, toSetter(get, (v) => obj()[k()] = v)];
|
|
82
82
|
}
|
|
83
|
+
function coalesceSignal([get, set], f) {
|
|
84
|
+
return [() => get() ?? set(f), set];
|
|
85
|
+
}
|
|
83
86
|
function unwrapSignal(f) {
|
|
84
87
|
return [() => f()[0](), (x) => f()[1](x)];
|
|
85
88
|
}
|
|
@@ -184,6 +187,7 @@
|
|
|
184
187
|
exports2.When = When;
|
|
185
188
|
exports2.bind = bind;
|
|
186
189
|
exports2.bindTwoWay = bindTwoWay;
|
|
190
|
+
exports2.coalesceSignal = coalesceSignal;
|
|
187
191
|
exports2.createExtractor = createExtractor;
|
|
188
192
|
exports2.createOption = createOption;
|
|
189
193
|
exports2.createReactiveResource = createReactiveResource;
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -136,6 +136,9 @@ Creates a full-fledged solid `Setter` from a normal one
|
|
|
136
136
|
### `toSignal()`
|
|
137
137
|
Creates a `Signal` from a property of an object
|
|
138
138
|
|
|
139
|
+
### `coalesceSignal()`
|
|
140
|
+
Creates a non nullable `Signal` from a nullable one
|
|
141
|
+
|
|
139
142
|
### `unwrapSignal()`
|
|
140
143
|
Calls an `Accessor` to a `Signal` maintaining its reactivity
|
|
141
144
|
|