solid-ctrl-flow 1.0.24 → 1.0.25

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
@@ -64,6 +64,14 @@ export declare function Case(props: {
64
64
  children: JSX.Element;
65
65
  }): JSX.Element;
66
66
 
67
+ /**
68
+ * Returns a {@link Signal} that applies the `??=` operator to the input one.
69
+ * If the getter of {@link param0} is like "x", then the result one is like "(x ??= {@link f}())"
70
+ * @param param0 The {@link Signal} to which to coalesce the getter
71
+ * @param f A function that creates a new {@link T}
72
+ */
73
+ export declare function coalesceSignal<T>([get, set]: Signal<T | undefined>, f: Accessor<T>): Signal<T>;
74
+
67
75
  /** Conversion function for bindings */
68
76
  export declare type Convert<S, D> = (x: S, prev: D) => D;
69
77
 
package/dist/index.mjs CHANGED
@@ -78,6 +78,9 @@ function toSignal(obj, k) {
78
78
  const get = () => obj()[k()];
79
79
  return [get, toSetter(get, (v) => obj()[k()] = v)];
80
80
  }
81
+ function coalesceSignal([get, set], f) {
82
+ return [() => get() ?? set(f), set];
83
+ }
81
84
  function unwrapSignal(f) {
82
85
  return [() => f()[0](), (x) => f()[1](x)];
83
86
  }
@@ -183,6 +186,7 @@ export {
183
186
  When,
184
187
  bind,
185
188
  bindTwoWay,
189
+ coalesceSignal,
186
190
  createExtractor,
187
191
  createOption,
188
192
  createReactiveResource,
package/dist/index.umd.js CHANGED
@@ -80,6 +80,9 @@
80
80
  const get = () => obj()[k()];
81
81
  return [get, toSetter(get, (v) => obj()[k()] = v)];
82
82
  }
83
+ function coalesceSignal([get, set], f) {
84
+ return [() => get() ?? set(f), set];
85
+ }
83
86
  function unwrapSignal(f) {
84
87
  return [() => f()[0](), (x) => f()[1](x)];
85
88
  }
@@ -184,6 +187,7 @@
184
187
  exports2.When = When;
185
188
  exports2.bind = bind;
186
189
  exports2.bindTwoWay = bindTwoWay;
190
+ exports2.coalesceSignal = coalesceSignal;
187
191
  exports2.createExtractor = createExtractor;
188
192
  exports2.createOption = createOption;
189
193
  exports2.createReactiveResource = createReactiveResource;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
package/readMe.md CHANGED
@@ -136,6 +136,9 @@ Creates a full-fledged solid `Setter` from a normal one
136
136
  ### `toSignal()`
137
137
  Creates a `Signal` from a property of an object
138
138
 
139
+ ### `coalesceSignal()`
140
+ Creates a non nullable `Signal` from a nullable one
141
+
139
142
  ### `unwrapSignal()`
140
143
  Calls an `Accessor` to a `Signal` maintaining its reactivity
141
144