solid-ctrl-flow 1.0.20 → 1.0.21
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 -1
- package/dist/index.mjs +10 -1
- package/dist/index.umd.js +9 -0
- package/package.json +1 -1
- package/readMe.md +3 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Accessor } from 'solid-js';
|
|
2
2
|
import { Context } from 'solid-js';
|
|
3
|
+
import { EffectFunction } from 'solid-js';
|
|
3
4
|
import { JSX } from 'solid-js';
|
|
5
|
+
import { Resource } from 'solid-js';
|
|
4
6
|
import { Setter } from 'solid-js';
|
|
5
7
|
import { Signal } from 'solid-js';
|
|
6
8
|
|
|
@@ -124,6 +126,13 @@ export declare function createOption<T>(init: T, def?: T, name?: string): {
|
|
|
124
126
|
read: Accessor<T>;
|
|
125
127
|
};
|
|
126
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Creates a {@link Resource} from the function {@link f}.
|
|
131
|
+
* The resource will be refetched each time one of the dependencies of {@link f} changes
|
|
132
|
+
* @param f A reactive resource fetcher
|
|
133
|
+
*/
|
|
134
|
+
export declare function createReactiveResource<R>(f: EffectFunction<R | undefined, R>): Resource<Awaited<R>>;
|
|
135
|
+
|
|
127
136
|
/** Creates a scope for the value of {@link Debug.read}, which allows you to display different things in debug mode */
|
|
128
137
|
export declare const Debug: {
|
|
129
138
|
(props: {
|
|
@@ -160,7 +169,7 @@ export declare function memoProps<T, K extends readonly (keyof T)[] = (keyof T)[
|
|
|
160
169
|
export declare function runWithContext<T, R>(ctx: Context<T>, value: T, f: (x: T) => R): R;
|
|
161
170
|
|
|
162
171
|
/**
|
|
163
|
-
*
|
|
172
|
+
* Executes {@link splitProps} and memoizes the first of the two returned objects
|
|
164
173
|
* @param obj Object to split and partially memoize
|
|
165
174
|
* @param keys The keys of the properties to memoize and to include in the first of the two objects
|
|
166
175
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { untrack, createMemo, splitProps, createContext, createRoot, getOwner, createComponent, useContext,
|
|
1
|
+
import { untrack, createMemo, splitProps, createResource, createEffect, on, createContext, createRoot, getOwner, createComponent, useContext, onCleanup, Match, mergeProps, For, Show } 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));
|
|
@@ -17,6 +17,14 @@ function splitAndMemoProps(obj, keys) {
|
|
|
17
17
|
out[0] = memoProps(out[0], keys);
|
|
18
18
|
return out;
|
|
19
19
|
}
|
|
20
|
+
function createReactiveResource(f) {
|
|
21
|
+
const memo = createMemo(f);
|
|
22
|
+
const [get, {
|
|
23
|
+
refetch
|
|
24
|
+
}] = createResource(memo);
|
|
25
|
+
createEffect(on(memo, (_x, _prev, ok) => (ok && refetch(), true)));
|
|
26
|
+
return get;
|
|
27
|
+
}
|
|
20
28
|
function createOption(init, def = init, name) {
|
|
21
29
|
const prop = "read";
|
|
22
30
|
const ctx2 = createContext(() => init, {
|
|
@@ -173,6 +181,7 @@ export {
|
|
|
173
181
|
bindTwoWay,
|
|
174
182
|
createExtractor,
|
|
175
183
|
createOption,
|
|
184
|
+
createReactiveResource,
|
|
176
185
|
memoProps,
|
|
177
186
|
runWithContext,
|
|
178
187
|
splitAndMemoProps,
|
package/dist/index.umd.js
CHANGED
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
out[0] = memoProps(out[0], keys);
|
|
20
20
|
return out;
|
|
21
21
|
}
|
|
22
|
+
function createReactiveResource(f) {
|
|
23
|
+
const memo = solidJs.createMemo(f);
|
|
24
|
+
const [get, {
|
|
25
|
+
refetch
|
|
26
|
+
}] = solidJs.createResource(memo);
|
|
27
|
+
solidJs.createEffect(solidJs.on(memo, (_x, _prev, ok) => (ok && refetch(), true)));
|
|
28
|
+
return get;
|
|
29
|
+
}
|
|
22
30
|
function createOption(init, def = init, name) {
|
|
23
31
|
const prop = "read";
|
|
24
32
|
const ctx2 = solidJs.createContext(() => init, {
|
|
@@ -174,6 +182,7 @@
|
|
|
174
182
|
exports2.bindTwoWay = bindTwoWay;
|
|
175
183
|
exports2.createExtractor = createExtractor;
|
|
176
184
|
exports2.createOption = createOption;
|
|
185
|
+
exports2.createReactiveResource = createReactiveResource;
|
|
177
186
|
exports2.memoProps = memoProps;
|
|
178
187
|
exports2.runWithContext = runWithContext;
|
|
179
188
|
exports2.splitAndMemoProps = splitAndMemoProps;
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -149,6 +149,9 @@ Creates a partial version of an object with memoized remaining properties
|
|
|
149
149
|
### `splitAndMemoProps()`
|
|
150
150
|
Like `splitProps()` but memoizes the whole local part
|
|
151
151
|
|
|
152
|
+
### `createReactiveResource()`
|
|
153
|
+
Like `createResource()` but the provided function will be reactive
|
|
154
|
+
|
|
152
155
|
### `createOption()`
|
|
153
156
|
Allows you to create simple reactive contexts; For example `Debug` is made with it
|
|
154
157
|
|