solid-ctrl-flow 1.0.21 → 1.0.23
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 +6 -0
- package/dist/index.mjs +17 -12
- package/dist/index.umd.js +15 -10
- package/package.json +1 -1
- package/readMe.md +8 -6
package/dist/index.d.ts
CHANGED
|
@@ -199,6 +199,12 @@ export declare function toSignal<T, K extends keyof T>(obj: T, k: K): Signal<T[K
|
|
|
199
199
|
*/
|
|
200
200
|
export declare function untrackCall<F extends (...args: any[]) => any>(this: ThisParameterType<F>, f: F, ...args: Parameters<F>): any;
|
|
201
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Calls {@link f} maintaining its reactivity
|
|
204
|
+
* @param f An {@link Accessor} to a {@link Signal}
|
|
205
|
+
*/
|
|
206
|
+
export declare function unwrapSignal<T>(f: Accessor<Signal<T>>): Signal<T>;
|
|
207
|
+
|
|
202
208
|
/** Like a {@link Match} but gets the value from the closest {@link Case} ancestor */
|
|
203
209
|
export declare function When(props: {
|
|
204
210
|
value: unknown;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { untrack, createMemo, splitProps,
|
|
1
|
+
import { untrack, createMemo, splitProps, createEffect, on, createResource, createContext, createRoot, getOwner, createComponent, useContext, 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));
|
|
@@ -18,11 +18,12 @@ function splitAndMemoProps(obj, keys) {
|
|
|
18
18
|
return out;
|
|
19
19
|
}
|
|
20
20
|
function createReactiveResource(f) {
|
|
21
|
+
var refetch;
|
|
21
22
|
const memo = createMemo(f);
|
|
22
|
-
|
|
23
|
+
createEffect(on(memo, () => refetch?.()));
|
|
24
|
+
const [get] = [, {
|
|
23
25
|
refetch
|
|
24
26
|
}] = createResource(memo);
|
|
25
|
-
createEffect(on(memo, (_x, _prev, ok) => (ok && refetch(), true)));
|
|
26
27
|
return get;
|
|
27
28
|
}
|
|
28
29
|
function createOption(init, def = init, name) {
|
|
@@ -58,6 +59,15 @@ function runWithContext(ctx2, value, f) {
|
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
const IDENTITY = (x) => x;
|
|
62
|
+
function bind(source, dest, to = IDENTITY) {
|
|
63
|
+
const d = createRoot((d2) => (createEffect(on(source[0], (x) => dest[1]((prev) => to(x, prev)))), d2));
|
|
64
|
+
return onCleanup(d), d;
|
|
65
|
+
}
|
|
66
|
+
function bindTwoWay(source, dest, to = IDENTITY, from = IDENTITY) {
|
|
67
|
+
const a = bind(source, dest, to);
|
|
68
|
+
const b = bind(dest, source, from);
|
|
69
|
+
return () => (a(), b());
|
|
70
|
+
}
|
|
61
71
|
function toSetter(get, set) {
|
|
62
72
|
return (x) => {
|
|
63
73
|
const out = typeof x === "function" ? x(untrack(get)) : x;
|
|
@@ -68,14 +78,8 @@ function toSignal(obj, k) {
|
|
|
68
78
|
const get = () => obj[k];
|
|
69
79
|
return [get, toSetter(get, (v) => obj[k] = v)];
|
|
70
80
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
return onCleanup(d), d;
|
|
74
|
-
}
|
|
75
|
-
function bindTwoWay(source, dest, to = IDENTITY, from = IDENTITY) {
|
|
76
|
-
const a = bind(source, dest, to);
|
|
77
|
-
const b = bind(dest, source, from);
|
|
78
|
-
return () => (a(), b());
|
|
81
|
+
function unwrapSignal(f) {
|
|
82
|
+
return [() => f()[0](), (x) => f()[1](x)];
|
|
79
83
|
}
|
|
80
84
|
const ctx = createContext(() => void 0, {
|
|
81
85
|
name: "case-when"
|
|
@@ -187,5 +191,6 @@ export {
|
|
|
187
191
|
splitAndMemoProps,
|
|
188
192
|
toSetter,
|
|
189
193
|
toSignal,
|
|
190
|
-
untrackCall
|
|
194
|
+
untrackCall,
|
|
195
|
+
unwrapSignal
|
|
191
196
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -20,11 +20,12 @@
|
|
|
20
20
|
return out;
|
|
21
21
|
}
|
|
22
22
|
function createReactiveResource(f) {
|
|
23
|
+
var refetch;
|
|
23
24
|
const memo = solidJs.createMemo(f);
|
|
24
|
-
|
|
25
|
+
solidJs.createEffect(solidJs.on(memo, () => refetch?.()));
|
|
26
|
+
const [get] = [, {
|
|
25
27
|
refetch
|
|
26
28
|
}] = solidJs.createResource(memo);
|
|
27
|
-
solidJs.createEffect(solidJs.on(memo, (_x, _prev, ok) => (ok && refetch(), true)));
|
|
28
29
|
return get;
|
|
29
30
|
}
|
|
30
31
|
function createOption(init, def = init, name) {
|
|
@@ -60,6 +61,15 @@
|
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
const IDENTITY = (x) => x;
|
|
64
|
+
function bind(source, dest, to = IDENTITY) {
|
|
65
|
+
const d = solidJs.createRoot((d2) => (solidJs.createEffect(solidJs.on(source[0], (x) => dest[1]((prev) => to(x, prev)))), d2));
|
|
66
|
+
return solidJs.onCleanup(d), d;
|
|
67
|
+
}
|
|
68
|
+
function bindTwoWay(source, dest, to = IDENTITY, from = IDENTITY) {
|
|
69
|
+
const a = bind(source, dest, to);
|
|
70
|
+
const b = bind(dest, source, from);
|
|
71
|
+
return () => (a(), b());
|
|
72
|
+
}
|
|
63
73
|
function toSetter(get, set) {
|
|
64
74
|
return (x) => {
|
|
65
75
|
const out = typeof x === "function" ? x(solidJs.untrack(get)) : x;
|
|
@@ -70,14 +80,8 @@
|
|
|
70
80
|
const get = () => obj[k];
|
|
71
81
|
return [get, toSetter(get, (v) => obj[k] = v)];
|
|
72
82
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
return solidJs.onCleanup(d), d;
|
|
76
|
-
}
|
|
77
|
-
function bindTwoWay(source, dest, to = IDENTITY, from = IDENTITY) {
|
|
78
|
-
const a = bind(source, dest, to);
|
|
79
|
-
const b = bind(dest, source, from);
|
|
80
|
-
return () => (a(), b());
|
|
83
|
+
function unwrapSignal(f) {
|
|
84
|
+
return [() => f()[0](), (x) => f()[1](x)];
|
|
81
85
|
}
|
|
82
86
|
const ctx = solidJs.createContext(() => void 0, {
|
|
83
87
|
name: "case-when"
|
|
@@ -189,5 +193,6 @@
|
|
|
189
193
|
exports2.toSetter = toSetter;
|
|
190
194
|
exports2.toSignal = toSignal;
|
|
191
195
|
exports2.untrackCall = untrackCall;
|
|
196
|
+
exports2.unwrapSignal = unwrapSignal;
|
|
192
197
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
193
198
|
});
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -124,18 +124,20 @@ return <>Something else</>
|
|
|
124
124
|
## Bindings
|
|
125
125
|
Functions that create bindings between `Signal`s
|
|
126
126
|
|
|
127
|
-
### `toSetter()`
|
|
128
|
-
Creates a full-fledged solid `Setter` from a normal one
|
|
129
|
-
|
|
130
|
-
### `toSignal()`
|
|
131
|
-
Creates a `Signal` from a property of an object
|
|
132
|
-
|
|
133
127
|
### `bind()`
|
|
134
128
|
Creates a one-way binding between two `Signal`s
|
|
135
129
|
|
|
136
130
|
### `bindTwoWay()`
|
|
137
131
|
Creates a two-way binding between two `Signal`s
|
|
138
132
|
|
|
133
|
+
### `toSetter()`
|
|
134
|
+
Creates a full-fledged solid `Setter` from a normal one
|
|
135
|
+
|
|
136
|
+
### `toSignal()`
|
|
137
|
+
Creates a `Signal` from a property of an object
|
|
138
|
+
|
|
139
|
+
### `unwrapSignal()`
|
|
140
|
+
Calls an `Accessor` to a `Signal` maintaining its reactivity
|
|
139
141
|
|
|
140
142
|
## Utility functions
|
|
141
143
|
Utility functions needed for the components above
|