solid-ctrl-flow 1.0.46 → 1.0.47
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 +11 -3
- package/dist/index.mjs +15 -13
- package/dist/index.umd.js +14 -12
- package/package.json +1 -1
- package/readMe.md +12 -9
package/dist/index.d.ts
CHANGED
|
@@ -127,6 +127,14 @@ export declare function createReactiveResource<R>(f: EffectFunction<R | undefine
|
|
|
127
127
|
/** Built-in {@link ReactiveContext} which allows you to display different things in debug mode */
|
|
128
128
|
export declare const debug: ReactiveContext<boolean>;
|
|
129
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Utility function that makes you use an {@link Accessor} of a {@link JSX.Element} as a {@link JSX.Element} itself.
|
|
132
|
+
* Used to defer the execution of {@link f} until it gets rendered.
|
|
133
|
+
* Using {@link Function}s as {@link JSX.Element} is supported by default but is forbidden by the types
|
|
134
|
+
* @param f The {@link Accessor} to the actual content
|
|
135
|
+
*/
|
|
136
|
+
export declare const deferCall: (f: Accessor<JSX.Element>) => JSX.Element;
|
|
137
|
+
|
|
130
138
|
/**
|
|
131
139
|
* Eventually wraps its content into a template if a certain condition is met.
|
|
132
140
|
* The content is memoized in the beginning and will be recycled even if the wrapper changes.
|
|
@@ -167,7 +175,7 @@ export declare function memoProps<T, K extends readonly (keyof T)[]>(obj: T, key
|
|
|
167
175
|
* Example:
|
|
168
176
|
* ```tsx
|
|
169
177
|
* return <>
|
|
170
|
-
* <Nest each={[ 1, 2, 3 ]} template={(c, x) => <>({x}, {c
|
|
178
|
+
* <Nest each={[ 1, 2, 3 ]} template={(c, x) => <>({x}, {c}, -{x})</>}>
|
|
171
179
|
* CONTENT
|
|
172
180
|
* </Nest>
|
|
173
181
|
* </>
|
|
@@ -176,7 +184,7 @@ export declare function memoProps<T, K extends readonly (keyof T)[]>(obj: T, key
|
|
|
176
184
|
*/
|
|
177
185
|
export declare function Nest<T>(props: ParentProps<{
|
|
178
186
|
each: readonly T[] | undefined;
|
|
179
|
-
template: (c:
|
|
187
|
+
template: (c: JSX.Element, x: T, i: Accessor<number>) => JSX.Element;
|
|
180
188
|
}>): JSX.Element;
|
|
181
189
|
|
|
182
190
|
/**
|
|
@@ -311,7 +319,7 @@ declare type Standard<T> = ParentProps<{
|
|
|
311
319
|
}>;
|
|
312
320
|
|
|
313
321
|
/** Type of an element wrapping call-back which accepts an additional parameter */
|
|
314
|
-
declare type Template<T> = (c:
|
|
322
|
+
declare type Template<T> = (c: JSX.Element, x: T) => JSX.Element;
|
|
315
323
|
|
|
316
324
|
/**
|
|
317
325
|
* Creates a full-fledged solid {@link Setter} from a normal one
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useContext, createMemo, createComponent, createContext, createRoot, getOwner,
|
|
1
|
+
import { useContext, createMemo, createComponent, createContext, createRoot, getOwner, untrack, createEffect, on, createResource, splitProps, Show, onCleanup, For, mapArray, createSignal, onMount, Match, mergeProps, createRenderEffect, getListener } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
const BASE_CTOR = Function;
|
|
4
4
|
class ReactiveContext extends BASE_CTOR {
|
|
@@ -64,6 +64,17 @@ function runWithContext(ctx2, value, f) {
|
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
+
const deferCall = (f) => f;
|
|
68
|
+
function untrackCall(f, ...args) {
|
|
69
|
+
return untrack(() => f.apply(this, args));
|
|
70
|
+
}
|
|
71
|
+
function createReactiveResource(f) {
|
|
72
|
+
var refetch;
|
|
73
|
+
const memo = createMemo(f);
|
|
74
|
+
createEffect(on(memo, () => refetch?.()));
|
|
75
|
+
const [get] = [, { refetch }] = createResource(memo);
|
|
76
|
+
return get;
|
|
77
|
+
}
|
|
67
78
|
function memoProps(obj, keys = Object.keys(obj), equals = false) {
|
|
68
79
|
const out = {};
|
|
69
80
|
for (const elm of keys)
|
|
@@ -75,16 +86,6 @@ function splitAndMemoProps(obj, keys, equals) {
|
|
|
75
86
|
out[0] = memoProps(out[0], keys, equals);
|
|
76
87
|
return out;
|
|
77
88
|
}
|
|
78
|
-
function createReactiveResource(f) {
|
|
79
|
-
var refetch;
|
|
80
|
-
const memo = createMemo(f);
|
|
81
|
-
createEffect(on(memo, () => refetch?.()));
|
|
82
|
-
const [get] = [, { refetch }] = createResource(memo);
|
|
83
|
-
return get;
|
|
84
|
-
}
|
|
85
|
-
function untrackCall(f, ...args) {
|
|
86
|
-
return untrack(() => f.apply(this, args));
|
|
87
|
-
}
|
|
88
89
|
const unwrap = (f) => new Proxy(f, HANDLER);
|
|
89
90
|
const HANDLER = new Proxy({}, {
|
|
90
91
|
get(cache, k) {
|
|
@@ -106,7 +107,7 @@ function Enfold(props) {
|
|
|
106
107
|
get fallback() {
|
|
107
108
|
return children();
|
|
108
109
|
},
|
|
109
|
-
children: (x) => createMemo(() => untrackCall(props.template, children, x))
|
|
110
|
+
children: (x) => createMemo(() => untrackCall(props.template, deferCall(children), x))
|
|
110
111
|
});
|
|
111
112
|
}
|
|
112
113
|
var Slot;
|
|
@@ -221,7 +222,7 @@ function Nest(props) {
|
|
|
221
222
|
const memo = memoProps(props, ["template", "children"]);
|
|
222
223
|
const content = mapArray(() => props.each, (x, i) => {
|
|
223
224
|
const [get, set] = createSignal();
|
|
224
|
-
const out = createMemo(() => untrackCall(memo.template, get, x, i));
|
|
225
|
+
const out = createMemo(() => untrackCall(memo.template, deferCall(get), x, i));
|
|
225
226
|
return (x2) => {
|
|
226
227
|
onMount(() => set(() => x2));
|
|
227
228
|
onCleanup(() => set(void 0));
|
|
@@ -302,6 +303,7 @@ export {
|
|
|
302
303
|
createExtractor,
|
|
303
304
|
createReactiveResource,
|
|
304
305
|
debug,
|
|
306
|
+
deferCall,
|
|
305
307
|
memoProps,
|
|
306
308
|
runWithContext,
|
|
307
309
|
splitAndMemoProps,
|
package/dist/index.umd.js
CHANGED
|
@@ -66,6 +66,17 @@
|
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
+
const deferCall = (f) => f;
|
|
70
|
+
function untrackCall(f, ...args) {
|
|
71
|
+
return solidJs.untrack(() => f.apply(this, args));
|
|
72
|
+
}
|
|
73
|
+
function createReactiveResource(f) {
|
|
74
|
+
var refetch;
|
|
75
|
+
const memo = solidJs.createMemo(f);
|
|
76
|
+
solidJs.createEffect(solidJs.on(memo, () => refetch?.()));
|
|
77
|
+
const [get] = [, { refetch }] = solidJs.createResource(memo);
|
|
78
|
+
return get;
|
|
79
|
+
}
|
|
69
80
|
function memoProps(obj, keys = Object.keys(obj), equals = false) {
|
|
70
81
|
const out = {};
|
|
71
82
|
for (const elm of keys)
|
|
@@ -77,16 +88,6 @@
|
|
|
77
88
|
out[0] = memoProps(out[0], keys, equals);
|
|
78
89
|
return out;
|
|
79
90
|
}
|
|
80
|
-
function createReactiveResource(f) {
|
|
81
|
-
var refetch;
|
|
82
|
-
const memo = solidJs.createMemo(f);
|
|
83
|
-
solidJs.createEffect(solidJs.on(memo, () => refetch?.()));
|
|
84
|
-
const [get] = [, { refetch }] = solidJs.createResource(memo);
|
|
85
|
-
return get;
|
|
86
|
-
}
|
|
87
|
-
function untrackCall(f, ...args) {
|
|
88
|
-
return solidJs.untrack(() => f.apply(this, args));
|
|
89
|
-
}
|
|
90
91
|
const unwrap = (f) => new Proxy(f, HANDLER);
|
|
91
92
|
const HANDLER = new Proxy({}, {
|
|
92
93
|
get(cache, k) {
|
|
@@ -108,7 +109,7 @@
|
|
|
108
109
|
get fallback() {
|
|
109
110
|
return children();
|
|
110
111
|
},
|
|
111
|
-
children: (x) => solidJs.createMemo(() => untrackCall(props.template, children, x))
|
|
112
|
+
children: (x) => solidJs.createMemo(() => untrackCall(props.template, deferCall(children), x))
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
115
|
exports2.Slot = void 0;
|
|
@@ -223,7 +224,7 @@
|
|
|
223
224
|
const memo = memoProps(props, ["template", "children"]);
|
|
224
225
|
const content = solidJs.mapArray(() => props.each, (x, i) => {
|
|
225
226
|
const [get, set] = solidJs.createSignal();
|
|
226
|
-
const out = solidJs.createMemo(() => untrackCall(memo.template, get, x, i));
|
|
227
|
+
const out = solidJs.createMemo(() => untrackCall(memo.template, deferCall(get), x, i));
|
|
227
228
|
return (x2) => {
|
|
228
229
|
solidJs.onMount(() => set(() => x2));
|
|
229
230
|
solidJs.onCleanup(() => set(void 0));
|
|
@@ -302,6 +303,7 @@
|
|
|
302
303
|
exports2.createExtractor = createExtractor;
|
|
303
304
|
exports2.createReactiveResource = createReactiveResource;
|
|
304
305
|
exports2.debug = debug;
|
|
306
|
+
exports2.deferCall = deferCall;
|
|
305
307
|
exports2.memoProps = memoProps;
|
|
306
308
|
exports2.runWithContext = runWithContext;
|
|
307
309
|
exports2.splitAndMemoProps = splitAndMemoProps;
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -22,7 +22,7 @@ The following code
|
|
|
22
22
|
```tsx
|
|
23
23
|
const value = true;
|
|
24
24
|
return <>
|
|
25
|
-
<Enfold when={value} template={c => <div style={{ background: "red" }}>{c
|
|
25
|
+
<Enfold when={value} template={c => <div style={{ background: "red" }}>{c}</div>}>
|
|
26
26
|
CONTENT
|
|
27
27
|
</Enfold>
|
|
28
28
|
</>
|
|
@@ -42,7 +42,7 @@ return <>CONTENT</>
|
|
|
42
42
|
If you are wrapping the content with a context provider you need to set the `unrecycled` attribute to `true` to run again the whole content, otherwise the `Owner` of the content won't be child of the template one
|
|
43
43
|
```tsx
|
|
44
44
|
return <>
|
|
45
|
-
<Enfold unrecycled when={value} template={c => <ctx.Provider value={2} children={c
|
|
45
|
+
<Enfold unrecycled when={value} template={c => <ctx.Provider value={2} children={c} />}>
|
|
46
46
|
{useContext(ctx)}
|
|
47
47
|
</Enfold>
|
|
48
48
|
</>
|
|
@@ -53,7 +53,7 @@ Like a `For`, but instead of putting an element after another it nests them.
|
|
|
53
53
|
The following code
|
|
54
54
|
```tsx
|
|
55
55
|
return <>
|
|
56
|
-
<Nest each={[ "red", "green", "blue" ]} template={(c, x) => <div style={{ background: x, padding: "1ch" }}>{c
|
|
56
|
+
<Nest each={[ "red", "green", "blue" ]} template={(c, x) => <div style={{ background: x, padding: "1ch" }}>{c}</div>}>
|
|
57
57
|
CONTENT
|
|
58
58
|
</Nest>
|
|
59
59
|
</>
|
|
@@ -234,14 +234,17 @@ return <>
|
|
|
234
234
|
</>
|
|
235
235
|
```
|
|
236
236
|
|
|
237
|
-
### `
|
|
238
|
-
|
|
237
|
+
### `deferCall()`
|
|
238
|
+
Utility function that makes you use an `Accessor` of a `JSX.Element` as a `JSX.Element` itself
|
|
239
239
|
|
|
240
|
-
### `
|
|
241
|
-
|
|
240
|
+
### `untrackCall()`
|
|
241
|
+
Calls a function untracking what happens inside of it but not what gets passed as its argument
|
|
242
242
|
|
|
243
243
|
### `createReactiveResource()`
|
|
244
244
|
Like `createResource()` but the provided function will be reactive
|
|
245
245
|
|
|
246
|
-
### `
|
|
247
|
-
|
|
246
|
+
### `memoProps()`
|
|
247
|
+
Creates a partial version of an object with memoized remaining properties
|
|
248
|
+
|
|
249
|
+
### `splitAndMemoProps()`
|
|
250
|
+
Like `splitProps()` but memoizes the whole local part
|