solid-ctrl-flow 4.1.0 → 5.0.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 +4 -9
- package/dist/index.mjs +35 -15
- package/dist/index.umd.js +34 -14
- package/package.json +1 -1
- package/readMe.md +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -86,17 +86,12 @@ declare type Keyed<T> = Standard<T> & {
|
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
* Memoizes
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* The memoized properties have {@link NO_OP} as setter, this is needed because {@link Ref}s are assigned if they're not functions, so an `undefined` forwarded {@link Ref} would throw in that case (In strict contexts)
|
|
93
|
-
* @param obj Object to partially memoize
|
|
94
|
-
* @param keys The keys of the properties to memoize
|
|
89
|
+
* Memoizes the properties of {@link obj}.
|
|
90
|
+
* The {@link equals} parameter defaults to `false` to allow the specific reactive value to have control over when its dependant effects are triggered
|
|
91
|
+
* @param obj The object to memoize
|
|
95
92
|
* @param equals The comparator function to use on the newly created memos
|
|
96
93
|
*/
|
|
97
|
-
export declare
|
|
98
|
-
|
|
99
|
-
export declare function memoProps<T, K extends readonly (keyof T)[]>(obj: T, keys: K, equals?: Equals): Pick<T, K[number]>;
|
|
94
|
+
export declare const memoProps: <T extends object>(obj: T, equals?: Equals) => T;
|
|
100
95
|
|
|
101
96
|
/**
|
|
102
97
|
* Allows the use of {@link Case}s inside of {@link Switch}es.
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { untrack, createRoot, getOwner, createMemo, Show, createContext, useContext, onCleanup, For, createRenderEffect, on, splitProps, createSignal, createSelector, equalFn, Match, runWithOwner } from "solid-js";
|
|
2
2
|
import { createComponent, memo, mergeProps, spread } from "solid-js/web";
|
|
3
|
-
const NO_OP = () => {
|
|
4
|
-
};
|
|
5
|
-
function memoProps(obj, keys = Reflect.ownKeys(obj), equals = false) {
|
|
6
|
-
const out = {};
|
|
7
|
-
for (const elm of keys)
|
|
8
|
-
Object.defineProperty(out, elm, { enumerable: true, set: NO_OP, get: createMemo(() => obj[elm], void 0, { equals }) });
|
|
9
|
-
return out;
|
|
10
|
-
}
|
|
11
|
-
const splitAndMemoProps = (obj, ...keys) => {
|
|
12
|
-
const out = splitProps(obj, ...keys);
|
|
13
|
-
for (var i = 0; i < keys.length; i++)
|
|
14
|
-
out[i] = memoProps(out[i], keys[i]);
|
|
15
|
-
return out;
|
|
16
|
-
};
|
|
17
3
|
function untrackCall(f, ...args) {
|
|
18
4
|
return untrack(() => f.apply(this, args));
|
|
19
5
|
}
|
|
@@ -229,6 +215,40 @@ function Case(props) {
|
|
|
229
215
|
}
|
|
230
216
|
});
|
|
231
217
|
}
|
|
218
|
+
const memoProps = (obj, equals) => new Proxy(obj, new MemoPropsHandler(getOwner(), equals));
|
|
219
|
+
const splitAndMemoProps = (obj, ...keys) => {
|
|
220
|
+
const out = splitProps(obj, ...keys);
|
|
221
|
+
for (var i = 0; i < keys.length; i++)
|
|
222
|
+
out[i] = memoProps(out[i]);
|
|
223
|
+
return out;
|
|
224
|
+
};
|
|
225
|
+
class MemoPropsHandler {
|
|
226
|
+
constructor(owner, equals = false) {
|
|
227
|
+
this.owner = owner;
|
|
228
|
+
this.equals = equals;
|
|
229
|
+
}
|
|
230
|
+
cache = /* @__PURE__ */ Object.create(null);
|
|
231
|
+
/**
|
|
232
|
+
* -
|
|
233
|
+
* Memoizes each property that gets read
|
|
234
|
+
* @inheritdoc
|
|
235
|
+
*/
|
|
236
|
+
get(t, k) {
|
|
237
|
+
const temp = k;
|
|
238
|
+
const cache = this.cache[temp] ??= this.memoize(t, temp);
|
|
239
|
+
return cache();
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Memoizes a property of an object
|
|
243
|
+
* @param t The object containing the property
|
|
244
|
+
* @param k The key of the property
|
|
245
|
+
*/
|
|
246
|
+
memoize(t, k) {
|
|
247
|
+
const name = `${memoProps.name}(${k.toString()})`;
|
|
248
|
+
const opts = { name, equals: this.equals };
|
|
249
|
+
return runWithOwner(this.owner, () => createMemo(() => t[k], void 0, opts));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
232
252
|
function SameContext(props) {
|
|
233
253
|
return createMemo(() => {
|
|
234
254
|
getOwner().context = props.owner.context;
|
package/dist/index.umd.js
CHANGED
|
@@ -2,20 +2,6 @@
|
|
|
2
2
|
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("solid-js"), require("solid-js/web")) : typeof define === "function" && define.amd ? define(["exports", "solid-js", "solid-js/web"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.solidCtrlFlow = {}, global.solidJs, global.solidJsWeb));
|
|
3
3
|
})(this, function(exports2, solidJs, web) {
|
|
4
4
|
"use strict";
|
|
5
|
-
const NO_OP = () => {
|
|
6
|
-
};
|
|
7
|
-
function memoProps(obj, keys = Reflect.ownKeys(obj), equals = false) {
|
|
8
|
-
const out = {};
|
|
9
|
-
for (const elm of keys)
|
|
10
|
-
Object.defineProperty(out, elm, { enumerable: true, set: NO_OP, get: solidJs.createMemo(() => obj[elm], void 0, { equals }) });
|
|
11
|
-
return out;
|
|
12
|
-
}
|
|
13
|
-
const splitAndMemoProps = (obj, ...keys) => {
|
|
14
|
-
const out = solidJs.splitProps(obj, ...keys);
|
|
15
|
-
for (var i = 0; i < keys.length; i++)
|
|
16
|
-
out[i] = memoProps(out[i], keys[i]);
|
|
17
|
-
return out;
|
|
18
|
-
};
|
|
19
5
|
function untrackCall(f, ...args) {
|
|
20
6
|
return solidJs.untrack(() => f.apply(this, args));
|
|
21
7
|
}
|
|
@@ -231,6 +217,40 @@
|
|
|
231
217
|
}
|
|
232
218
|
});
|
|
233
219
|
}
|
|
220
|
+
const memoProps = (obj, equals) => new Proxy(obj, new MemoPropsHandler(solidJs.getOwner(), equals));
|
|
221
|
+
const splitAndMemoProps = (obj, ...keys) => {
|
|
222
|
+
const out = solidJs.splitProps(obj, ...keys);
|
|
223
|
+
for (var i = 0; i < keys.length; i++)
|
|
224
|
+
out[i] = memoProps(out[i]);
|
|
225
|
+
return out;
|
|
226
|
+
};
|
|
227
|
+
class MemoPropsHandler {
|
|
228
|
+
constructor(owner, equals = false) {
|
|
229
|
+
this.owner = owner;
|
|
230
|
+
this.equals = equals;
|
|
231
|
+
}
|
|
232
|
+
cache = /* @__PURE__ */ Object.create(null);
|
|
233
|
+
/**
|
|
234
|
+
* -
|
|
235
|
+
* Memoizes each property that gets read
|
|
236
|
+
* @inheritdoc
|
|
237
|
+
*/
|
|
238
|
+
get(t, k) {
|
|
239
|
+
const temp = k;
|
|
240
|
+
const cache = this.cache[temp] ??= this.memoize(t, temp);
|
|
241
|
+
return cache();
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Memoizes a property of an object
|
|
245
|
+
* @param t The object containing the property
|
|
246
|
+
* @param k The key of the property
|
|
247
|
+
*/
|
|
248
|
+
memoize(t, k) {
|
|
249
|
+
const name = `${memoProps.name}(${k.toString()})`;
|
|
250
|
+
const opts = { name, equals: this.equals };
|
|
251
|
+
return solidJs.runWithOwner(this.owner, () => solidJs.createMemo(() => t[k], void 0, opts));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
234
254
|
function SameContext(props) {
|
|
235
255
|
return solidJs.createMemo(() => {
|
|
236
256
|
solidJs.getOwner().context = props.owner.context;
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -225,10 +225,10 @@ return <>
|
|
|
225
225
|
Calls an `Accessor` maintaining its reactivity at 1 level
|
|
226
226
|
|
|
227
227
|
### `memoProps()`
|
|
228
|
-
|
|
228
|
+
Memoizes the properties of an object
|
|
229
229
|
|
|
230
230
|
### `splitAndMemoProps()`
|
|
231
|
-
Like `splitProps()` but
|
|
231
|
+
Like `splitProps()` but passes the every part except the last one to [`memoProps()`](#memoprops)
|
|
232
232
|
|
|
233
233
|
### `untrackCall()`
|
|
234
234
|
Calls a function untracking what happens inside of it but not what gets passed as its argument
|