solid-ctrl-flow 1.0.22 → 1.0.23

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
@@ -199,6 +199,12 @@ export declare function toSignal<T, K extends keyof T>(obj: T, k: K): Signal<T[K
199
199
  */
200
200
  export declare function untrackCall<F extends (...args: any[]) => any>(this: ThisParameterType<F>, f: F, ...args: Parameters<F>): any;
201
201
 
202
+ /**
203
+ * Calls {@link f} maintaining its reactivity
204
+ * @param f An {@link Accessor} to a {@link Signal}
205
+ */
206
+ export declare function unwrapSignal<T>(f: Accessor<Signal<T>>): Signal<T>;
207
+
202
208
  /** Like a {@link Match} but gets the value from the closest {@link Case} ancestor */
203
209
  export declare function When(props: {
204
210
  value: unknown;
package/dist/index.mjs CHANGED
@@ -59,6 +59,15 @@ function runWithContext(ctx2, value, f) {
59
59
  });
60
60
  }
61
61
  const IDENTITY = (x) => x;
62
+ function bind(source, dest, to = IDENTITY) {
63
+ const d = createRoot((d2) => (createEffect(on(source[0], (x) => dest[1]((prev) => to(x, prev)))), d2));
64
+ return onCleanup(d), d;
65
+ }
66
+ function bindTwoWay(source, dest, to = IDENTITY, from = IDENTITY) {
67
+ const a = bind(source, dest, to);
68
+ const b = bind(dest, source, from);
69
+ return () => (a(), b());
70
+ }
62
71
  function toSetter(get, set) {
63
72
  return (x) => {
64
73
  const out = typeof x === "function" ? x(untrack(get)) : x;
@@ -69,14 +78,8 @@ function toSignal(obj, k) {
69
78
  const get = () => obj[k];
70
79
  return [get, toSetter(get, (v) => obj[k] = v)];
71
80
  }
72
- function bind(source, dest, to = IDENTITY) {
73
- const d = createRoot((d2) => (createEffect(on(source[0], (x) => dest[1]((prev) => to(x, prev)))), d2));
74
- return onCleanup(d), d;
75
- }
76
- function bindTwoWay(source, dest, to = IDENTITY, from = IDENTITY) {
77
- const a = bind(source, dest, to);
78
- const b = bind(dest, source, from);
79
- return () => (a(), b());
81
+ function unwrapSignal(f) {
82
+ return [() => f()[0](), (x) => f()[1](x)];
80
83
  }
81
84
  const ctx = createContext(() => void 0, {
82
85
  name: "case-when"
@@ -188,5 +191,6 @@ export {
188
191
  splitAndMemoProps,
189
192
  toSetter,
190
193
  toSignal,
191
- untrackCall
194
+ untrackCall,
195
+ unwrapSignal
192
196
  };
package/dist/index.umd.js CHANGED
@@ -61,6 +61,15 @@
61
61
  });
62
62
  }
63
63
  const IDENTITY = (x) => x;
64
+ function bind(source, dest, to = IDENTITY) {
65
+ const d = solidJs.createRoot((d2) => (solidJs.createEffect(solidJs.on(source[0], (x) => dest[1]((prev) => to(x, prev)))), d2));
66
+ return solidJs.onCleanup(d), d;
67
+ }
68
+ function bindTwoWay(source, dest, to = IDENTITY, from = IDENTITY) {
69
+ const a = bind(source, dest, to);
70
+ const b = bind(dest, source, from);
71
+ return () => (a(), b());
72
+ }
64
73
  function toSetter(get, set) {
65
74
  return (x) => {
66
75
  const out = typeof x === "function" ? x(solidJs.untrack(get)) : x;
@@ -71,14 +80,8 @@
71
80
  const get = () => obj[k];
72
81
  return [get, toSetter(get, (v) => obj[k] = v)];
73
82
  }
74
- function bind(source, dest, to = IDENTITY) {
75
- const d = solidJs.createRoot((d2) => (solidJs.createEffect(solidJs.on(source[0], (x) => dest[1]((prev) => to(x, prev)))), d2));
76
- return solidJs.onCleanup(d), d;
77
- }
78
- function bindTwoWay(source, dest, to = IDENTITY, from = IDENTITY) {
79
- const a = bind(source, dest, to);
80
- const b = bind(dest, source, from);
81
- return () => (a(), b());
83
+ function unwrapSignal(f) {
84
+ return [() => f()[0](), (x) => f()[1](x)];
82
85
  }
83
86
  const ctx = solidJs.createContext(() => void 0, {
84
87
  name: "case-when"
@@ -190,5 +193,6 @@
190
193
  exports2.toSetter = toSetter;
191
194
  exports2.toSignal = toSignal;
192
195
  exports2.untrackCall = untrackCall;
196
+ exports2.unwrapSignal = unwrapSignal;
193
197
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
194
198
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
package/readMe.md CHANGED
@@ -124,18 +124,20 @@ return <>Something else</>
124
124
  ## Bindings
125
125
  Functions that create bindings between `Signal`s
126
126
 
127
- ### `toSetter()`
128
- Creates a full-fledged solid `Setter` from a normal one
129
-
130
- ### `toSignal()`
131
- Creates a `Signal` from a property of an object
132
-
133
127
  ### `bind()`
134
128
  Creates a one-way binding between two `Signal`s
135
129
 
136
130
  ### `bindTwoWay()`
137
131
  Creates a two-way binding between two `Signal`s
138
132
 
133
+ ### `toSetter()`
134
+ Creates a full-fledged solid `Setter` from a normal one
135
+
136
+ ### `toSignal()`
137
+ Creates a `Signal` from a property of an object
138
+
139
+ ### `unwrapSignal()`
140
+ Calls an `Accessor` to a `Signal` maintaining its reactivity
139
141
 
140
142
  ## Utility functions
141
143
  Utility functions needed for the components above