solid-ctrl-flow 1.0.33 → 1.0.35
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 +10 -18
- package/dist/index.mjs +12 -26
- package/dist/index.umd.js +12 -26
- package/package.json +1 -1
- package/readMe.md +36 -37
package/dist/index.d.ts
CHANGED
|
@@ -7,20 +7,23 @@ import { Resource } from 'solid-js';
|
|
|
7
7
|
import { Setter } from 'solid-js';
|
|
8
8
|
import { Signal } from 'solid-js';
|
|
9
9
|
|
|
10
|
+
/** Type hack for making {@link ReactiveContext} implement {@link Accessor} */
|
|
11
|
+
declare const BASE_CTOR: new <T>() => Accessor<T>;
|
|
12
|
+
|
|
10
13
|
/**
|
|
11
14
|
* Creates a one-way binding between two {@link Signal}s.
|
|
12
15
|
* The function uses {@link createRenderEffect}, which means that:
|
|
13
16
|
* - As soon as the function is done executing the two {@link Signal}s will have the same value
|
|
14
17
|
* - If {@link source} changes, {@link dest} wont be instantly updated
|
|
15
18
|
* - If the current owner gets disposed before {@link dest} is updated, it never will
|
|
16
|
-
* @param source The source of the binding
|
|
17
|
-
* @param dest The destination of the binding
|
|
19
|
+
* @param source The getter of source of the binding
|
|
20
|
+
* @param dest The setter of destination of the binding
|
|
18
21
|
* @param to Conversion function from {@link S} to {@link D}
|
|
19
22
|
* @returns A function that disposes the binding
|
|
20
23
|
*/
|
|
21
|
-
export declare function bind<S>(source:
|
|
24
|
+
export declare function bind<S>(source: Accessor<S>, dest: Setter<S>): () => void;
|
|
22
25
|
|
|
23
|
-
export declare function bind<S, D>(source:
|
|
26
|
+
export declare function bind<S, D>(source: Accessor<S>, dest: Setter<D>, to: Convert<S, D>): () => void;
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* Creates a two-way binding between two {@link Signal}s calling {@link bind} two times
|
|
@@ -126,17 +129,8 @@ export declare function createExtractor(name?: string): {
|
|
|
126
129
|
*/
|
|
127
130
|
export declare function createReactiveResource<R>(f: EffectFunction<R | undefined, R>): Resource<Awaited<R>>;
|
|
128
131
|
|
|
129
|
-
/**
|
|
130
|
-
export declare
|
|
131
|
-
value?: boolean;
|
|
132
|
-
children?: JSX.Element;
|
|
133
|
-
}): JSX.Element;
|
|
134
|
-
|
|
135
|
-
/** Internals of {@link Debug} */
|
|
136
|
-
export declare namespace Debug {
|
|
137
|
-
/** Returns an {@link Accessor} that tells whether the current {@link Owner} is in debug mode */
|
|
138
|
-
const isDebug: Accessor<boolean>;
|
|
139
|
-
}
|
|
132
|
+
/** Built-in {@link ReactiveContext} which allows you to display different things in debug mode */
|
|
133
|
+
export declare const debug: ReactiveContext<boolean>;
|
|
140
134
|
|
|
141
135
|
/** Informations about a {@link Source} component */
|
|
142
136
|
declare type Info = {
|
|
@@ -157,7 +151,7 @@ export declare function memoProps<T, K extends readonly (keyof T)[] = (keyof T)[
|
|
|
157
151
|
* Reactive {@link Context} with some additional built-in functionalities.
|
|
158
152
|
* The call signature returns the value in the current {@link Owner} (It's like calling {@link read})
|
|
159
153
|
*/
|
|
160
|
-
export declare abstract class ReactiveContext<T> extends
|
|
154
|
+
export declare abstract class ReactiveContext<T> extends BASE_CTOR<T> {
|
|
161
155
|
/** The actual {@link Context} that contains the reactive {@link Accessor} to the value */
|
|
162
156
|
abstract ctx: Context<Accessor<T>>;
|
|
163
157
|
/**
|
|
@@ -192,8 +186,6 @@ export declare abstract class ReactiveContext<T> extends ReactiveContext_base<T>
|
|
|
192
186
|
static create<T>(defaultValue: T, name?: string): ReactiveContext<T>;
|
|
193
187
|
}
|
|
194
188
|
|
|
195
|
-
declare const ReactiveContext_base: new <T_1>() => Accessor<T_1>;
|
|
196
|
-
|
|
197
189
|
/**
|
|
198
190
|
* Executes a {@link Ref}.
|
|
199
191
|
* Throws a {@link ReferenceError} if {@link ref} its not a function at runtime (Which should never be the case thanks to the solid compiler)
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useContext, createMemo, createComponent, createContext, Match, mergeProps, onCleanup, For, Show, 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
|
+
class ReactiveContext extends BASE_CTOR {
|
|
4
5
|
/** The actual {@link Context} that contains the reactive {@link Accessor} to the value */
|
|
5
6
|
/**
|
|
6
7
|
* Returns the {@link Accessor} for the value in the current {@link Owner}.
|
|
@@ -53,13 +54,13 @@ class ReactiveContext extends Function {
|
|
|
53
54
|
return out;
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
|
-
const ctx
|
|
57
|
-
const Case = ctx
|
|
57
|
+
const ctx = ReactiveContext.create(void 0, "case-when");
|
|
58
|
+
const Case = ctx.Provider;
|
|
58
59
|
function When(props) {
|
|
59
60
|
const [mine, other] = splitAndMemoProps(props, ["value", "pred"]);
|
|
60
61
|
const {
|
|
61
62
|
read
|
|
62
|
-
} = ctx
|
|
63
|
+
} = ctx;
|
|
63
64
|
const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
|
|
64
65
|
return createComponent(Match, mergeProps({
|
|
65
66
|
get when() {
|
|
@@ -67,22 +68,6 @@ function When(props) {
|
|
|
67
68
|
}
|
|
68
69
|
}, other));
|
|
69
70
|
}
|
|
70
|
-
const ctx = ReactiveContext.create(false, "debug-scope");
|
|
71
|
-
function Debug(props) {
|
|
72
|
-
return createComponent(ctx.Provider, {
|
|
73
|
-
get value() {
|
|
74
|
-
return props.value ?? true;
|
|
75
|
-
},
|
|
76
|
-
get children() {
|
|
77
|
-
return props.children;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
(function(_Debug) {
|
|
82
|
-
Object.defineProperty(Debug, "isDebug", {
|
|
83
|
-
get: () => ctx.read
|
|
84
|
-
});
|
|
85
|
-
})(Debug || (Debug = {}));
|
|
86
71
|
function createExtractor(name = "extractor") {
|
|
87
72
|
const ctx2 = createContext(void 0, {
|
|
88
73
|
name
|
|
@@ -157,13 +142,13 @@ function Joint(props) {
|
|
|
157
142
|
});
|
|
158
143
|
}
|
|
159
144
|
const IDENTITY = (x) => x;
|
|
160
|
-
function bind(
|
|
161
|
-
const d = createRoot((d2) => (createRenderEffect(on(
|
|
145
|
+
function bind(source, dest, to = IDENTITY) {
|
|
146
|
+
const d = createRoot((d2) => (createRenderEffect(on(source, (x) => dest((prev) => to(x, prev)))), d2));
|
|
162
147
|
return onCleanup(d), d;
|
|
163
148
|
}
|
|
164
|
-
function bindTwoWay(source, dest, to
|
|
165
|
-
const a = bind(source, dest, to);
|
|
166
|
-
const b = bind(dest, source, from);
|
|
149
|
+
function bindTwoWay(source, dest, to, from) {
|
|
150
|
+
const a = bind(source[0], dest[1], to);
|
|
151
|
+
const b = bind(dest[0], source[1], from);
|
|
167
152
|
return () => (a(), b());
|
|
168
153
|
}
|
|
169
154
|
function toSetter(get, set) {
|
|
@@ -226,9 +211,9 @@ function createReactiveResource(f) {
|
|
|
226
211
|
}] = createResource(memo);
|
|
227
212
|
return get;
|
|
228
213
|
}
|
|
214
|
+
const debug = ReactiveContext.create(false, "debug-scope");
|
|
229
215
|
export {
|
|
230
216
|
Case,
|
|
231
|
-
Debug,
|
|
232
217
|
ReactiveContext,
|
|
233
218
|
When,
|
|
234
219
|
bind,
|
|
@@ -236,6 +221,7 @@ export {
|
|
|
236
221
|
coalesceSignal,
|
|
237
222
|
createExtractor,
|
|
238
223
|
createReactiveResource,
|
|
224
|
+
debug,
|
|
239
225
|
memoProps,
|
|
240
226
|
refCall,
|
|
241
227
|
runWithContext,
|
package/dist/index.umd.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("solid-js"), require("solid-js/store")) : typeof define === "function" && define.amd ? define(["exports", "solid-js", "solid-js/store"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.solidCtrlFlow = {}, global.solidJs, global.solidJsStore));
|
|
3
3
|
})(this, function(exports2, solidJs, store) {
|
|
4
4
|
"use strict";
|
|
5
|
-
|
|
5
|
+
const BASE_CTOR = Function;
|
|
6
|
+
class ReactiveContext extends BASE_CTOR {
|
|
6
7
|
/** The actual {@link Context} that contains the reactive {@link Accessor} to the value */
|
|
7
8
|
/**
|
|
8
9
|
* Returns the {@link Accessor} for the value in the current {@link Owner}.
|
|
@@ -55,13 +56,13 @@
|
|
|
55
56
|
return out;
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
|
-
const ctx
|
|
59
|
-
const Case = ctx
|
|
59
|
+
const ctx = ReactiveContext.create(void 0, "case-when");
|
|
60
|
+
const Case = ctx.Provider;
|
|
60
61
|
function When(props) {
|
|
61
62
|
const [mine, other] = splitAndMemoProps(props, ["value", "pred"]);
|
|
62
63
|
const {
|
|
63
64
|
read
|
|
64
|
-
} = ctx
|
|
65
|
+
} = ctx;
|
|
65
66
|
const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
|
|
66
67
|
return solidJs.createComponent(solidJs.Match, solidJs.mergeProps({
|
|
67
68
|
get when() {
|
|
@@ -69,22 +70,6 @@
|
|
|
69
70
|
}
|
|
70
71
|
}, other));
|
|
71
72
|
}
|
|
72
|
-
const ctx = ReactiveContext.create(false, "debug-scope");
|
|
73
|
-
function Debug(props) {
|
|
74
|
-
return solidJs.createComponent(ctx.Provider, {
|
|
75
|
-
get value() {
|
|
76
|
-
return props.value ?? true;
|
|
77
|
-
},
|
|
78
|
-
get children() {
|
|
79
|
-
return props.children;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
(function(_Debug) {
|
|
84
|
-
Object.defineProperty(Debug, "isDebug", {
|
|
85
|
-
get: () => ctx.read
|
|
86
|
-
});
|
|
87
|
-
})(Debug || (Debug = {}));
|
|
88
73
|
function createExtractor(name = "extractor") {
|
|
89
74
|
const ctx2 = solidJs.createContext(void 0, {
|
|
90
75
|
name
|
|
@@ -159,13 +144,13 @@
|
|
|
159
144
|
});
|
|
160
145
|
}
|
|
161
146
|
const IDENTITY = (x) => x;
|
|
162
|
-
function bind(
|
|
163
|
-
const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(
|
|
147
|
+
function bind(source, dest, to = IDENTITY) {
|
|
148
|
+
const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(source, (x) => dest((prev) => to(x, prev)))), d2));
|
|
164
149
|
return solidJs.onCleanup(d), d;
|
|
165
150
|
}
|
|
166
|
-
function bindTwoWay(source, dest, to
|
|
167
|
-
const a = bind(source, dest, to);
|
|
168
|
-
const b = bind(dest, source, from);
|
|
151
|
+
function bindTwoWay(source, dest, to, from) {
|
|
152
|
+
const a = bind(source[0], dest[1], to);
|
|
153
|
+
const b = bind(dest[0], source[1], from);
|
|
169
154
|
return () => (a(), b());
|
|
170
155
|
}
|
|
171
156
|
function toSetter(get, set) {
|
|
@@ -228,8 +213,8 @@
|
|
|
228
213
|
}] = solidJs.createResource(memo);
|
|
229
214
|
return get;
|
|
230
215
|
}
|
|
216
|
+
const debug = ReactiveContext.create(false, "debug-scope");
|
|
231
217
|
exports2.Case = Case;
|
|
232
|
-
exports2.Debug = Debug;
|
|
233
218
|
exports2.ReactiveContext = ReactiveContext;
|
|
234
219
|
exports2.When = When;
|
|
235
220
|
exports2.bind = bind;
|
|
@@ -237,6 +222,7 @@
|
|
|
237
222
|
exports2.coalesceSignal = coalesceSignal;
|
|
238
223
|
exports2.createExtractor = createExtractor;
|
|
239
224
|
exports2.createReactiveResource = createReactiveResource;
|
|
225
|
+
exports2.debug = debug;
|
|
240
226
|
exports2.memoProps = memoProps;
|
|
241
227
|
exports2.refCall = refCall;
|
|
242
228
|
exports2.runWithContext = runWithContext;
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -34,20 +34,6 @@ return <>
|
|
|
34
34
|
</>
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
### `Debug`
|
|
38
|
-
Allows you to define ui section that are only visible in debug or NOT in debug
|
|
39
|
-
```tsx
|
|
40
|
-
const value = false;
|
|
41
|
-
return <>
|
|
42
|
-
<Debug value={value}>
|
|
43
|
-
{/* (A LOT OF NESTING...) */}
|
|
44
|
-
<Show when={Debug.isDebug()}>
|
|
45
|
-
THIS WOULD BE VISIBLE IF "value" HAD BEEN {true}
|
|
46
|
-
</Show>
|
|
47
|
-
</Debug>
|
|
48
|
-
</>
|
|
49
|
-
```
|
|
50
|
-
|
|
51
37
|
### `createExtractor()`
|
|
52
38
|
Creates a context for components that may need to be out of their parent in certain conditions.
|
|
53
39
|
If you have this component
|
|
@@ -122,6 +108,29 @@ Notice that you can use a `Source` component without adding it to the DOM:
|
|
|
122
108
|
return <>Something else</>
|
|
123
109
|
```
|
|
124
110
|
|
|
111
|
+
## Utility
|
|
112
|
+
|
|
113
|
+
### Bindings
|
|
114
|
+
Functions that create bindings between `Signal`s
|
|
115
|
+
|
|
116
|
+
> #### `bind()`
|
|
117
|
+
> Creates a one-way binding between two `Signal`s
|
|
118
|
+
>
|
|
119
|
+
> #### `bindTwoWay()`
|
|
120
|
+
> Creates a two-way binding between two `Signal`s
|
|
121
|
+
>
|
|
122
|
+
> #### `toSetter()`
|
|
123
|
+
> Creates a full-fledged solid `Setter` from a normal one
|
|
124
|
+
>
|
|
125
|
+
> #### `toSignal()`
|
|
126
|
+
> Creates a `Signal` from a property of an object
|
|
127
|
+
>
|
|
128
|
+
> #### `coalesceSignal()`
|
|
129
|
+
> Creates a non nullable `Signal` from a nullable one
|
|
130
|
+
>
|
|
131
|
+
> #### `unwrapSignal()`
|
|
132
|
+
> Calls an `Accessor` to a `Signal` maintaining its reactivity
|
|
133
|
+
|
|
125
134
|
### `ReactiveContext.create()`
|
|
126
135
|
Method that creates a reactive version of a solid `Context` with some additional built-in functionalities
|
|
127
136
|
```ts
|
|
@@ -131,29 +140,19 @@ const valueAccessorForTheCurrentOwner = ctx.read;
|
|
|
131
140
|
const value = ctx();
|
|
132
141
|
```
|
|
133
142
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
Creates a `Signal` from a property of an object
|
|
148
|
-
|
|
149
|
-
### `coalesceSignal()`
|
|
150
|
-
Creates a non nullable `Signal` from a nullable one
|
|
151
|
-
|
|
152
|
-
### `unwrapSignal()`
|
|
153
|
-
Calls an `Accessor` to a `Signal` maintaining its reactivity
|
|
154
|
-
|
|
155
|
-
## Utility functions
|
|
156
|
-
Utility functions needed for the components above
|
|
143
|
+
### `debug()`
|
|
144
|
+
Allows you to define ui section that are only visible in debug or NOT in debug
|
|
145
|
+
```tsx
|
|
146
|
+
const value = false;
|
|
147
|
+
return <>
|
|
148
|
+
<debug.Provider value={value}>
|
|
149
|
+
{/* (A LOT OF NESTING...) */}
|
|
150
|
+
<Show when={debug()}>
|
|
151
|
+
THIS WOULD BE VISIBLE IF "value" HAD BEEN {true}
|
|
152
|
+
</Show>
|
|
153
|
+
</debug.Provider>
|
|
154
|
+
</>
|
|
155
|
+
```
|
|
157
156
|
|
|
158
157
|
### `untrackCall()`
|
|
159
158
|
Calls a function untracking what happens inside of it but not what gets passed as its argument
|