@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 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) => Object.keys(props).reduce((acc, key) => {
5
- const currentValue = props[key];
6
- if (currentValue !== void 0) acc[key] = currentValue;
7
- return acc;
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.0",
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.0",
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.0",
52
- "@pyreon/ui-core": "^0.24.0"
51
+ "@pyreon/core": "^0.24.2",
52
+ "@pyreon/ui-core": "^0.24.2"
53
53
  }
54
54
  }
@@ -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(props).reduce<Record<string, unknown>>((acc, key) => {
15
- const currentValue = props[key]
16
- if (currentValue !== undefined) acc[key] = currentValue
17
- return acc
18
- }, {})) as RemoveUndefinedProps
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)