solid-ctrl-flow 1.0.20 → 1.0.22

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
@@ -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
- * Esecutes {@link splitProps} and memoizes the first of the two returned objects
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, createEffect, on, onCleanup, Match, mergeProps, For, Show } from "solid-js";
1
+ import { untrack, createMemo, splitProps, createEffect, on, createResource, 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,15 @@ function splitAndMemoProps(obj, keys) {
17
17
  out[0] = memoProps(out[0], keys);
18
18
  return out;
19
19
  }
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
+ }
20
29
  function createOption(init, def = init, name) {
21
30
  const prop = "read";
22
31
  const ctx2 = createContext(() => init, {
@@ -173,6 +182,7 @@ export {
173
182
  bindTwoWay,
174
183
  createExtractor,
175
184
  createOption,
185
+ createReactiveResource,
176
186
  memoProps,
177
187
  runWithContext,
178
188
  splitAndMemoProps,
package/dist/index.umd.js CHANGED
@@ -19,6 +19,15 @@
19
19
  out[0] = memoProps(out[0], keys);
20
20
  return out;
21
21
  }
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
+ }
22
31
  function createOption(init, def = init, name) {
23
32
  const prop = "read";
24
33
  const ctx2 = solidJs.createContext(() => init, {
@@ -174,6 +183,7 @@
174
183
  exports2.bindTwoWay = bindTwoWay;
175
184
  exports2.createExtractor = createExtractor;
176
185
  exports2.createOption = createOption;
186
+ exports2.createReactiveResource = createReactiveResource;
177
187
  exports2.memoProps = memoProps;
178
188
  exports2.runWithContext = runWithContext;
179
189
  exports2.splitAndMemoProps = splitAndMemoProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
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