solid-ctrl-flow 1.0.23 → 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
 
@@ -184,10 +192,10 @@ export declare function toSetter<T>(get: Accessor<T>, set: (x: T) => void): Sett
184
192
 
185
193
  /**
186
194
  * Creates a {@link Signal} from a property access
187
- * @param obj The object from which to get the property
188
- * @param k The key of the property
195
+ * @param obj The {@link Accessor} to the object from which to get the property
196
+ * @param k The {@link Accessor} to the key of the property
189
197
  */
190
- export declare function toSignal<T, K extends keyof T>(obj: T, k: K): Signal<T[K]>;
198
+ export declare function toSignal<T, K extends keyof T>(obj: Accessor<T>, k: Accessor<K>): Signal<T[K]>;
191
199
 
192
200
  /**
193
201
  * Executes {@link f} untracking it.
package/dist/index.mjs CHANGED
@@ -75,8 +75,11 @@ function toSetter(get, set) {
75
75
  };
76
76
  }
77
77
  function toSignal(obj, k) {
78
- const get = () => obj[k];
79
- return [get, toSetter(get, (v) => obj[k] = v)];
78
+ const get = () => obj()[k()];
79
+ return [get, toSetter(get, (v) => obj()[k()] = v)];
80
+ }
81
+ function coalesceSignal([get, set], f) {
82
+ return [() => get() ?? set(f), set];
80
83
  }
81
84
  function unwrapSignal(f) {
82
85
  return [() => f()[0](), (x) => f()[1](x)];
@@ -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
@@ -77,8 +77,11 @@
77
77
  };
78
78
  }
79
79
  function toSignal(obj, k) {
80
- const get = () => obj[k];
81
- return [get, toSetter(get, (v) => obj[k] = v)];
80
+ const get = () => obj()[k()];
81
+ return [get, toSetter(get, (v) => obj()[k()] = v)];
82
+ }
83
+ function coalesceSignal([get, set], f) {
84
+ return [() => get() ?? set(f), set];
82
85
  }
83
86
  function unwrapSignal(f) {
84
87
  return [() => f()[0](), (x) => f()[1](x)];
@@ -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.23",
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