solid-ctrl-flow 1.0.39 → 1.0.41
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 +58 -18
- package/dist/index.mjs +56 -51
- package/dist/index.umd.js +54 -49
- package/package.json +1 -1
- package/readMe.md +41 -9
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { Context } from 'solid-js';
|
|
|
3
3
|
import { EffectFunction } from 'solid-js';
|
|
4
4
|
import { JSX } from 'solid-js';
|
|
5
5
|
import { MemoOptions } from 'solid-js';
|
|
6
|
-
import { Ref } from 'solid-js';
|
|
7
6
|
import { Resource } from 'solid-js';
|
|
8
7
|
import { Setter } from 'solid-js';
|
|
9
8
|
import { Signal } from 'solid-js';
|
|
@@ -20,11 +19,12 @@ declare const BASE_CTOR: new <T>() => Accessor<T>;
|
|
|
20
19
|
* @param source The getter of the source of the binding
|
|
21
20
|
* @param dest The setter of the destination of the binding
|
|
22
21
|
* @param to Conversion function from {@link S} to {@link D}
|
|
22
|
+
* @param skip If it is `true`, {@link dest} won't be executed until the next change
|
|
23
23
|
* @returns A function that disposes the binding
|
|
24
24
|
*/
|
|
25
|
-
export declare function bind<S>(source: Accessor<S>, dest: Setter<S
|
|
25
|
+
export declare function bind<S>(source: Accessor<S>, dest: Setter<S>, to?: undefined, skip?: boolean): () => void;
|
|
26
26
|
|
|
27
|
-
export declare function bind<S, D>(source: Accessor<S>, dest: Setter<D>, to: Convert<S, D
|
|
27
|
+
export declare function bind<S, D>(source: Accessor<S>, dest: Setter<D>, to: Convert<S, D>, skip?: boolean): () => void;
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Creates a two-way binding between two {@link Signal}s calling {@link bind} two times
|
|
@@ -133,6 +133,18 @@ export declare function createReactiveResource<R>(f: EffectFunction<R | undefine
|
|
|
133
133
|
/** Built-in {@link ReactiveContext} which allows you to display different things in debug mode */
|
|
134
134
|
export declare const debug: ReactiveContext<boolean>;
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Eventually wraps its content into a template if a certain condition is met.
|
|
138
|
+
* The content is memoized in the beginning and will be recycled even if the wrapper changes.
|
|
139
|
+
* You can avoid the memoization trought {@link Standard.unrecycled}, this is needed if you want to use a context provider on your template.
|
|
140
|
+
* If {@link Keyed.keyed} is active, the template will be executed each time the content of {@link Standard.when} changes.
|
|
141
|
+
* If {@link Standard.unrecycled} is 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).
|
|
142
|
+
* If both {@link Keyed.keyed} and {@link Standard.unrecycled} are active, the content will be executed each time {@link Standard.when} changes
|
|
143
|
+
*/
|
|
144
|
+
export declare function Enfold<T>(props: Keyed<T>): JSX.Element;
|
|
145
|
+
|
|
146
|
+
export declare function Enfold<T>(props: Unkeyed<T>): JSX.Element;
|
|
147
|
+
|
|
136
148
|
/** Handy type alias */
|
|
137
149
|
declare type Equals = MemoOptions<unknown>["equals"];
|
|
138
150
|
|
|
@@ -143,6 +155,12 @@ declare type Info = {
|
|
|
143
155
|
children: JSX.Element;
|
|
144
156
|
};
|
|
145
157
|
|
|
158
|
+
/** Parameters to pass to a keyed {@link Enfold} */
|
|
159
|
+
declare type Keyed<T> = Standard<T> & {
|
|
160
|
+
keyed: true;
|
|
161
|
+
template: Template<NonNullable<T>>;
|
|
162
|
+
};
|
|
163
|
+
|
|
146
164
|
/**
|
|
147
165
|
* Memoizes some of the properties of {@link obj}.
|
|
148
166
|
* If {@link keys} is not provided, memoizes everything that get returned by {@link Object.keys} when provided with {@link obj}.
|
|
@@ -158,11 +176,11 @@ export declare function memoProps<T, K extends readonly (keyof T)[]>(obj: T, key
|
|
|
158
176
|
/**
|
|
159
177
|
* Like a {@link For}, but instead of putting an element after another it nests them.
|
|
160
178
|
* The component will try to recycle the layers when the source array changes (Once again, like the {@link For}).
|
|
161
|
-
* Due to the recyling, the layers will be created indipendently, thus their {@link Owner}s won't be nested in their parents' ones.
|
|
179
|
+
* 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.
|
|
162
180
|
* Example:
|
|
163
181
|
* ```tsx
|
|
164
182
|
* return <>
|
|
165
|
-
* <Nest each={[ 1, 2, 3 ]} template={(
|
|
183
|
+
* <Nest each={[ 1, 2, 3 ]} template={(c, x) => <>({x}, {c()}, -{x})</>}>
|
|
166
184
|
* content
|
|
167
185
|
* </Nest>
|
|
168
186
|
* </>
|
|
@@ -170,8 +188,8 @@ export declare function memoProps<T, K extends readonly (keyof T)[]>(obj: T, key
|
|
|
170
188
|
* Will output "(1, (2, (3, content, -3), -2), -1)"
|
|
171
189
|
*/
|
|
172
190
|
export declare function Nest<T>(props: {
|
|
173
|
-
each: T[];
|
|
174
|
-
template: (
|
|
191
|
+
each: readonly T[] | undefined;
|
|
192
|
+
template: (c: Accessor<JSX.Element>, x: T, i: Accessor<number>) => JSX.Element;
|
|
175
193
|
children: JSX.Element;
|
|
176
194
|
}): JSX.Element;
|
|
177
195
|
|
|
@@ -214,15 +232,6 @@ export declare abstract class ReactiveContext<T> extends BASE_CTOR<T> {
|
|
|
214
232
|
static create<T>(defaultValue: T, name?: string): ReactiveContext<T>;
|
|
215
233
|
}
|
|
216
234
|
|
|
217
|
-
/**
|
|
218
|
-
* Executes a {@link Ref}.
|
|
219
|
-
* Throws a {@link ReferenceError} if {@link ref} its not a function at runtime (Which should never be the case thanks to the solid compiler)
|
|
220
|
-
* @param ref The function to execute
|
|
221
|
-
* @param value The value to pass to the function
|
|
222
|
-
* @returns The same value of {@link value}
|
|
223
|
-
*/
|
|
224
|
-
export declare function refCall<T, U extends T = T>(ref: Ref<T> | undefined, value: U): U;
|
|
225
|
-
|
|
226
235
|
/**
|
|
227
236
|
* Executes {@link f} with the provided value for the specified {@link Context}.
|
|
228
237
|
* You can pass `undefined` to {@link value} in order to get back the default value for {@link ctx}.
|
|
@@ -244,6 +253,16 @@ export declare function runWithContext<T, R>(ctx: Context<T>, value: T | undefin
|
|
|
244
253
|
*/
|
|
245
254
|
export declare function splitAndMemoProps<T extends Record<any, any>, K extends readonly (keyof T)[]>(obj: T, keys: K, equals?: Equals): [Pick<T, Extract<K, readonly (keyof T)[]>[number]>, Omit<T, K[number]>];
|
|
246
255
|
|
|
256
|
+
/** Standard parameters to pass to an {@link Enfold} */
|
|
257
|
+
declare type Standard<T> = {
|
|
258
|
+
when: T;
|
|
259
|
+
children: JSX.Element;
|
|
260
|
+
unrecycled?: boolean;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/** Type of an element wrapping call-back which accepts an additional parameter */
|
|
264
|
+
declare type Template<T> = (c: Accessor<JSX.Element>, x: T) => JSX.Element;
|
|
265
|
+
|
|
247
266
|
/**
|
|
248
267
|
* Creates a full-fledged solid {@link Setter} from a normal one
|
|
249
268
|
* @param get The getter of the {@link Signal}; It's needed when a function gets passed to the new setter
|
|
@@ -258,6 +277,12 @@ export declare function toSetter<T>(get: Accessor<T>, set: (x: T) => void): Sett
|
|
|
258
277
|
*/
|
|
259
278
|
export declare function toSignal<T, K extends keyof T>(obj: Accessor<T>, k: Accessor<K>): Signal<T[K]>;
|
|
260
279
|
|
|
280
|
+
/** Parameters to pass to an unkeyed {@link Enfold} */
|
|
281
|
+
declare type Unkeyed<T> = Standard<T> & {
|
|
282
|
+
keyed?: false;
|
|
283
|
+
template: Template<Accessor<NonNullable<T>>>;
|
|
284
|
+
};
|
|
285
|
+
|
|
261
286
|
/**
|
|
262
287
|
* Executes {@link f} untracking it.
|
|
263
288
|
* Due to the fact that the function is passed as input, it does not untrack its changes (It's intentional)
|
|
@@ -269,11 +294,26 @@ export declare function toSignal<T, K extends keyof T>(obj: Accessor<T>, k: Acce
|
|
|
269
294
|
export declare function untrackCall<F extends (...args: any[]) => unknown>(this: ThisParameterType<F>, f: F, ...args: Parameters<F>): ReturnType<F>;
|
|
270
295
|
|
|
271
296
|
/**
|
|
272
|
-
* Calls an {@link Accessor} maintaining its reactivity
|
|
297
|
+
* Calls an {@link Accessor} maintaining its reactivity at 1 level.
|
|
298
|
+
* The `typeof` operator on the output returns `"function"`, so you have to wrap it if you use it in, for example, in a {@link Setter} and you don't want it to be invoked
|
|
273
299
|
* @param f The {@link Accessor} to the value to emulate
|
|
274
300
|
* @returns A {@link Proxy} that copies the functionalities of the result of {@link f} calling it for each interaction, thus maintaining reactivity
|
|
275
301
|
*/
|
|
276
|
-
export declare const unwrap: <T>(f: Accessor<T>) => T;
|
|
302
|
+
export declare const unwrap: <T extends object>(f: Accessor<T>) => T;
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Calls {@link f} maintaining its reactivity at 2 levels.
|
|
306
|
+
* Unlike the normal {@link unwrap}, this maintains reactivity on the elements of the array too, which means that it can be destructured
|
|
307
|
+
* ```ts
|
|
308
|
+
* const first = unwrap(f); // The value of "first" is reactive but CANNOT be destructured
|
|
309
|
+
* const [ getFirst ] = first; // The value of "getFirst" is NOT reactive, it's the first element of the CURRENT signal returned by "f"
|
|
310
|
+
*
|
|
311
|
+
* const second = unwrapSignal(f); // The value of "second" is reactive and CAN be destructured
|
|
312
|
+
* const [ getSecond ] = second; // The value of "getSecond" IS reactive, it's a function that calls "f", gets the first element and calls that too
|
|
313
|
+
* ```
|
|
314
|
+
* @param f An {@link Accessor} to a {@link Signal}
|
|
315
|
+
*/
|
|
316
|
+
export declare function unwrapSignal<T>(f: Accessor<Signal<T>>): Signal<T>;
|
|
277
317
|
|
|
278
318
|
/** Like a {@link Match} but gets the value from the closest {@link Case} ancestor */
|
|
279
319
|
export declare function When(props: {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useContext, createMemo, createComponent, createContext, createRoot, getOwner, Match, mergeProps,
|
|
1
|
+
import { useContext, createMemo, createComponent, createContext, createRoot, getOwner, Match, mergeProps, splitProps, createEffect, on, createResource, untrack, Show, onCleanup, For, mapArray, createSignal, onMount, createRenderEffect } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
const BASE_CTOR = Function;
|
|
4
4
|
class ReactiveContext extends BASE_CTOR {
|
|
@@ -78,6 +78,51 @@ function When(props) {
|
|
|
78
78
|
}
|
|
79
79
|
}, other));
|
|
80
80
|
}
|
|
81
|
+
function memoProps(obj, keys = Object.keys(obj), equals = false) {
|
|
82
|
+
const out = {};
|
|
83
|
+
for (const elm of keys)
|
|
84
|
+
Object.defineProperty(out, elm, { enumerable: true, get: createMemo(() => obj[elm], void 0, { equals }) });
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
function splitAndMemoProps(obj, keys, equals) {
|
|
88
|
+
const out = splitProps(obj, keys);
|
|
89
|
+
out[0] = memoProps(out[0], keys, equals);
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
function createReactiveResource(f) {
|
|
93
|
+
var refetch;
|
|
94
|
+
const memo = createMemo(f);
|
|
95
|
+
createEffect(on(memo, () => refetch?.()));
|
|
96
|
+
const [get] = [, { refetch }] = createResource(memo);
|
|
97
|
+
return get;
|
|
98
|
+
}
|
|
99
|
+
function untrackCall(f, ...args) {
|
|
100
|
+
return untrack(() => f.apply(this, args));
|
|
101
|
+
}
|
|
102
|
+
const unwrap = (f) => new Proxy(f, HANDLER);
|
|
103
|
+
const HANDLER = new Proxy({}, {
|
|
104
|
+
get(cache, k) {
|
|
105
|
+
return cache[k] ??= (t, ...args) => {
|
|
106
|
+
return Reflect[k](t(), ...args);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
function Enfold(props) {
|
|
111
|
+
const f = () => props.children;
|
|
112
|
+
const children = unwrap(createMemo(() => props.unrecycled ? f : createMemo(f)));
|
|
113
|
+
return createComponent(Show, {
|
|
114
|
+
get keyed() {
|
|
115
|
+
return props.keyed;
|
|
116
|
+
},
|
|
117
|
+
get when() {
|
|
118
|
+
return props.when;
|
|
119
|
+
},
|
|
120
|
+
get fallback() {
|
|
121
|
+
return children();
|
|
122
|
+
},
|
|
123
|
+
children: (x) => createMemo(() => untrackCall(props.template, children, x))
|
|
124
|
+
});
|
|
125
|
+
}
|
|
81
126
|
function createExtractor(name = "extractor") {
|
|
82
127
|
const ctx2 = createContext(void 0, {
|
|
83
128
|
name
|
|
@@ -151,47 +196,11 @@ function Joint(props) {
|
|
|
151
196
|
}
|
|
152
197
|
});
|
|
153
198
|
}
|
|
154
|
-
function untrackCall(f, ...args) {
|
|
155
|
-
return untrack(() => f.apply(this, args));
|
|
156
|
-
}
|
|
157
|
-
function refCall(ref, value) {
|
|
158
|
-
if (!ref)
|
|
159
|
-
return value;
|
|
160
|
-
if (typeof ref !== "function")
|
|
161
|
-
throw new ReferenceError('Il parametro "ref" deve essere stato compilato in una funzione a runtime');
|
|
162
|
-
ref(value);
|
|
163
|
-
return value;
|
|
164
|
-
}
|
|
165
|
-
function memoProps(obj, keys = Object.keys(obj), equals = false) {
|
|
166
|
-
const out = {};
|
|
167
|
-
for (const elm of keys)
|
|
168
|
-
Object.defineProperty(out, elm, {
|
|
169
|
-
enumerable: true,
|
|
170
|
-
get: createMemo(() => obj[elm], void 0, {
|
|
171
|
-
equals
|
|
172
|
-
})
|
|
173
|
-
});
|
|
174
|
-
return out;
|
|
175
|
-
}
|
|
176
|
-
function splitAndMemoProps(obj, keys, equals) {
|
|
177
|
-
const out = splitProps(obj, keys);
|
|
178
|
-
out[0] = memoProps(out[0], keys, equals);
|
|
179
|
-
return out;
|
|
180
|
-
}
|
|
181
|
-
function createReactiveResource(f) {
|
|
182
|
-
var refetch;
|
|
183
|
-
const memo = createMemo(f);
|
|
184
|
-
createEffect(on(memo, () => refetch?.()));
|
|
185
|
-
const [get] = [, {
|
|
186
|
-
refetch
|
|
187
|
-
}] = createResource(memo);
|
|
188
|
-
return get;
|
|
189
|
-
}
|
|
190
199
|
function Nest(props) {
|
|
191
200
|
const memo = memoProps(props, ["template", "children"]);
|
|
192
201
|
const content = mapArray(() => props.each, (x, i) => {
|
|
193
202
|
const [get, set] = createSignal();
|
|
194
|
-
const out = memo.template
|
|
203
|
+
const out = createMemo(() => untrackCall(memo.template, get, x, i));
|
|
195
204
|
return (x2) => {
|
|
196
205
|
onMount(() => set(() => x2));
|
|
197
206
|
onCleanup(() => set(void 0));
|
|
@@ -201,13 +210,13 @@ function Nest(props) {
|
|
|
201
210
|
return createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
|
|
202
211
|
}
|
|
203
212
|
const IDENTITY = (x) => x;
|
|
204
|
-
function bind(source, dest, to = IDENTITY) {
|
|
205
|
-
const d = createRoot((d2) => (createRenderEffect(on(source, (x) => dest((prev) => to(x, prev)))), d2));
|
|
213
|
+
function bind(source, dest, to = IDENTITY, skip = false) {
|
|
214
|
+
const d = createRoot((d2) => (createRenderEffect(on(source, (x) => skip ? skip = false : dest((prev) => to(x, prev)))), d2));
|
|
206
215
|
return onCleanup(d), d;
|
|
207
216
|
}
|
|
208
217
|
function bindTwoWay(source, dest, to, from) {
|
|
209
218
|
const a = bind(source[0], dest[1], to);
|
|
210
|
-
const b = bind(dest[0], source[1], from);
|
|
219
|
+
const b = bind(dest[0], source[1], from, true);
|
|
211
220
|
return () => (a(), b());
|
|
212
221
|
}
|
|
213
222
|
function toSetter(get, set) {
|
|
@@ -223,17 +232,13 @@ function toSignal(obj, k) {
|
|
|
223
232
|
function coalesceSignal([get, set], f) {
|
|
224
233
|
return [() => get() ?? set(f), set];
|
|
225
234
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return cache[k] ??= (t, ...args) => {
|
|
230
|
-
return Reflect[k](t(), ...args);
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
});
|
|
235
|
+
function unwrapSignal(f) {
|
|
236
|
+
return [() => f()[0](), (x) => f()[1](x)];
|
|
237
|
+
}
|
|
234
238
|
const debug = ReactiveContext.create(false, "debug-scope");
|
|
235
239
|
export {
|
|
236
240
|
Case,
|
|
241
|
+
Enfold,
|
|
237
242
|
Nest,
|
|
238
243
|
ReactiveContext,
|
|
239
244
|
When,
|
|
@@ -244,11 +249,11 @@ export {
|
|
|
244
249
|
createReactiveResource,
|
|
245
250
|
debug,
|
|
246
251
|
memoProps,
|
|
247
|
-
refCall,
|
|
248
252
|
runWithContext,
|
|
249
253
|
splitAndMemoProps,
|
|
250
254
|
toSetter,
|
|
251
255
|
toSignal,
|
|
252
256
|
untrackCall,
|
|
253
|
-
unwrap
|
|
257
|
+
unwrap,
|
|
258
|
+
unwrapSignal
|
|
254
259
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -80,6 +80,51 @@
|
|
|
80
80
|
}
|
|
81
81
|
}, other));
|
|
82
82
|
}
|
|
83
|
+
function memoProps(obj, keys = Object.keys(obj), equals = false) {
|
|
84
|
+
const out = {};
|
|
85
|
+
for (const elm of keys)
|
|
86
|
+
Object.defineProperty(out, elm, { enumerable: true, get: solidJs.createMemo(() => obj[elm], void 0, { equals }) });
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
function splitAndMemoProps(obj, keys, equals) {
|
|
90
|
+
const out = solidJs.splitProps(obj, keys);
|
|
91
|
+
out[0] = memoProps(out[0], keys, equals);
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
function createReactiveResource(f) {
|
|
95
|
+
var refetch;
|
|
96
|
+
const memo = solidJs.createMemo(f);
|
|
97
|
+
solidJs.createEffect(solidJs.on(memo, () => refetch?.()));
|
|
98
|
+
const [get] = [, { refetch }] = solidJs.createResource(memo);
|
|
99
|
+
return get;
|
|
100
|
+
}
|
|
101
|
+
function untrackCall(f, ...args) {
|
|
102
|
+
return solidJs.untrack(() => f.apply(this, args));
|
|
103
|
+
}
|
|
104
|
+
const unwrap = (f) => new Proxy(f, HANDLER);
|
|
105
|
+
const HANDLER = new Proxy({}, {
|
|
106
|
+
get(cache, k) {
|
|
107
|
+
return cache[k] ??= (t, ...args) => {
|
|
108
|
+
return Reflect[k](t(), ...args);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
function Enfold(props) {
|
|
113
|
+
const f = () => props.children;
|
|
114
|
+
const children = unwrap(solidJs.createMemo(() => props.unrecycled ? f : solidJs.createMemo(f)));
|
|
115
|
+
return solidJs.createComponent(solidJs.Show, {
|
|
116
|
+
get keyed() {
|
|
117
|
+
return props.keyed;
|
|
118
|
+
},
|
|
119
|
+
get when() {
|
|
120
|
+
return props.when;
|
|
121
|
+
},
|
|
122
|
+
get fallback() {
|
|
123
|
+
return children();
|
|
124
|
+
},
|
|
125
|
+
children: (x) => solidJs.createMemo(() => untrackCall(props.template, children, x))
|
|
126
|
+
});
|
|
127
|
+
}
|
|
83
128
|
function createExtractor(name = "extractor") {
|
|
84
129
|
const ctx2 = solidJs.createContext(void 0, {
|
|
85
130
|
name
|
|
@@ -153,47 +198,11 @@
|
|
|
153
198
|
}
|
|
154
199
|
});
|
|
155
200
|
}
|
|
156
|
-
function untrackCall(f, ...args) {
|
|
157
|
-
return solidJs.untrack(() => f.apply(this, args));
|
|
158
|
-
}
|
|
159
|
-
function refCall(ref, value) {
|
|
160
|
-
if (!ref)
|
|
161
|
-
return value;
|
|
162
|
-
if (typeof ref !== "function")
|
|
163
|
-
throw new ReferenceError('Il parametro "ref" deve essere stato compilato in una funzione a runtime');
|
|
164
|
-
ref(value);
|
|
165
|
-
return value;
|
|
166
|
-
}
|
|
167
|
-
function memoProps(obj, keys = Object.keys(obj), equals = false) {
|
|
168
|
-
const out = {};
|
|
169
|
-
for (const elm of keys)
|
|
170
|
-
Object.defineProperty(out, elm, {
|
|
171
|
-
enumerable: true,
|
|
172
|
-
get: solidJs.createMemo(() => obj[elm], void 0, {
|
|
173
|
-
equals
|
|
174
|
-
})
|
|
175
|
-
});
|
|
176
|
-
return out;
|
|
177
|
-
}
|
|
178
|
-
function splitAndMemoProps(obj, keys, equals) {
|
|
179
|
-
const out = solidJs.splitProps(obj, keys);
|
|
180
|
-
out[0] = memoProps(out[0], keys, equals);
|
|
181
|
-
return out;
|
|
182
|
-
}
|
|
183
|
-
function createReactiveResource(f) {
|
|
184
|
-
var refetch;
|
|
185
|
-
const memo = solidJs.createMemo(f);
|
|
186
|
-
solidJs.createEffect(solidJs.on(memo, () => refetch?.()));
|
|
187
|
-
const [get] = [, {
|
|
188
|
-
refetch
|
|
189
|
-
}] = solidJs.createResource(memo);
|
|
190
|
-
return get;
|
|
191
|
-
}
|
|
192
201
|
function Nest(props) {
|
|
193
202
|
const memo = memoProps(props, ["template", "children"]);
|
|
194
203
|
const content = solidJs.mapArray(() => props.each, (x, i) => {
|
|
195
204
|
const [get, set] = solidJs.createSignal();
|
|
196
|
-
const out = memo.template
|
|
205
|
+
const out = solidJs.createMemo(() => untrackCall(memo.template, get, x, i));
|
|
197
206
|
return (x2) => {
|
|
198
207
|
solidJs.onMount(() => set(() => x2));
|
|
199
208
|
solidJs.onCleanup(() => set(void 0));
|
|
@@ -203,13 +212,13 @@
|
|
|
203
212
|
return solidJs.createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
|
|
204
213
|
}
|
|
205
214
|
const IDENTITY = (x) => x;
|
|
206
|
-
function bind(source, dest, to = IDENTITY) {
|
|
207
|
-
const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(source, (x) => dest((prev) => to(x, prev)))), d2));
|
|
215
|
+
function bind(source, dest, to = IDENTITY, skip = false) {
|
|
216
|
+
const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(source, (x) => skip ? skip = false : dest((prev) => to(x, prev)))), d2));
|
|
208
217
|
return solidJs.onCleanup(d), d;
|
|
209
218
|
}
|
|
210
219
|
function bindTwoWay(source, dest, to, from) {
|
|
211
220
|
const a = bind(source[0], dest[1], to);
|
|
212
|
-
const b = bind(dest[0], source[1], from);
|
|
221
|
+
const b = bind(dest[0], source[1], from, true);
|
|
213
222
|
return () => (a(), b());
|
|
214
223
|
}
|
|
215
224
|
function toSetter(get, set) {
|
|
@@ -225,16 +234,12 @@
|
|
|
225
234
|
function coalesceSignal([get, set], f) {
|
|
226
235
|
return [() => get() ?? set(f), set];
|
|
227
236
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return cache[k] ??= (t, ...args) => {
|
|
232
|
-
return Reflect[k](t(), ...args);
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
});
|
|
237
|
+
function unwrapSignal(f) {
|
|
238
|
+
return [() => f()[0](), (x) => f()[1](x)];
|
|
239
|
+
}
|
|
236
240
|
const debug = ReactiveContext.create(false, "debug-scope");
|
|
237
241
|
exports2.Case = Case;
|
|
242
|
+
exports2.Enfold = Enfold;
|
|
238
243
|
exports2.Nest = Nest;
|
|
239
244
|
exports2.ReactiveContext = ReactiveContext;
|
|
240
245
|
exports2.When = When;
|
|
@@ -245,12 +250,12 @@
|
|
|
245
250
|
exports2.createReactiveResource = createReactiveResource;
|
|
246
251
|
exports2.debug = debug;
|
|
247
252
|
exports2.memoProps = memoProps;
|
|
248
|
-
exports2.refCall = refCall;
|
|
249
253
|
exports2.runWithContext = runWithContext;
|
|
250
254
|
exports2.splitAndMemoProps = splitAndMemoProps;
|
|
251
255
|
exports2.toSetter = toSetter;
|
|
252
256
|
exports2.toSignal = toSignal;
|
|
253
257
|
exports2.untrackCall = untrackCall;
|
|
254
258
|
exports2.unwrap = unwrap;
|
|
259
|
+
exports2.unwrapSignal = unwrapSignal;
|
|
255
260
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
256
261
|
});
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -34,12 +34,44 @@ return <>
|
|
|
34
34
|
</>
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
### `Enfold`
|
|
38
|
+
Eventually wraps its content into a template if a certain condition is met.
|
|
39
|
+
The following code
|
|
40
|
+
```tsx
|
|
41
|
+
const value = true;
|
|
42
|
+
return <>
|
|
43
|
+
<Enfold when={value} template={c => <div style={{ background: "red" }}>{c()}</div>}>
|
|
44
|
+
content
|
|
45
|
+
</Enfold>
|
|
46
|
+
</>
|
|
47
|
+
```
|
|
48
|
+
Is equivalent to this
|
|
49
|
+
```tsx
|
|
50
|
+
return <>
|
|
51
|
+
<div style={{ background: "red" }}>
|
|
52
|
+
content
|
|
53
|
+
</div>
|
|
54
|
+
</>
|
|
55
|
+
```
|
|
56
|
+
And if `value` was falsish, it would have been equivalent to this
|
|
57
|
+
```tsx
|
|
58
|
+
return <>content</>
|
|
59
|
+
```
|
|
60
|
+
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
|
|
61
|
+
```tsx
|
|
62
|
+
return <>
|
|
63
|
+
<Enfold unrecycled when={value} template={c => <ctx.Provider value={2} children={c()} />}>
|
|
64
|
+
{useContext(ctx)}
|
|
65
|
+
</Enfold>
|
|
66
|
+
</>
|
|
67
|
+
```
|
|
68
|
+
|
|
37
69
|
### `Nest`
|
|
38
70
|
Like a `For`, but instead of putting an element after another it nests them.
|
|
39
71
|
The following code
|
|
40
72
|
```tsx
|
|
41
73
|
return <>
|
|
42
|
-
<Nest each={[ "red", "green", "blue" ]} template={(
|
|
74
|
+
<Nest each={[ "red", "green", "blue" ]} template={(c, x) => <div style={{ background: x, padding: "1ch" }}>{c()}</div>}>
|
|
43
75
|
content
|
|
44
76
|
</Nest>
|
|
45
77
|
</>
|
|
@@ -150,6 +182,9 @@ Functions that create bindings between `Signal`s
|
|
|
150
182
|
>
|
|
151
183
|
> #### `coalesceSignal()`
|
|
152
184
|
> Creates a non nullable `Signal` from a nullable one
|
|
185
|
+
>
|
|
186
|
+
> #### `unwrapSignal()`
|
|
187
|
+
> A `Signal`-specific version of `unwrap()` that allows the destructuring of its result
|
|
153
188
|
|
|
154
189
|
### `ReactiveContext.create()`
|
|
155
190
|
Method that creates a reactive version of a solid `Context` with some additional built-in functionalities
|
|
@@ -164,7 +199,7 @@ const value = ctx();
|
|
|
164
199
|
Creates a context scope that persists for the duration of a function
|
|
165
200
|
|
|
166
201
|
### `unwrap()`
|
|
167
|
-
Calls an `Accessor` maintaining its reactivity
|
|
202
|
+
Calls an `Accessor` maintaining its reactivity at 1 level
|
|
168
203
|
|
|
169
204
|
### `debug()`
|
|
170
205
|
Allows you to define ui section that are only visible in debug or NOT in debug
|
|
@@ -180,12 +215,6 @@ return <>
|
|
|
180
215
|
</>
|
|
181
216
|
```
|
|
182
217
|
|
|
183
|
-
### `untrackCall()`
|
|
184
|
-
Calls a function untracking what happens inside of it but not what gets passed as its argument
|
|
185
|
-
|
|
186
|
-
### `refCall()`
|
|
187
|
-
Executes a `Ref`
|
|
188
|
-
|
|
189
218
|
### `memoProps()`
|
|
190
219
|
Creates a partial version of an object with memoized remaining properties
|
|
191
220
|
|
|
@@ -193,4 +222,7 @@ Creates a partial version of an object with memoized remaining properties
|
|
|
193
222
|
Like `splitProps()` but memoizes the whole local part
|
|
194
223
|
|
|
195
224
|
### `createReactiveResource()`
|
|
196
|
-
Like `createResource()` but the provided function will be reactive
|
|
225
|
+
Like `createResource()` but the provided function will be reactive
|
|
226
|
+
|
|
227
|
+
### `untrackCall()`
|
|
228
|
+
Calls a function untracking what happens inside of it but not what gets passed as its argument
|