solid-ctrl-flow 1.0.45 → 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 -31
- package/dist/index.mjs +15 -24
- package/dist/index.umd.js +14 -23
- package/package.json +1 -1
- package/readMe.md +12 -30
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Accessor } from 'solid-js';
|
|
2
|
-
import { ComponentProps } from 'solid-js';
|
|
3
2
|
import { Context } from 'solid-js';
|
|
4
3
|
import { EffectFunction } from 'solid-js';
|
|
5
4
|
import { JSX } from 'solid-js';
|
|
@@ -8,9 +7,7 @@ import { Owner } from 'solid-js';
|
|
|
8
7
|
import { ParentProps } from 'solid-js';
|
|
9
8
|
import { Resource } from 'solid-js';
|
|
10
9
|
import { Setter } from 'solid-js';
|
|
11
|
-
import { Show } from 'solid-js';
|
|
12
10
|
import { Signal } from 'solid-js';
|
|
13
|
-
import { Without } from 'logic-types';
|
|
14
11
|
|
|
15
12
|
/** Type hack for making {@link ReactiveContext} implement {@link Accessor} */
|
|
16
13
|
declare const BASE_CTOR: new <T>() => Accessor<T>;
|
|
@@ -130,6 +127,14 @@ export declare function createReactiveResource<R>(f: EffectFunction<R | undefine
|
|
|
130
127
|
/** Built-in {@link ReactiveContext} which allows you to display different things in debug mode */
|
|
131
128
|
export declare const debug: ReactiveContext<boolean>;
|
|
132
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
|
+
|
|
133
138
|
/**
|
|
134
139
|
* Eventually wraps its content into a template if a certain condition is met.
|
|
135
140
|
* The content is memoized in the beginning and will be recycled even if the wrapper changes.
|
|
@@ -142,31 +147,6 @@ export declare function Enfold<T>(props: Keyed<T>): JSX.Element;
|
|
|
142
147
|
|
|
143
148
|
export declare function Enfold<T>(props: Unkeyed<T>): JSX.Element;
|
|
144
149
|
|
|
145
|
-
/**
|
|
146
|
-
* It works like a `Show`, but for `Switch`es, you can wrap `Match`es with it in order to not trigger them in certain conditions.
|
|
147
|
-
* It doesn't support the `fallback` attribute.
|
|
148
|
-
* Example:
|
|
149
|
-
* ```tsx
|
|
150
|
-
* const value = false;
|
|
151
|
-
* return <>
|
|
152
|
-
* <Switch>
|
|
153
|
-
* <Match when={false}>
|
|
154
|
-
* FALSE
|
|
155
|
-
* </Match>
|
|
156
|
-
* <Ensure when={false}>
|
|
157
|
-
* <Match when>
|
|
158
|
-
* This won't render because "value" is {false}
|
|
159
|
-
* </Match>
|
|
160
|
-
* </Ensure>
|
|
161
|
-
* <Match when>
|
|
162
|
-
* (This will render)
|
|
163
|
-
* </Match>
|
|
164
|
-
* </Switch>
|
|
165
|
-
* <>
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
export declare function Ensure(props: Without<ComponentProps<typeof Show>, "fallback">): JSX.Element;
|
|
169
|
-
|
|
170
150
|
/** Handy type alias */
|
|
171
151
|
declare type Equals = MemoOptions<unknown>["equals"];
|
|
172
152
|
|
|
@@ -195,7 +175,7 @@ export declare function memoProps<T, K extends readonly (keyof T)[]>(obj: T, key
|
|
|
195
175
|
* Example:
|
|
196
176
|
* ```tsx
|
|
197
177
|
* return <>
|
|
198
|
-
* <Nest each={[ 1, 2, 3 ]} template={(c, x) => <>({x}, {c
|
|
178
|
+
* <Nest each={[ 1, 2, 3 ]} template={(c, x) => <>({x}, {c}, -{x})</>}>
|
|
199
179
|
* CONTENT
|
|
200
180
|
* </Nest>
|
|
201
181
|
* </>
|
|
@@ -204,7 +184,7 @@ export declare function memoProps<T, K extends readonly (keyof T)[]>(obj: T, key
|
|
|
204
184
|
*/
|
|
205
185
|
export declare function Nest<T>(props: ParentProps<{
|
|
206
186
|
each: readonly T[] | undefined;
|
|
207
|
-
template: (c:
|
|
187
|
+
template: (c: JSX.Element, x: T, i: Accessor<number>) => JSX.Element;
|
|
208
188
|
}>): JSX.Element;
|
|
209
189
|
|
|
210
190
|
/**
|
|
@@ -339,7 +319,7 @@ declare type Standard<T> = ParentProps<{
|
|
|
339
319
|
}>;
|
|
340
320
|
|
|
341
321
|
/** Type of an element wrapping call-back which accepts an additional parameter */
|
|
342
|
-
declare type Template<T> = (c:
|
|
322
|
+
declare type Template<T> = (c: JSX.Element, x: T) => JSX.Element;
|
|
343
323
|
|
|
344
324
|
/**
|
|
345
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));
|
|
@@ -244,16 +245,6 @@ function Case(props) {
|
|
|
244
245
|
}
|
|
245
246
|
}, other));
|
|
246
247
|
}
|
|
247
|
-
function Ensure(props) {
|
|
248
|
-
return createComponent(Show, mergeProps(props, {
|
|
249
|
-
get fallback() {
|
|
250
|
-
return createComponent(Match, {
|
|
251
|
-
when: false,
|
|
252
|
-
children: void 0
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}));
|
|
256
|
-
}
|
|
257
248
|
const IDENTITY = (x) => x;
|
|
258
249
|
function bind(source, dest, to = IDENTITY, skip = false) {
|
|
259
250
|
const d = createRoot((d2) => (createRenderEffect(on(source, (x) => skip ? skip = false : dest((prev) => to(x, prev)))), d2));
|
|
@@ -301,7 +292,6 @@ function SameContext(props) {
|
|
|
301
292
|
export {
|
|
302
293
|
Case,
|
|
303
294
|
Enfold,
|
|
304
|
-
Ensure,
|
|
305
295
|
Nest,
|
|
306
296
|
On,
|
|
307
297
|
ReactiveContext,
|
|
@@ -313,6 +303,7 @@ export {
|
|
|
313
303
|
createExtractor,
|
|
314
304
|
createReactiveResource,
|
|
315
305
|
debug,
|
|
306
|
+
deferCall,
|
|
316
307
|
memoProps,
|
|
317
308
|
runWithContext,
|
|
318
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));
|
|
@@ -246,16 +247,6 @@
|
|
|
246
247
|
}
|
|
247
248
|
}, other));
|
|
248
249
|
}
|
|
249
|
-
function Ensure(props) {
|
|
250
|
-
return solidJs.createComponent(solidJs.Show, solidJs.mergeProps(props, {
|
|
251
|
-
get fallback() {
|
|
252
|
-
return solidJs.createComponent(solidJs.Match, {
|
|
253
|
-
when: false,
|
|
254
|
-
children: void 0
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
}));
|
|
258
|
-
}
|
|
259
250
|
const IDENTITY = (x) => x;
|
|
260
251
|
function bind(source, dest, to = IDENTITY, skip = false) {
|
|
261
252
|
const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(source, (x) => skip ? skip = false : dest((prev) => to(x, prev)))), d2));
|
|
@@ -302,7 +293,6 @@
|
|
|
302
293
|
}
|
|
303
294
|
exports2.Case = Case;
|
|
304
295
|
exports2.Enfold = Enfold;
|
|
305
|
-
exports2.Ensure = Ensure;
|
|
306
296
|
exports2.Nest = Nest;
|
|
307
297
|
exports2.On = On;
|
|
308
298
|
exports2.ReactiveContext = ReactiveContext;
|
|
@@ -313,6 +303,7 @@
|
|
|
313
303
|
exports2.createExtractor = createExtractor;
|
|
314
304
|
exports2.createReactiveResource = createReactiveResource;
|
|
315
305
|
exports2.debug = debug;
|
|
306
|
+
exports2.deferCall = deferCall;
|
|
316
307
|
exports2.memoProps = memoProps;
|
|
317
308
|
exports2.runWithContext = runWithContext;
|
|
318
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
|
</>
|
|
@@ -100,27 +100,6 @@ return <>
|
|
|
100
100
|
</>
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
### `Ensure`
|
|
104
|
-
It works like a `Show`, but for `Switch`es, you can wrap `Match`es with it in order to not trigger them in certain conditions
|
|
105
|
-
```tsx
|
|
106
|
-
const value = false;
|
|
107
|
-
return <>
|
|
108
|
-
<Switch>
|
|
109
|
-
<Match when={false}>
|
|
110
|
-
FALSE
|
|
111
|
-
</Match>
|
|
112
|
-
<Ensure when={false}>
|
|
113
|
-
<Match when>
|
|
114
|
-
This won't render because "value" is {false}
|
|
115
|
-
</Match>
|
|
116
|
-
</Ensure>
|
|
117
|
-
<Match when>
|
|
118
|
-
(This will render)
|
|
119
|
-
</Match>
|
|
120
|
-
</Switch>
|
|
121
|
-
<>
|
|
122
|
-
```
|
|
123
|
-
|
|
124
103
|
### `createExtractor()`
|
|
125
104
|
Creates a context for components that may need to be out of their parent in certain conditions.
|
|
126
105
|
If you have this component
|
|
@@ -255,14 +234,17 @@ return <>
|
|
|
255
234
|
</>
|
|
256
235
|
```
|
|
257
236
|
|
|
258
|
-
### `
|
|
259
|
-
|
|
237
|
+
### `deferCall()`
|
|
238
|
+
Utility function that makes you use an `Accessor` of a `JSX.Element` as a `JSX.Element` itself
|
|
260
239
|
|
|
261
|
-
### `
|
|
262
|
-
|
|
240
|
+
### `untrackCall()`
|
|
241
|
+
Calls a function untracking what happens inside of it but not what gets passed as its argument
|
|
263
242
|
|
|
264
243
|
### `createReactiveResource()`
|
|
265
244
|
Like `createResource()` but the provided function will be reactive
|
|
266
245
|
|
|
267
|
-
### `
|
|
268
|
-
|
|
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
|