solid-ctrl-flow 6.1.0 → 6.1.1

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
@@ -11,6 +11,14 @@ export declare function Case(props: ParentProps<{
11
11
  value: unknown;
12
12
  }>): JSX;
13
13
 
14
+ /**
15
+ * Runs {@link f} and ensures that its reactive resources are cleaned up not only when the current {@link Owner} is disposed, but also when the provided one is
16
+ * @param outer The {@link Owner} for which to listen for its disposal
17
+ * @param f The function to run
18
+ * @return The same thing {@link f} returned
19
+ */
20
+ export declare function disposeWithOwner<T>(outer: Owner, f: Accessor<T>): T;
21
+
14
22
  /**
15
23
  * Eventually wraps its content into a template if a certain condition is met.
16
24
  * If you set {@link Standard.recycled} to `true`, the content will be memoized in the beginning and will be recycled even if the wrapper changes.
package/dist/index.mjs CHANGED
@@ -1,8 +1,16 @@
1
- import { untrack, createRoot, getOwner, createMemo, Show, createContext, useContext, onCleanup, For, createRenderEffect, on, splitProps, createSignal, batch, createSelector, equalFn, Match, runWithOwner } from "solid-js";
1
+ import { untrack, getOwner, createRoot, runWithOwner, onCleanup, createMemo, Show, createContext, useContext, For, createRenderEffect, on, splitProps, createSignal, batch, createSelector, equalFn, Match } from "solid-js";
2
2
  import { createComponent, memo, mergeProps, spread } from "solid-js/web";
3
3
  function untrackCall(f, ...args) {
4
4
  return untrack(() => f.apply(this, args));
5
5
  }
6
+ function disposeWithOwner(outer, f) {
7
+ const inner = getOwner();
8
+ return createRoot((d) => {
9
+ runWithOwner(outer, () => onCleanup(d));
10
+ runWithOwner(inner, () => onCleanup(d));
11
+ return f();
12
+ });
13
+ }
6
14
  function runWithContext(ctx2, value, f) {
7
15
  return createRoot((d) => {
8
16
  try {
@@ -180,12 +188,13 @@ function Source(props) {
180
188
  sources
181
189
  } = state;
182
190
  const order = createMemo(() => props.order);
191
+ const owner = getOwner();
183
192
  const info = {
184
193
  get order() {
185
194
  return order();
186
195
  },
187
196
  get children() {
188
- return props.children;
197
+ return disposeWithOwner(owner, () => props.children);
189
198
  }
190
199
  };
191
200
  const node = new OrderedLinkedListNode(info);
@@ -291,6 +300,7 @@ export {
291
300
  OrderedLinkedListNode,
292
301
  SameContext,
293
302
  Spread,
303
+ disposeWithOwner,
294
304
  memoProps,
295
305
  runWithContext,
296
306
  splitAndMemoProps,
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 disposeWithOwner(outer, f) {
9
+ const inner = solidJs.getOwner();
10
+ return solidJs.createRoot((d) => {
11
+ solidJs.runWithOwner(outer, () => solidJs.onCleanup(d));
12
+ solidJs.runWithOwner(inner, () => solidJs.onCleanup(d));
13
+ return f();
14
+ });
15
+ }
8
16
  function runWithContext(ctx2, value, f) {
9
17
  return solidJs.createRoot((d) => {
10
18
  try {
@@ -182,12 +190,13 @@
182
190
  sources
183
191
  } = state;
184
192
  const order = solidJs.createMemo(() => props.order);
193
+ const owner = solidJs.getOwner();
185
194
  const info = {
186
195
  get order() {
187
196
  return order();
188
197
  },
189
198
  get children() {
190
- return props.children;
199
+ return disposeWithOwner(owner, () => props.children);
191
200
  }
192
201
  };
193
202
  const node = new OrderedLinkedListNode(info);
@@ -292,6 +301,7 @@
292
301
  exports2.OrderedLinkedListNode = OrderedLinkedListNode;
293
302
  exports2.SameContext = SameContext;
294
303
  exports2.Spread = Spread;
304
+ exports2.disposeWithOwner = disposeWithOwner;
295
305
  exports2.memoProps = memoProps;
296
306
  exports2.runWithContext = runWithContext;
297
307
  exports2.splitAndMemoProps = splitAndMemoProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "6.1.0",
3
+ "version": "6.1.1",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
package/readMe.md CHANGED
@@ -235,5 +235,8 @@ Like `splitProps()` but passes the every part except the last one to [`memoProps
235
235
  ### `untrackCall()`
236
236
  Calls a function untracking what happens inside of it but not what gets passed as its argument
237
237
 
238
+ ### `disposeWithOwner()`
239
+ Calls a function in a way that makes it so that the reactive resources it creates are managed by 2 `Owner`s
240
+
238
241
  ### `runWithContext()`
239
242
  Creates a context scope that persists for the duration of a function