solid-ctrl-flow 1.0.26 → 1.0.28
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 +23 -4
- package/dist/index.mjs +25 -10
- package/dist/index.umd.js +24 -9
- package/package.json +1 -1
- package/readMe.md +16 -4
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,17 @@ import { Accessor } from 'solid-js';
|
|
|
2
2
|
import { Context } from 'solid-js';
|
|
3
3
|
import { EffectFunction } from 'solid-js';
|
|
4
4
|
import { JSX } from 'solid-js';
|
|
5
|
+
import { Ref } from 'solid-js';
|
|
5
6
|
import { Resource } from 'solid-js';
|
|
6
7
|
import { Setter } from 'solid-js';
|
|
7
8
|
import { Signal } from 'solid-js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
* Creates a one-way binding between two {@link Signal}s
|
|
11
|
+
* Creates a one-way binding between two {@link Signal}s.
|
|
12
|
+
* The function uses {@link createRenderEffect}, which means that:
|
|
13
|
+
* - As soon as the function is done executing the two {@link Signal}s will have the same value
|
|
14
|
+
* - If {@link source} changes, {@link dest} wont be instantly updated
|
|
15
|
+
* - If the current owner gets disposed before {@link dest} is updated, it never will
|
|
11
16
|
* @param source The source of the binding
|
|
12
17
|
* @param dest The destination of the binding
|
|
13
18
|
* @param to Conversion function from {@link S} to {@link D}
|
|
@@ -18,7 +23,7 @@ export declare function bind<S>(source: Signal<S>, dest: Signal<S>): () => void;
|
|
|
18
23
|
export declare function bind<S, D>(source: Signal<S>, dest: Signal<D>, to: Convert<S, D>): () => void;
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
|
-
* Creates a two-way binding between two {@link Signal}s
|
|
26
|
+
* Creates a two-way binding between two {@link Signal}s calling {@link bind} two times
|
|
22
27
|
* @param source The source of the binding
|
|
23
28
|
* @param dest The destination of the binding
|
|
24
29
|
* @param to Conversion function from {@link S} to {@link D}
|
|
@@ -68,7 +73,7 @@ export declare function Case(props: {
|
|
|
68
73
|
* Returns a {@link Signal} that applies the `??=` operator to the input one.
|
|
69
74
|
* If the getter of {@link param0} is like "x", then the result one is like "(x ??= {@link f}())"
|
|
70
75
|
* @param param0 The {@link Signal} to which to coalesce the getter
|
|
71
|
-
* @param f
|
|
76
|
+
* @param f An {@link Accessor} to the value to use when there's a nullish value
|
|
72
77
|
*/
|
|
73
78
|
export declare function coalesceSignal<T>([get, set]: Signal<T | undefined>, f: Accessor<T>): Signal<T>;
|
|
74
79
|
|
|
@@ -152,6 +157,11 @@ export declare const Debug: {
|
|
|
152
157
|
read: Accessor<boolean>;
|
|
153
158
|
};
|
|
154
159
|
|
|
160
|
+
/** Component that gives you the owner {@link Document} */
|
|
161
|
+
export declare function Doc(props: {
|
|
162
|
+
ref: Ref<Document>;
|
|
163
|
+
}): Text;
|
|
164
|
+
|
|
155
165
|
/** Informations about a {@link Source} component */
|
|
156
166
|
declare type Info = {
|
|
157
167
|
/** Order of the current source if there are many */
|
|
@@ -167,6 +177,15 @@ declare type Info = {
|
|
|
167
177
|
*/
|
|
168
178
|
export declare function memoProps<T, K extends readonly (keyof T)[] = (keyof T)[]>(obj: T, keys?: K): Pick<T, K[number]>;
|
|
169
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Executes a {@link Ref}.
|
|
182
|
+
* Throws a {@link ReferenceError} if {@link ref} its not a function at runtime (Which should never be the case thanks to the solid compiler)
|
|
183
|
+
* @param ref The function to execute
|
|
184
|
+
* @param value The value to pass to the function
|
|
185
|
+
* @returns The same value of {@link value}
|
|
186
|
+
*/
|
|
187
|
+
export declare function refCall<T, U extends T = T>(ref: Ref<T> | undefined, value: U): U;
|
|
188
|
+
|
|
170
189
|
/**
|
|
171
190
|
* Executes {@link f} with the provided {@link Context}
|
|
172
191
|
* @param ctx The context to which to set the value
|
|
@@ -205,7 +224,7 @@ export declare function toSignal<T, K extends keyof T>(obj: Accessor<T>, k: Acce
|
|
|
205
224
|
* @param args Arguments for calling {@link f}
|
|
206
225
|
* @returns The same thing {@link f} returned
|
|
207
226
|
*/
|
|
208
|
-
export declare function untrackCall<F extends (...args: any[]) => any>(this: ThisParameterType<F>, f: F, ...args: Parameters<F>):
|
|
227
|
+
export declare function untrackCall<F extends (...args: any[]) => any>(this: ThisParameterType<F>, f: F, ...args: Parameters<F>): ReturnType<F>;
|
|
209
228
|
|
|
210
229
|
/**
|
|
211
230
|
* Calls {@link f} maintaining its reactivity
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { untrack, createMemo, splitProps,
|
|
1
|
+
import { untrack, createMemo, splitProps, createContext, createRoot, getOwner, createEffect, on, createResource, createComponent, useContext, createRenderEffect, onCleanup, Match, mergeProps, For, Show, onMount } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
function untrackCall(f, ...args) {
|
|
4
4
|
return untrack(() => f.apply(this, args));
|
|
5
5
|
}
|
|
6
|
+
function refCall(ref, value) {
|
|
7
|
+
if (!ref)
|
|
8
|
+
return value;
|
|
9
|
+
if (typeof ref !== "function")
|
|
10
|
+
throw new ReferenceError('Il parametro "ref" deve essere stato compilato in una funzione a runtime');
|
|
11
|
+
ref(value);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
6
14
|
function memoProps(obj, keys = Object.keys(obj)) {
|
|
7
15
|
const out = {};
|
|
8
16
|
for (const elm of keys)
|
|
@@ -17,15 +25,6 @@ function splitAndMemoProps(obj, keys) {
|
|
|
17
25
|
out[0] = memoProps(out[0], keys);
|
|
18
26
|
return out;
|
|
19
27
|
}
|
|
20
|
-
function createReactiveResource(f) {
|
|
21
|
-
var refetch;
|
|
22
|
-
const memo = createMemo(f);
|
|
23
|
-
createEffect(on(memo, () => refetch?.()));
|
|
24
|
-
const [get] = [, {
|
|
25
|
-
refetch
|
|
26
|
-
}] = createResource(memo);
|
|
27
|
-
return get;
|
|
28
|
-
}
|
|
29
28
|
function createOption(init, def = init, name) {
|
|
30
29
|
const prop = "read";
|
|
31
30
|
const ctx2 = createContext(() => init, {
|
|
@@ -58,6 +57,15 @@ function runWithContext(ctx2, value, f) {
|
|
|
58
57
|
}
|
|
59
58
|
});
|
|
60
59
|
}
|
|
60
|
+
function createReactiveResource(f) {
|
|
61
|
+
var refetch;
|
|
62
|
+
const memo = createMemo(f);
|
|
63
|
+
createEffect(on(memo, () => refetch?.()));
|
|
64
|
+
const [get] = [, {
|
|
65
|
+
refetch
|
|
66
|
+
}] = createResource(memo);
|
|
67
|
+
return get;
|
|
68
|
+
}
|
|
61
69
|
const IDENTITY = (x) => x;
|
|
62
70
|
function bind([get], [, set], to = IDENTITY) {
|
|
63
71
|
const d = createRoot((d2) => (createRenderEffect(on(get, (x) => set((prev) => to(x, prev)))), d2));
|
|
@@ -180,9 +188,15 @@ function Joint(props) {
|
|
|
180
188
|
});
|
|
181
189
|
}
|
|
182
190
|
const Debug = createOption(false, true, "debug-scope");
|
|
191
|
+
function Doc(props) {
|
|
192
|
+
const node = document.createTextNode("");
|
|
193
|
+
onMount(() => (refCall(props.ref, node.ownerDocument), node.remove()));
|
|
194
|
+
return node;
|
|
195
|
+
}
|
|
183
196
|
export {
|
|
184
197
|
Case,
|
|
185
198
|
Debug,
|
|
199
|
+
Doc,
|
|
186
200
|
When,
|
|
187
201
|
bind,
|
|
188
202
|
bindTwoWay,
|
|
@@ -191,6 +205,7 @@ export {
|
|
|
191
205
|
createOption,
|
|
192
206
|
createReactiveResource,
|
|
193
207
|
memoProps,
|
|
208
|
+
refCall,
|
|
194
209
|
runWithContext,
|
|
195
210
|
splitAndMemoProps,
|
|
196
211
|
toSetter,
|
package/dist/index.umd.js
CHANGED
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
function untrackCall(f, ...args) {
|
|
6
6
|
return solidJs.untrack(() => f.apply(this, args));
|
|
7
7
|
}
|
|
8
|
+
function refCall(ref, value) {
|
|
9
|
+
if (!ref)
|
|
10
|
+
return value;
|
|
11
|
+
if (typeof ref !== "function")
|
|
12
|
+
throw new ReferenceError('Il parametro "ref" deve essere stato compilato in una funzione a runtime');
|
|
13
|
+
ref(value);
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
8
16
|
function memoProps(obj, keys = Object.keys(obj)) {
|
|
9
17
|
const out = {};
|
|
10
18
|
for (const elm of keys)
|
|
@@ -19,15 +27,6 @@
|
|
|
19
27
|
out[0] = memoProps(out[0], keys);
|
|
20
28
|
return out;
|
|
21
29
|
}
|
|
22
|
-
function createReactiveResource(f) {
|
|
23
|
-
var refetch;
|
|
24
|
-
const memo = solidJs.createMemo(f);
|
|
25
|
-
solidJs.createEffect(solidJs.on(memo, () => refetch?.()));
|
|
26
|
-
const [get] = [, {
|
|
27
|
-
refetch
|
|
28
|
-
}] = solidJs.createResource(memo);
|
|
29
|
-
return get;
|
|
30
|
-
}
|
|
31
30
|
function createOption(init, def = init, name) {
|
|
32
31
|
const prop = "read";
|
|
33
32
|
const ctx2 = solidJs.createContext(() => init, {
|
|
@@ -60,6 +59,15 @@
|
|
|
60
59
|
}
|
|
61
60
|
});
|
|
62
61
|
}
|
|
62
|
+
function createReactiveResource(f) {
|
|
63
|
+
var refetch;
|
|
64
|
+
const memo = solidJs.createMemo(f);
|
|
65
|
+
solidJs.createEffect(solidJs.on(memo, () => refetch?.()));
|
|
66
|
+
const [get] = [, {
|
|
67
|
+
refetch
|
|
68
|
+
}] = solidJs.createResource(memo);
|
|
69
|
+
return get;
|
|
70
|
+
}
|
|
63
71
|
const IDENTITY = (x) => x;
|
|
64
72
|
function bind([get], [, set], to = IDENTITY) {
|
|
65
73
|
const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(get, (x) => set((prev) => to(x, prev)))), d2));
|
|
@@ -182,8 +190,14 @@
|
|
|
182
190
|
});
|
|
183
191
|
}
|
|
184
192
|
const Debug = createOption(false, true, "debug-scope");
|
|
193
|
+
function Doc(props) {
|
|
194
|
+
const node = document.createTextNode("");
|
|
195
|
+
solidJs.onMount(() => (refCall(props.ref, node.ownerDocument), node.remove()));
|
|
196
|
+
return node;
|
|
197
|
+
}
|
|
185
198
|
exports2.Case = Case;
|
|
186
199
|
exports2.Debug = Debug;
|
|
200
|
+
exports2.Doc = Doc;
|
|
187
201
|
exports2.When = When;
|
|
188
202
|
exports2.bind = bind;
|
|
189
203
|
exports2.bindTwoWay = bindTwoWay;
|
|
@@ -192,6 +206,7 @@
|
|
|
192
206
|
exports2.createOption = createOption;
|
|
193
207
|
exports2.createReactiveResource = createReactiveResource;
|
|
194
208
|
exports2.memoProps = memoProps;
|
|
209
|
+
exports2.refCall = refCall;
|
|
195
210
|
exports2.runWithContext = runWithContext;
|
|
196
211
|
exports2.splitAndMemoProps = splitAndMemoProps;
|
|
197
212
|
exports2.toSetter = toSetter;
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -47,6 +47,15 @@ return <>
|
|
|
47
47
|
</>
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
### `Doc`
|
|
51
|
+
Gives back the current document
|
|
52
|
+
```tsx
|
|
53
|
+
var doc: Document;
|
|
54
|
+
return <>
|
|
55
|
+
<Doc ref={doc} />
|
|
56
|
+
</>
|
|
57
|
+
```
|
|
58
|
+
|
|
50
59
|
### `createExtractor()`
|
|
51
60
|
Creates a context for components that may need to be out of their parent in certain conditions.
|
|
52
61
|
If you have this component
|
|
@@ -148,17 +157,20 @@ Utility functions needed for the components above
|
|
|
148
157
|
### `untrackCall()`
|
|
149
158
|
Calls a function untracking what happens inside of it but not what gets passed as its argument
|
|
150
159
|
|
|
160
|
+
### `refCall()`
|
|
161
|
+
Executes a `Ref`
|
|
162
|
+
|
|
151
163
|
### `memoProps()`
|
|
152
164
|
Creates a partial version of an object with memoized remaining properties
|
|
153
165
|
|
|
154
166
|
### `splitAndMemoProps()`
|
|
155
167
|
Like `splitProps()` but memoizes the whole local part
|
|
156
168
|
|
|
157
|
-
### `createReactiveResource()`
|
|
158
|
-
Like `createResource()` but the provided function will be reactive
|
|
159
|
-
|
|
160
169
|
### `createOption()`
|
|
161
170
|
Allows you to create simple reactive contexts; For example `Debug` is made with it
|
|
162
171
|
|
|
163
172
|
### `runWithContext()`
|
|
164
|
-
Creates a context scope that persists for the duration of a function
|
|
173
|
+
Creates a context scope that persists for the duration of a function
|
|
174
|
+
|
|
175
|
+
### `createReactiveResource()`
|
|
176
|
+
Like `createResource()` but the provided function will be reactive
|