solid-ctrl-flow 1.0.35 → 1.0.36

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 CHANGED
@@ -16,8 +16,8 @@ declare const BASE_CTOR: new <T>() => Accessor<T>;
16
16
  * - As soon as the function is done executing the two {@link Signal}s will have the same value
17
17
  * - If {@link source} changes, {@link dest} wont be instantly updated
18
18
  * - If the current owner gets disposed before {@link dest} is updated, it never will
19
- * @param source The getter of source of the binding
20
- * @param dest The setter of destination of the binding
19
+ * @param source The getter of the source of the binding
20
+ * @param dest The setter of the destination of the binding
21
21
  * @param to Conversion function from {@link S} to {@link D}
22
22
  * @returns A function that disposes the binding
23
23
  */
@@ -147,6 +147,26 @@ declare type Info = {
147
147
  */
148
148
  export declare function memoProps<T, K extends readonly (keyof T)[] = (keyof T)[]>(obj: T, keys?: K): Pick<T, K[number]>;
149
149
 
150
+ /**
151
+ * Like a {@link For}, but instead of putting an element after another it nests them.
152
+ * The component will try to recycle the layers when the source array changes (Once again, like the {@link For}).
153
+ * Due to the recyling, the layers will be created indipendently, thus their {@link Owner}s won't be nested in their parents' ones.
154
+ * Example:
155
+ * ```tsx
156
+ * return <>
157
+ * <Nest each={[ 1, 2, 3 ]} template={(x, y) => <>({x}, {y()}, -{x})</>}>
158
+ * content
159
+ * </Nest>
160
+ * </>
161
+ * ```
162
+ * Will output "(1, (2, (3, content, -3), -2), -1)"
163
+ */
164
+ export declare function Nest<T>(props: {
165
+ each: T[];
166
+ template: (x: T, c: Accessor<JSX.Element>, i: Accessor<number>) => JSX.Element;
167
+ children: JSX.Element;
168
+ }): JSX.Element;
169
+
150
170
  /**
151
171
  * Reactive {@link Context} with some additional built-in functionalities.
152
172
  * The call signature returns the value in the current {@link Owner} (It's like calling {@link read})
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useContext, createMemo, createComponent, createContext, Match, mergeProps, onCleanup, For, Show, createRoot, createRenderEffect, on, untrack, splitProps, getOwner, createEffect, createResource } from "solid-js";
1
+ import { useContext, createMemo, createComponent, createContext, Match, mergeProps, onCleanup, For, Show, mapArray, createSignal, onMount, createRoot, createRenderEffect, on, untrack, splitProps, getOwner, createEffect, createResource } from "solid-js";
2
2
  import { createMutable } from "solid-js/store";
3
3
  const BASE_CTOR = Function;
4
4
  class ReactiveContext extends BASE_CTOR {
@@ -141,6 +141,19 @@ function Joint(props) {
141
141
  }
142
142
  });
143
143
  }
144
+ function Nest(props) {
145
+ const memo = memoProps(props, ["template", "children"]);
146
+ const content = mapArray(() => props.each, (x, i) => {
147
+ const [get, set] = createSignal();
148
+ const out = memo.template(x, get, i);
149
+ return (x2) => {
150
+ onMount(() => set(() => x2));
151
+ onCleanup(() => set(void 0));
152
+ return out;
153
+ };
154
+ });
155
+ return createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
156
+ }
144
157
  const IDENTITY = (x) => x;
145
158
  function bind(source, dest, to = IDENTITY) {
146
159
  const d = createRoot((d2) => (createRenderEffect(on(source, (x) => dest((prev) => to(x, prev)))), d2));
@@ -214,6 +227,7 @@ function createReactiveResource(f) {
214
227
  const debug = ReactiveContext.create(false, "debug-scope");
215
228
  export {
216
229
  Case,
230
+ Nest,
217
231
  ReactiveContext,
218
232
  When,
219
233
  bind,
package/dist/index.umd.js CHANGED
@@ -143,6 +143,19 @@
143
143
  }
144
144
  });
145
145
  }
146
+ function Nest(props) {
147
+ const memo = memoProps(props, ["template", "children"]);
148
+ const content = solidJs.mapArray(() => props.each, (x, i) => {
149
+ const [get, set] = solidJs.createSignal();
150
+ const out = memo.template(x, get, i);
151
+ return (x2) => {
152
+ solidJs.onMount(() => set(() => x2));
153
+ solidJs.onCleanup(() => set(void 0));
154
+ return out;
155
+ };
156
+ });
157
+ return solidJs.createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
158
+ }
146
159
  const IDENTITY = (x) => x;
147
160
  function bind(source, dest, to = IDENTITY) {
148
161
  const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(source, (x) => dest((prev) => to(x, prev)))), d2));
@@ -215,6 +228,7 @@
215
228
  }
216
229
  const debug = ReactiveContext.create(false, "debug-scope");
217
230
  exports2.Case = Case;
231
+ exports2.Nest = Nest;
218
232
  exports2.ReactiveContext = ReactiveContext;
219
233
  exports2.When = When;
220
234
  exports2.bind = bind;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "1.0.35",
3
+ "version": "1.0.36",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
package/readMe.md CHANGED
@@ -6,7 +6,7 @@ It's always under hard development
6
6
  ## Components
7
7
 
8
8
  ### `Case` - `When`
9
- Allows you to not specify the full condition inside of a `Switch` component.
9
+ Allows you to not repeat the same condition across many `Match` components.
10
10
  The following code
11
11
  ```tsx
12
12
  const value = 1;
@@ -34,6 +34,29 @@ return <>
34
34
  </>
35
35
  ```
36
36
 
37
+ ### `Nest`
38
+ Like a `For`, but instead of putting an element after another it nests them.
39
+ The following code
40
+ ```tsx
41
+ return <>
42
+ <Nest each={[ "red", "green", "blue" ]} template={(x, y) => <div style={{ background: x, padding: "1ch" }}>{y()}</div>}>
43
+ content
44
+ </Nest>
45
+ </>
46
+ ```
47
+ Is equivalent to this
48
+ ```tsx
49
+ return <>
50
+ <div style={{ background: "red", padding: "1ch" }}>
51
+ <div style={{ background: "green", padding: "1ch" }}>
52
+ <div style={{ background: "blue", padding: "1ch" }}>
53
+ content
54
+ </div>
55
+ </div>
56
+ </div>
57
+ </>
58
+ ```
59
+
37
60
  ### `createExtractor()`
38
61
  Creates a context for components that may need to be out of their parent in certain conditions.
39
62
  If you have this component