solid-ctrl-flow 1.0.29 → 1.0.31

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
@@ -157,11 +157,6 @@ export declare const Debug: {
157
157
  read: Accessor<boolean>;
158
158
  };
159
159
 
160
- /** Component that gives you the owner {@link Document} */
161
- export declare function Doc(props: {
162
- ref: Ref<Document>;
163
- }): Text;
164
-
165
160
  /** Informations about a {@link Source} component */
166
161
  declare type Info = {
167
162
  /** Order of the current source if there are many */
@@ -186,9 +181,17 @@ export declare function memoProps<T, K extends readonly (keyof T)[] = (keyof T)[
186
181
  */
187
182
  export declare function refCall<T, U extends T = T>(ref: Ref<T> | undefined, value: U): U;
188
183
 
184
+ /**
185
+ * Executes {@link f} and then calls {@link d} regardless of errors.
186
+ * If {@link f} returns a {@link Promise}, {@link d} will be called asynchronously
187
+ * @returns The same thing {@link f} returned
188
+ */
189
+ export declare function runAndDispose<R>(d: () => void, f: () => R): R;
190
+
189
191
  /**
190
192
  * Executes {@link f} with the provided value for the specified {@link Context}.
191
- * You can pass `undefined` to {@link value} in order to get back the default value for {@link ctx}
193
+ * You can pass `undefined` to {@link value} in order to get back the default value for {@link ctx}.
194
+ * Everything that happens {@link f} will be disposed as soon as the execution ends
192
195
  * @param ctx The context to which to set the value
193
196
  * @param value The value for the context
194
197
  * @param f The function to run
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { untrack, createMemo, splitProps, createContext, getOwner, runWithOwner, createEffect, on, createResource, createComponent, useContext, createRoot, createRenderEffect, onCleanup, Match, mergeProps, For, Show, onMount } from "solid-js";
1
+ import { untrack, createMemo, splitProps, createContext, createRoot, createEffect, on, createResource, createComponent, useContext, getOwner, createRenderEffect, 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));
@@ -43,18 +43,12 @@ function createOption(init, def = init, name) {
43
43
  return provider;
44
44
  }
45
45
  function runWithContext(ctx2, value, f) {
46
- const owner = getOwner();
47
- const context = {
48
- ...owner?.context,
49
- [ctx2.id]: value
50
- };
51
- const temp = {
52
- context,
53
- owner,
54
- owned: null,
55
- cleanups: null
56
- };
57
- return runWithOwner(temp, () => f(value));
46
+ return createRoot((d) => {
47
+ return runAndDispose(d, () => {
48
+ (getOwner().context ??= {})[ctx2.id] = value;
49
+ return f(value);
50
+ });
51
+ });
58
52
  }
59
53
  function createReactiveResource(f) {
60
54
  var refetch;
@@ -65,6 +59,14 @@ function createReactiveResource(f) {
65
59
  }] = createResource(memo);
66
60
  return get;
67
61
  }
62
+ function runAndDispose(d, f) {
63
+ try {
64
+ const out = f();
65
+ return out instanceof Promise ? out.finally(d) : (d(), out);
66
+ } catch (ex) {
67
+ throw d(), ex;
68
+ }
69
+ }
68
70
  const IDENTITY = (x) => x;
69
71
  function bind([get], [, set], to = IDENTITY) {
70
72
  const d = createRoot((d2) => (createRenderEffect(on(get, (x) => set((prev) => to(x, prev)))), d2));
@@ -187,15 +189,9 @@ function Joint(props) {
187
189
  });
188
190
  }
189
191
  const Debug = createOption(false, true, "debug-scope");
190
- function Doc(props) {
191
- const node = document.createTextNode("");
192
- onMount(() => (refCall(props.ref, node.ownerDocument), node.remove()));
193
- return node;
194
- }
195
192
  export {
196
193
  Case,
197
194
  Debug,
198
- Doc,
199
195
  When,
200
196
  bind,
201
197
  bindTwoWay,
@@ -205,6 +201,7 @@ export {
205
201
  createReactiveResource,
206
202
  memoProps,
207
203
  refCall,
204
+ runAndDispose,
208
205
  runWithContext,
209
206
  splitAndMemoProps,
210
207
  toSetter,
package/dist/index.umd.js CHANGED
@@ -45,18 +45,12 @@
45
45
  return provider;
46
46
  }
47
47
  function runWithContext(ctx2, value, f) {
48
- const owner = solidJs.getOwner();
49
- const context = {
50
- ...owner?.context,
51
- [ctx2.id]: value
52
- };
53
- const temp = {
54
- context,
55
- owner,
56
- owned: null,
57
- cleanups: null
58
- };
59
- return solidJs.runWithOwner(temp, () => f(value));
48
+ return solidJs.createRoot((d) => {
49
+ return runAndDispose(d, () => {
50
+ (solidJs.getOwner().context ??= {})[ctx2.id] = value;
51
+ return f(value);
52
+ });
53
+ });
60
54
  }
61
55
  function createReactiveResource(f) {
62
56
  var refetch;
@@ -67,6 +61,14 @@
67
61
  }] = solidJs.createResource(memo);
68
62
  return get;
69
63
  }
64
+ function runAndDispose(d, f) {
65
+ try {
66
+ const out = f();
67
+ return out instanceof Promise ? out.finally(d) : (d(), out);
68
+ } catch (ex) {
69
+ throw d(), ex;
70
+ }
71
+ }
70
72
  const IDENTITY = (x) => x;
71
73
  function bind([get], [, set], to = IDENTITY) {
72
74
  const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(get, (x) => set((prev) => to(x, prev)))), d2));
@@ -189,14 +191,8 @@
189
191
  });
190
192
  }
191
193
  const Debug = createOption(false, true, "debug-scope");
192
- function Doc(props) {
193
- const node = document.createTextNode("");
194
- solidJs.onMount(() => (refCall(props.ref, node.ownerDocument), node.remove()));
195
- return node;
196
- }
197
194
  exports2.Case = Case;
198
195
  exports2.Debug = Debug;
199
- exports2.Doc = Doc;
200
196
  exports2.When = When;
201
197
  exports2.bind = bind;
202
198
  exports2.bindTwoWay = bindTwoWay;
@@ -206,6 +202,7 @@
206
202
  exports2.createReactiveResource = createReactiveResource;
207
203
  exports2.memoProps = memoProps;
208
204
  exports2.refCall = refCall;
205
+ exports2.runAndDispose = runAndDispose;
209
206
  exports2.runWithContext = runWithContext;
210
207
  exports2.splitAndMemoProps = splitAndMemoProps;
211
208
  exports2.toSetter = toSetter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
package/readMe.md CHANGED
@@ -47,15 +47,6 @@ 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
-
59
50
  ### `createExtractor()`
60
51
  Creates a context for components that may need to be out of their parent in certain conditions.
61
52
  If you have this component
@@ -173,4 +164,7 @@ Allows you to create simple reactive contexts; For example `Debug` is made with
173
164
  Creates a context scope that persists for the duration of a function
174
165
 
175
166
  ### `createReactiveResource()`
176
- Like `createResource()` but the provided function will be reactive
167
+ Like `createResource()` but the provided function will be reactive
168
+
169
+ ### `runAndDispose()`
170
+ Executes a function THEN calls a dispose callback; It works with async functions too