solid-ctrl-flow 1.0.48 → 1.0.50
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 -27
- package/dist/index.mjs +7 -21
- package/dist/index.umd.js +6 -20
- package/package.json +1 -1
- package/readMe.md +5 -27
package/dist/index.d.ts
CHANGED
|
@@ -129,11 +129,11 @@ export declare const debug: ReactiveContext<boolean>;
|
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
131
|
* Eventually wraps its content into a template if a certain condition is met.
|
|
132
|
-
*
|
|
133
|
-
* You can
|
|
132
|
+
* If you set {@link Standard.recycled} to `true`, the content will be memoized in the beginning and will be recycled even if the wrapper changes.
|
|
133
|
+
* You can't use memoization if you want to use a context provider on your template.
|
|
134
134
|
* If {@link Keyed.keyed} is active, the template will be executed each time the content of {@link Standard.when} changes.
|
|
135
|
-
* If {@link Standard.
|
|
136
|
-
* If
|
|
135
|
+
* If {@link Standard.recycled} is not active, the content will be executed each time it is mounted (Each time {@link Standard.when} goes from a falsish value to a truish one and vice versa).
|
|
136
|
+
* If {@link Keyed.keyed} is active and {@link Standard.recycled} isn't, the content will be executed each time {@link Standard.when} changes
|
|
137
137
|
*/
|
|
138
138
|
export declare function Enfold<T>(props: Keyed<T>): JSX.Element;
|
|
139
139
|
|
|
@@ -160,25 +160,6 @@ export declare function memoProps<T>(obj: T, keys?: undefined, equals?: Equals):
|
|
|
160
160
|
|
|
161
161
|
export declare function memoProps<T, K extends readonly (keyof T)[]>(obj: T, keys: K, equals?: Equals): Pick<T, K[number]>;
|
|
162
162
|
|
|
163
|
-
/**
|
|
164
|
-
* Like a {@link For}, but instead of putting an element after another it nests them.
|
|
165
|
-
* The component will try to recycle the layers when the source array changes (Once again, like the {@link For}).
|
|
166
|
-
* Due to the recyling, the layers will be created indipendently, thus their {@link Owner}s won't be nested in their parents' ones, this makes the component unsuitable to wrap the content with context providers.
|
|
167
|
-
* Example:
|
|
168
|
-
* ```tsx
|
|
169
|
-
* return <>
|
|
170
|
-
* <Nest each={[ 1, 2, 3 ]} template={(c, x) => <>({x}, {c}, -{x})</>}>
|
|
171
|
-
* CONTENT
|
|
172
|
-
* </Nest>
|
|
173
|
-
* </>
|
|
174
|
-
* ```
|
|
175
|
-
* Will output "(1, (2, (3, CONTENT, -3), -2), -1)"
|
|
176
|
-
*/
|
|
177
|
-
export declare function Nest<T>(props: ParentProps<{
|
|
178
|
-
each: readonly T[] | undefined;
|
|
179
|
-
template: (c: JSX.Element, x: T, i: Accessor<number>) => JSX.Element;
|
|
180
|
-
}>): JSX.Element;
|
|
181
|
-
|
|
182
163
|
/**
|
|
183
164
|
* Allows the use of {@link Case}s inside of {@link Switch}es.
|
|
184
165
|
* Example:
|
|
@@ -215,7 +196,7 @@ export declare const On: (props: ParentProps<{
|
|
|
215
196
|
|
|
216
197
|
/**
|
|
217
198
|
* Reactive {@link Context} with some additional built-in functionalities.
|
|
218
|
-
* The call signature returns the value in the current {@link Owner} (It's like calling {@link
|
|
199
|
+
* The call signature returns the value in the current {@link Owner} (It's like calling {@link get})
|
|
219
200
|
*/
|
|
220
201
|
export declare abstract class ReactiveContext<T> extends BASE_CTOR<T> {
|
|
221
202
|
/** The actual {@link Context} that contains the reactive {@link Accessor} to the value */
|
|
@@ -224,7 +205,7 @@ export declare abstract class ReactiveContext<T> extends BASE_CTOR<T> {
|
|
|
224
205
|
* Returns the {@link Accessor} for the value in the current {@link Owner}.
|
|
225
206
|
* It's like calling {@link useContext}
|
|
226
207
|
*/
|
|
227
|
-
get
|
|
208
|
+
get get(): Accessor<T>;
|
|
228
209
|
/**
|
|
229
210
|
* Component that sets the value of the current {@link Context} for its children.
|
|
230
211
|
* If no value is provided then it will use the default value for {@link ctx}.
|
|
@@ -307,11 +288,11 @@ export declare function splitAndMemoProps<T extends Record<any, any>, K extends
|
|
|
307
288
|
/** Standard parameters to pass to an {@link Enfold} */
|
|
308
289
|
declare type Standard<T> = ParentProps<{
|
|
309
290
|
when: T;
|
|
310
|
-
|
|
291
|
+
recycled?: boolean;
|
|
311
292
|
}>;
|
|
312
293
|
|
|
313
294
|
/** Type of an element wrapping call-back which accepts an additional parameter */
|
|
314
|
-
declare type Template<T> = (c: JSX.Element
|
|
295
|
+
declare type Template<T> = (c: Accessor<JSX.Element>, x: T) => JSX.Element;
|
|
315
296
|
|
|
316
297
|
/**
|
|
317
298
|
* 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, untrack, createEffect, on, createResource, splitProps, Show, onCleanup, For,
|
|
1
|
+
import { useContext, createMemo, createComponent, createContext, createRoot, getOwner, untrack, createEffect, on, createResource, splitProps, Show, onCleanup, For, 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 {
|
|
@@ -7,7 +7,7 @@ class ReactiveContext extends BASE_CTOR {
|
|
|
7
7
|
* Returns the {@link Accessor} for the value in the current {@link Owner}.
|
|
8
8
|
* It's like calling {@link useContext}
|
|
9
9
|
*/
|
|
10
|
-
get
|
|
10
|
+
get get() {
|
|
11
11
|
return useContext(this.ctx);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
@@ -48,7 +48,7 @@ class ReactiveContext extends BASE_CTOR {
|
|
|
48
48
|
const ctx2 = createContext(() => defaultValue, {
|
|
49
49
|
name
|
|
50
50
|
});
|
|
51
|
-
const f = () => out.
|
|
51
|
+
const f = () => out.get();
|
|
52
52
|
f.ctx = ctx2;
|
|
53
53
|
const out = Object.setPrototypeOf(f, ReactiveContext.prototype);
|
|
54
54
|
return out;
|
|
@@ -95,7 +95,7 @@ const HANDLER = new Proxy({}, {
|
|
|
95
95
|
});
|
|
96
96
|
function Enfold(props) {
|
|
97
97
|
const f = () => props.children;
|
|
98
|
-
const children = unwrap(createMemo(() => props.
|
|
98
|
+
const children = unwrap(createMemo(() => props.recycled ? createMemo(f) : f));
|
|
99
99
|
return createComponent(Show, {
|
|
100
100
|
get keyed() {
|
|
101
101
|
return props.keyed;
|
|
@@ -106,7 +106,7 @@ function Enfold(props) {
|
|
|
106
106
|
get fallback() {
|
|
107
107
|
return children();
|
|
108
108
|
},
|
|
109
|
-
children: (x) => createMemo(() => untrackCall(props.template,
|
|
109
|
+
children: (x) => createMemo(() => untrackCall(props.template, children, x))
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
var Slot;
|
|
@@ -217,30 +217,17 @@ function createInfo(props) {
|
|
|
217
217
|
}
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
|
-
function Nest(props) {
|
|
221
|
-
const memo = memoProps(props, ["template", "children"]);
|
|
222
|
-
const content = mapArray(() => props.each, (x, i) => {
|
|
223
|
-
const [get, set] = createSignal();
|
|
224
|
-
const out = createMemo(() => untrackCall(memo.template, createMemo(get), x, i));
|
|
225
|
-
return (x2) => {
|
|
226
|
-
onMount(() => set(() => x2));
|
|
227
|
-
onCleanup(() => set(void 0));
|
|
228
|
-
return out;
|
|
229
|
-
};
|
|
230
|
-
});
|
|
231
|
-
return createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
|
|
232
|
-
}
|
|
233
220
|
const ctx = ReactiveContext.create(void 0, "on-case");
|
|
234
221
|
const On = ctx.Provider;
|
|
235
222
|
function Case(props) {
|
|
236
223
|
const [mine, other] = splitAndMemoProps(props, ["value", "pred"]);
|
|
237
224
|
const {
|
|
238
|
-
|
|
225
|
+
get
|
|
239
226
|
} = ctx;
|
|
240
227
|
const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
|
|
241
228
|
return createComponent(Match, mergeProps({
|
|
242
229
|
get when() {
|
|
243
|
-
return pred(
|
|
230
|
+
return pred(get());
|
|
244
231
|
}
|
|
245
232
|
}, other));
|
|
246
233
|
}
|
|
@@ -291,7 +278,6 @@ function SameContext(props) {
|
|
|
291
278
|
export {
|
|
292
279
|
Case,
|
|
293
280
|
Enfold,
|
|
294
|
-
Nest,
|
|
295
281
|
On,
|
|
296
282
|
ReactiveContext,
|
|
297
283
|
SameContext,
|
package/dist/index.umd.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Returns the {@link Accessor} for the value in the current {@link Owner}.
|
|
10
10
|
* It's like calling {@link useContext}
|
|
11
11
|
*/
|
|
12
|
-
get
|
|
12
|
+
get get() {
|
|
13
13
|
return solidJs.useContext(this.ctx);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
const ctx2 = solidJs.createContext(() => defaultValue, {
|
|
51
51
|
name
|
|
52
52
|
});
|
|
53
|
-
const f = () => out.
|
|
53
|
+
const f = () => out.get();
|
|
54
54
|
f.ctx = ctx2;
|
|
55
55
|
const out = Object.setPrototypeOf(f, ReactiveContext.prototype);
|
|
56
56
|
return out;
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
});
|
|
98
98
|
function Enfold(props) {
|
|
99
99
|
const f = () => props.children;
|
|
100
|
-
const children = unwrap(solidJs.createMemo(() => props.
|
|
100
|
+
const children = unwrap(solidJs.createMemo(() => props.recycled ? solidJs.createMemo(f) : f));
|
|
101
101
|
return solidJs.createComponent(solidJs.Show, {
|
|
102
102
|
get keyed() {
|
|
103
103
|
return props.keyed;
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
get fallback() {
|
|
109
109
|
return children();
|
|
110
110
|
},
|
|
111
|
-
children: (x) => solidJs.createMemo(() => untrackCall(props.template,
|
|
111
|
+
children: (x) => solidJs.createMemo(() => untrackCall(props.template, children, x))
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
exports2.Slot = void 0;
|
|
@@ -219,30 +219,17 @@
|
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
-
function Nest(props) {
|
|
223
|
-
const memo = memoProps(props, ["template", "children"]);
|
|
224
|
-
const content = solidJs.mapArray(() => props.each, (x, i) => {
|
|
225
|
-
const [get, set] = solidJs.createSignal();
|
|
226
|
-
const out = solidJs.createMemo(() => untrackCall(memo.template, solidJs.createMemo(get), x, i));
|
|
227
|
-
return (x2) => {
|
|
228
|
-
solidJs.onMount(() => set(() => x2));
|
|
229
|
-
solidJs.onCleanup(() => set(void 0));
|
|
230
|
-
return out;
|
|
231
|
-
};
|
|
232
|
-
});
|
|
233
|
-
return solidJs.createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
|
|
234
|
-
}
|
|
235
222
|
const ctx = ReactiveContext.create(void 0, "on-case");
|
|
236
223
|
const On = ctx.Provider;
|
|
237
224
|
function Case(props) {
|
|
238
225
|
const [mine, other] = splitAndMemoProps(props, ["value", "pred"]);
|
|
239
226
|
const {
|
|
240
|
-
|
|
227
|
+
get
|
|
241
228
|
} = ctx;
|
|
242
229
|
const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
|
|
243
230
|
return solidJs.createComponent(solidJs.Match, solidJs.mergeProps({
|
|
244
231
|
get when() {
|
|
245
|
-
return pred(
|
|
232
|
+
return pred(get());
|
|
246
233
|
}
|
|
247
234
|
}, other));
|
|
248
235
|
}
|
|
@@ -292,7 +279,6 @@
|
|
|
292
279
|
}
|
|
293
280
|
exports2.Case = Case;
|
|
294
281
|
exports2.Enfold = Enfold;
|
|
295
|
-
exports2.Nest = Nest;
|
|
296
282
|
exports2.On = On;
|
|
297
283
|
exports2.ReactiveContext = ReactiveContext;
|
|
298
284
|
exports2.SameContext = SameContext;
|
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}</div>}>
|
|
25
|
+
<Enfold when={value} template={c => <div style={{ background: "red" }}>{c()}</div>}>
|
|
26
26
|
CONTENT
|
|
27
27
|
</Enfold>
|
|
28
28
|
</>
|
|
@@ -39,38 +39,16 @@ And if `value` was falsish, it would have been equivalent to this
|
|
|
39
39
|
```tsx
|
|
40
40
|
return <>CONTENT</>
|
|
41
41
|
```
|
|
42
|
-
If you are wrapping the content with a context provider you
|
|
42
|
+
If you are NOT wrapping the content with a context provider you can set the `recycled` attribute to `true` in order to NOT run again the whole content each time its template gets added/removed, in this case the `Owner` of the content won't be child of the template one
|
|
43
43
|
```tsx
|
|
44
44
|
return <>
|
|
45
|
-
<Enfold
|
|
45
|
+
<Enfold recycled when={value} template={c => <ctx.Provider value={2} children={c()} />}>
|
|
46
|
+
{/* This won't work */}
|
|
46
47
|
{useContext(ctx)}
|
|
47
48
|
</Enfold>
|
|
48
49
|
</>
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
### `Nest`
|
|
52
|
-
Like a `For`, but instead of putting an element after another it nests them.
|
|
53
|
-
The following code
|
|
54
|
-
```tsx
|
|
55
|
-
return <>
|
|
56
|
-
<Nest each={[ "red", "green", "blue" ]} template={(c, x) => <div style={{ background: x, padding: "1ch" }}>{c}</div>}>
|
|
57
|
-
CONTENT
|
|
58
|
-
</Nest>
|
|
59
|
-
</>
|
|
60
|
-
```
|
|
61
|
-
Is equivalent to this
|
|
62
|
-
```tsx
|
|
63
|
-
return <>
|
|
64
|
-
<div style={{ background: "red", padding: "1ch" }}>
|
|
65
|
-
<div style={{ background: "green", padding: "1ch" }}>
|
|
66
|
-
<div style={{ background: "blue", padding: "1ch" }}>
|
|
67
|
-
CONTENT
|
|
68
|
-
</div>
|
|
69
|
-
</div>
|
|
70
|
-
</div>
|
|
71
|
-
</>
|
|
72
|
-
```
|
|
73
|
-
|
|
74
52
|
### `On` - `Case`
|
|
75
53
|
Allows you to not repeat the same condition across many `Match` components.
|
|
76
54
|
The following code
|
|
@@ -210,7 +188,7 @@ Method that creates a reactive version of a solid `Context` with some additional
|
|
|
210
188
|
```ts
|
|
211
189
|
const ctx = ReactiveContext.create("SOMETHING");
|
|
212
190
|
const underlyingNormalContext = ctx.ctx;
|
|
213
|
-
const valueAccessorForTheCurrentOwner = ctx.
|
|
191
|
+
const valueAccessorForTheCurrentOwner = ctx.get;
|
|
214
192
|
const value = ctx();
|
|
215
193
|
```
|
|
216
194
|
|