solid-ctrl-flow 1.0.38 → 1.0.39
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 +4 -3
- package/dist/index.mjs +56 -51
- package/dist/index.umd.js +55 -50
- package/package.json +1 -1
- package/readMe.md +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -269,10 +269,11 @@ export declare function toSignal<T, K extends keyof T>(obj: Accessor<T>, k: Acce
|
|
|
269
269
|
export declare function untrackCall<F extends (...args: any[]) => unknown>(this: ThisParameterType<F>, f: F, ...args: Parameters<F>): ReturnType<F>;
|
|
270
270
|
|
|
271
271
|
/**
|
|
272
|
-
* Calls {@link
|
|
273
|
-
* @param f
|
|
272
|
+
* Calls an {@link Accessor} maintaining its reactivity
|
|
273
|
+
* @param f The {@link Accessor} to the value to emulate
|
|
274
|
+
* @returns A {@link Proxy} that copies the functionalities of the result of {@link f} calling it for each interaction, thus maintaining reactivity
|
|
274
275
|
*/
|
|
275
|
-
export declare
|
|
276
|
+
export declare const unwrap: <T>(f: Accessor<T>) => T;
|
|
276
277
|
|
|
277
278
|
/** Like a {@link Match} but gets the value from the closest {@link Case} ancestor */
|
|
278
279
|
export declare function When(props: {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useContext, createMemo, createComponent, createContext, Match, mergeProps, onCleanup, For, Show,
|
|
1
|
+
import { useContext, createMemo, createComponent, createContext, createRoot, getOwner, Match, mergeProps, onCleanup, For, Show, untrack, splitProps, createEffect, on, createResource, mapArray, createSignal, onMount, createRenderEffect } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
const BASE_CTOR = Function;
|
|
4
4
|
class ReactiveContext extends BASE_CTOR {
|
|
@@ -54,6 +54,16 @@ class ReactiveContext extends BASE_CTOR {
|
|
|
54
54
|
return out;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
+
function runWithContext(ctx2, value, f) {
|
|
58
|
+
return createRoot((d) => {
|
|
59
|
+
try {
|
|
60
|
+
(getOwner().context ??= {})[ctx2.id] = value;
|
|
61
|
+
return f(value === void 0 ? ctx2.defaultValue : value);
|
|
62
|
+
} finally {
|
|
63
|
+
d();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
57
67
|
const ctx = ReactiveContext.create(void 0, "case-when");
|
|
58
68
|
const Case = ctx.Provider;
|
|
59
69
|
function When(props) {
|
|
@@ -141,45 +151,6 @@ function Joint(props) {
|
|
|
141
151
|
}
|
|
142
152
|
});
|
|
143
153
|
}
|
|
144
|
-
function Nest(props) {
|
|
145
|
-
const memo = memoProps(props, ["template", "children"]);
|
|
146
|
-
const content = mapArray(() => props.each, (x, i) => {
|
|
147
|
-
const [get, set] = createSignal();
|
|
148
|
-
const out = memo.template(x, get, i);
|
|
149
|
-
return (x2) => {
|
|
150
|
-
onMount(() => set(() => x2));
|
|
151
|
-
onCleanup(() => set(void 0));
|
|
152
|
-
return out;
|
|
153
|
-
};
|
|
154
|
-
});
|
|
155
|
-
return createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
|
|
156
|
-
}
|
|
157
|
-
const IDENTITY = (x) => x;
|
|
158
|
-
function bind(source, dest, to = IDENTITY) {
|
|
159
|
-
const d = createRoot((d2) => (createRenderEffect(on(source, (x) => dest((prev) => to(x, prev)))), d2));
|
|
160
|
-
return onCleanup(d), d;
|
|
161
|
-
}
|
|
162
|
-
function bindTwoWay(source, dest, to, from) {
|
|
163
|
-
const a = bind(source[0], dest[1], to);
|
|
164
|
-
const b = bind(dest[0], source[1], from);
|
|
165
|
-
return () => (a(), b());
|
|
166
|
-
}
|
|
167
|
-
function toSetter(get, set) {
|
|
168
|
-
return (x) => {
|
|
169
|
-
const out = typeof x === "function" ? x(untrack(get)) : x;
|
|
170
|
-
return set(out), out;
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
function toSignal(obj, k) {
|
|
174
|
-
const get = () => obj()[k()];
|
|
175
|
-
return [get, toSetter(get, (v) => obj()[k()] = v)];
|
|
176
|
-
}
|
|
177
|
-
function coalesceSignal([get, set], f) {
|
|
178
|
-
return [() => get() ?? set(f), set];
|
|
179
|
-
}
|
|
180
|
-
function unwrapSignal(f) {
|
|
181
|
-
return [() => f()[0](), (x) => f()[1](x)];
|
|
182
|
-
}
|
|
183
154
|
function untrackCall(f, ...args) {
|
|
184
155
|
return untrack(() => f.apply(this, args));
|
|
185
156
|
}
|
|
@@ -207,16 +178,6 @@ function splitAndMemoProps(obj, keys, equals) {
|
|
|
207
178
|
out[0] = memoProps(out[0], keys, equals);
|
|
208
179
|
return out;
|
|
209
180
|
}
|
|
210
|
-
function runWithContext(ctx2, value, f) {
|
|
211
|
-
return createRoot((d) => {
|
|
212
|
-
try {
|
|
213
|
-
(getOwner().context ??= {})[ctx2.id] = value;
|
|
214
|
-
return f(value === void 0 ? ctx2.defaultValue : value);
|
|
215
|
-
} finally {
|
|
216
|
-
d();
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
181
|
function createReactiveResource(f) {
|
|
221
182
|
var refetch;
|
|
222
183
|
const memo = createMemo(f);
|
|
@@ -226,6 +187,50 @@ function createReactiveResource(f) {
|
|
|
226
187
|
}] = createResource(memo);
|
|
227
188
|
return get;
|
|
228
189
|
}
|
|
190
|
+
function Nest(props) {
|
|
191
|
+
const memo = memoProps(props, ["template", "children"]);
|
|
192
|
+
const content = mapArray(() => props.each, (x, i) => {
|
|
193
|
+
const [get, set] = createSignal();
|
|
194
|
+
const out = memo.template(x, get, i);
|
|
195
|
+
return (x2) => {
|
|
196
|
+
onMount(() => set(() => x2));
|
|
197
|
+
onCleanup(() => set(void 0));
|
|
198
|
+
return out;
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
return createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
|
|
202
|
+
}
|
|
203
|
+
const IDENTITY = (x) => x;
|
|
204
|
+
function bind(source, dest, to = IDENTITY) {
|
|
205
|
+
const d = createRoot((d2) => (createRenderEffect(on(source, (x) => dest((prev) => to(x, prev)))), d2));
|
|
206
|
+
return onCleanup(d), d;
|
|
207
|
+
}
|
|
208
|
+
function bindTwoWay(source, dest, to, from) {
|
|
209
|
+
const a = bind(source[0], dest[1], to);
|
|
210
|
+
const b = bind(dest[0], source[1], from);
|
|
211
|
+
return () => (a(), b());
|
|
212
|
+
}
|
|
213
|
+
function toSetter(get, set) {
|
|
214
|
+
return (x) => {
|
|
215
|
+
const out = typeof x === "function" ? x(untrack(get)) : x;
|
|
216
|
+
return set(out), out;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function toSignal(obj, k) {
|
|
220
|
+
const get = () => obj()[k()];
|
|
221
|
+
return [get, toSetter(get, (v) => obj()[k()] = v)];
|
|
222
|
+
}
|
|
223
|
+
function coalesceSignal([get, set], f) {
|
|
224
|
+
return [() => get() ?? set(f), set];
|
|
225
|
+
}
|
|
226
|
+
const unwrap = (f) => new Proxy(f, HANDLER);
|
|
227
|
+
const HANDLER = new Proxy({}, {
|
|
228
|
+
get(cache, k) {
|
|
229
|
+
return cache[k] ??= (t, ...args) => {
|
|
230
|
+
return Reflect[k](t(), ...args);
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
});
|
|
229
234
|
const debug = ReactiveContext.create(false, "debug-scope");
|
|
230
235
|
export {
|
|
231
236
|
Case,
|
|
@@ -245,5 +250,5 @@ export {
|
|
|
245
250
|
toSetter,
|
|
246
251
|
toSignal,
|
|
247
252
|
untrackCall,
|
|
248
|
-
|
|
253
|
+
unwrap
|
|
249
254
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -56,6 +56,16 @@
|
|
|
56
56
|
return out;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
function runWithContext(ctx2, value, f) {
|
|
60
|
+
return solidJs.createRoot((d) => {
|
|
61
|
+
try {
|
|
62
|
+
(solidJs.getOwner().context ??= {})[ctx2.id] = value;
|
|
63
|
+
return f(value === void 0 ? ctx2.defaultValue : value);
|
|
64
|
+
} finally {
|
|
65
|
+
d();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
59
69
|
const ctx = ReactiveContext.create(void 0, "case-when");
|
|
60
70
|
const Case = ctx.Provider;
|
|
61
71
|
function When(props) {
|
|
@@ -143,45 +153,6 @@
|
|
|
143
153
|
}
|
|
144
154
|
});
|
|
145
155
|
}
|
|
146
|
-
function Nest(props) {
|
|
147
|
-
const memo = memoProps(props, ["template", "children"]);
|
|
148
|
-
const content = solidJs.mapArray(() => props.each, (x, i) => {
|
|
149
|
-
const [get, set] = solidJs.createSignal();
|
|
150
|
-
const out = memo.template(x, get, i);
|
|
151
|
-
return (x2) => {
|
|
152
|
-
solidJs.onMount(() => set(() => x2));
|
|
153
|
-
solidJs.onCleanup(() => set(void 0));
|
|
154
|
-
return out;
|
|
155
|
-
};
|
|
156
|
-
});
|
|
157
|
-
return solidJs.createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
|
|
158
|
-
}
|
|
159
|
-
const IDENTITY = (x) => x;
|
|
160
|
-
function bind(source, dest, to = IDENTITY) {
|
|
161
|
-
const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(source, (x) => dest((prev) => to(x, prev)))), d2));
|
|
162
|
-
return solidJs.onCleanup(d), d;
|
|
163
|
-
}
|
|
164
|
-
function bindTwoWay(source, dest, to, from) {
|
|
165
|
-
const a = bind(source[0], dest[1], to);
|
|
166
|
-
const b = bind(dest[0], source[1], from);
|
|
167
|
-
return () => (a(), b());
|
|
168
|
-
}
|
|
169
|
-
function toSetter(get, set) {
|
|
170
|
-
return (x) => {
|
|
171
|
-
const out = typeof x === "function" ? x(solidJs.untrack(get)) : x;
|
|
172
|
-
return set(out), out;
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function toSignal(obj, k) {
|
|
176
|
-
const get = () => obj()[k()];
|
|
177
|
-
return [get, toSetter(get, (v) => obj()[k()] = v)];
|
|
178
|
-
}
|
|
179
|
-
function coalesceSignal([get, set], f) {
|
|
180
|
-
return [() => get() ?? set(f), set];
|
|
181
|
-
}
|
|
182
|
-
function unwrapSignal(f) {
|
|
183
|
-
return [() => f()[0](), (x) => f()[1](x)];
|
|
184
|
-
}
|
|
185
156
|
function untrackCall(f, ...args) {
|
|
186
157
|
return solidJs.untrack(() => f.apply(this, args));
|
|
187
158
|
}
|
|
@@ -209,16 +180,6 @@
|
|
|
209
180
|
out[0] = memoProps(out[0], keys, equals);
|
|
210
181
|
return out;
|
|
211
182
|
}
|
|
212
|
-
function runWithContext(ctx2, value, f) {
|
|
213
|
-
return solidJs.createRoot((d) => {
|
|
214
|
-
try {
|
|
215
|
-
(solidJs.getOwner().context ??= {})[ctx2.id] = value;
|
|
216
|
-
return f(value === void 0 ? ctx2.defaultValue : value);
|
|
217
|
-
} finally {
|
|
218
|
-
d();
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
183
|
function createReactiveResource(f) {
|
|
223
184
|
var refetch;
|
|
224
185
|
const memo = solidJs.createMemo(f);
|
|
@@ -228,6 +189,50 @@
|
|
|
228
189
|
}] = solidJs.createResource(memo);
|
|
229
190
|
return get;
|
|
230
191
|
}
|
|
192
|
+
function Nest(props) {
|
|
193
|
+
const memo = memoProps(props, ["template", "children"]);
|
|
194
|
+
const content = solidJs.mapArray(() => props.each, (x, i) => {
|
|
195
|
+
const [get, set] = solidJs.createSignal();
|
|
196
|
+
const out = memo.template(x, get, i);
|
|
197
|
+
return (x2) => {
|
|
198
|
+
solidJs.onMount(() => set(() => x2));
|
|
199
|
+
solidJs.onCleanup(() => set(void 0));
|
|
200
|
+
return out;
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
return solidJs.createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
|
|
204
|
+
}
|
|
205
|
+
const IDENTITY = (x) => x;
|
|
206
|
+
function bind(source, dest, to = IDENTITY) {
|
|
207
|
+
const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(source, (x) => dest((prev) => to(x, prev)))), d2));
|
|
208
|
+
return solidJs.onCleanup(d), d;
|
|
209
|
+
}
|
|
210
|
+
function bindTwoWay(source, dest, to, from) {
|
|
211
|
+
const a = bind(source[0], dest[1], to);
|
|
212
|
+
const b = bind(dest[0], source[1], from);
|
|
213
|
+
return () => (a(), b());
|
|
214
|
+
}
|
|
215
|
+
function toSetter(get, set) {
|
|
216
|
+
return (x) => {
|
|
217
|
+
const out = typeof x === "function" ? x(solidJs.untrack(get)) : x;
|
|
218
|
+
return set(out), out;
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function toSignal(obj, k) {
|
|
222
|
+
const get = () => obj()[k()];
|
|
223
|
+
return [get, toSetter(get, (v) => obj()[k()] = v)];
|
|
224
|
+
}
|
|
225
|
+
function coalesceSignal([get, set], f) {
|
|
226
|
+
return [() => get() ?? set(f), set];
|
|
227
|
+
}
|
|
228
|
+
const unwrap = (f) => new Proxy(f, HANDLER);
|
|
229
|
+
const HANDLER = new Proxy({}, {
|
|
230
|
+
get(cache, k) {
|
|
231
|
+
return cache[k] ??= (t, ...args) => {
|
|
232
|
+
return Reflect[k](t(), ...args);
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
});
|
|
231
236
|
const debug = ReactiveContext.create(false, "debug-scope");
|
|
232
237
|
exports2.Case = Case;
|
|
233
238
|
exports2.Nest = Nest;
|
|
@@ -246,6 +251,6 @@
|
|
|
246
251
|
exports2.toSetter = toSetter;
|
|
247
252
|
exports2.toSignal = toSignal;
|
|
248
253
|
exports2.untrackCall = untrackCall;
|
|
249
|
-
exports2.
|
|
254
|
+
exports2.unwrap = unwrap;
|
|
250
255
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
251
256
|
});
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -150,9 +150,6 @@ Functions that create bindings between `Signal`s
|
|
|
150
150
|
>
|
|
151
151
|
> #### `coalesceSignal()`
|
|
152
152
|
> Creates a non nullable `Signal` from a nullable one
|
|
153
|
-
>
|
|
154
|
-
> #### `unwrapSignal()`
|
|
155
|
-
> Calls an `Accessor` to a `Signal` maintaining its reactivity
|
|
156
153
|
|
|
157
154
|
### `ReactiveContext.create()`
|
|
158
155
|
Method that creates a reactive version of a solid `Context` with some additional built-in functionalities
|
|
@@ -163,6 +160,12 @@ const valueAccessorForTheCurrentOwner = ctx.read;
|
|
|
163
160
|
const value = ctx();
|
|
164
161
|
```
|
|
165
162
|
|
|
163
|
+
### `runWithContext()`
|
|
164
|
+
Creates a context scope that persists for the duration of a function
|
|
165
|
+
|
|
166
|
+
### `unwrap()`
|
|
167
|
+
Calls an `Accessor` maintaining its reactivity
|
|
168
|
+
|
|
166
169
|
### `debug()`
|
|
167
170
|
Allows you to define ui section that are only visible in debug or NOT in debug
|
|
168
171
|
```tsx
|
|
@@ -189,8 +192,5 @@ Creates a partial version of an object with memoized remaining properties
|
|
|
189
192
|
### `splitAndMemoProps()`
|
|
190
193
|
Like `splitProps()` but memoizes the whole local part
|
|
191
194
|
|
|
192
|
-
### `runWithContext()`
|
|
193
|
-
Creates a context scope that persists for the duration of a function
|
|
194
|
-
|
|
195
195
|
### `createReactiveResource()`
|
|
196
196
|
Like `createResource()` but the provided function will be reactive
|