@pyreon/attrs 0.24.0 → 0.24.2
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/lib/index.js +8 -5
- package/package.json +4 -4
- package/src/utils/attrs.ts +12 -6
package/lib/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { compose, hoistNonReactStatics, isEmpty, omit, pick } from "@pyreon/ui-core";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/attrs.ts
|
|
4
|
-
const removeUndefinedProps = ((props) =>
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const removeUndefinedProps = ((props) => {
|
|
5
|
+
const result = {};
|
|
6
|
+
for (const key in props) {
|
|
7
|
+
const value = props[key];
|
|
8
|
+
if (value !== void 0) result[key] = value;
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
});
|
|
9
12
|
const calculateChainOptions = (options) => (args) => {
|
|
10
13
|
const result = {};
|
|
11
14
|
if (!options || isEmpty(options)) return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyreon/attrs",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.2",
|
|
4
4
|
"description": "Attrs HOC chaining for Pyreon components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"typecheck": "tsc --noEmit"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@pyreon/typescript": "^0.24.
|
|
44
|
+
"@pyreon/typescript": "^0.24.2",
|
|
45
45
|
"@vitus-labs/tools-rolldown": "^2.4.0"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">= 22"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@pyreon/core": "^0.24.
|
|
52
|
-
"@pyreon/ui-core": "^0.24.
|
|
51
|
+
"@pyreon/core": "^0.24.2",
|
|
52
|
+
"@pyreon/ui-core": "^0.24.2"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/utils/attrs.ts
CHANGED
|
@@ -10,12 +10,18 @@ type RemoveUndefinedProps = <T extends Record<string, any>>(
|
|
|
10
10
|
props: T,
|
|
11
11
|
) => { [I in keyof T as T[I] extends undefined ? never : I]: T[I] }
|
|
12
12
|
|
|
13
|
-
export const removeUndefinedProps = (<T extends Record<string, any>>(props: T) =>
|
|
14
|
-
Object.keys
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
export const removeUndefinedProps = (<T extends Record<string, any>>(props: T) => {
|
|
14
|
+
// Direct for-in loop avoids the `Object.keys` array allocation that
|
|
15
|
+
// the prior `reduce` over `Object.keys(props)` paid on every render.
|
|
16
|
+
// The hot path fires on every content-equal re-render of any attrs-
|
|
17
|
+
// wrapped component. Ported from vitus-labs `b003de47`.
|
|
18
|
+
const result: Record<string, unknown> = {}
|
|
19
|
+
for (const key in props) {
|
|
20
|
+
const value = props[key]
|
|
21
|
+
if (value !== undefined) result[key] = value
|
|
22
|
+
}
|
|
23
|
+
return result
|
|
24
|
+
}) as RemoveUndefinedProps
|
|
19
25
|
|
|
20
26
|
/**
|
|
21
27
|
* Reduces an array of option functions (from chained `.attrs()` calls)
|