Skip to content

Commit 0af5fa5

Browse files
committed
Replace lodash keys with native code
1 parent b4ef049 commit 0af5fa5

File tree

10 files changed

+49
-35
lines changed

10 files changed

+49
-35
lines changed

.changeset/curvy-socks-sip.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"victory-box-plot": patch
3+
"victory-core": patch
4+
"victory-create-container": patch
5+
"victory-legend": patch
6+
"victory-selection-container": patch
7+
"victory-shared-events": patch
8+
"victory-stack": patch
9+
"victory-voronoi": patch
10+
"victory-voronoi-container": patch
11+
---
12+
13+
Replace lodash keys with native code

packages/victory-box-plot/src/helper-methods.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { orderBy, defaults, uniq, groupBy, keys } from "lodash";
1+
import { orderBy, defaults, uniq, groupBy } from "lodash";
22
import { Helpers, Scale, Domain, Data, Collection } from "victory-core";
33
import {
44
min as d3Min,
@@ -72,7 +72,7 @@ const processData = (data) => {
7272
} else {
7373
/* Group data by independent variable and generate summary statistics for each group */
7474
const groupedData = groupBy(data, groupKey);
75-
return keys(groupedData).map((key) => {
75+
return Object.keys(groupedData).map((key) => {
7676
const datum = groupedData[key];
7777
const sortedData = orderBy(datum, sortKey);
7878
return getSummaryStatistics(sortedData);

packages/victory-core/src/victory-portal/portal.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "react";
2-
import { keys } from "lodash";
32
import { PortalContextValue } from "./portal-context";
43

54
export interface PortalProps {
@@ -40,7 +39,7 @@ export class Portal
4039
};
4140

4241
public getChildren() {
43-
return keys(this.map).map((key) => {
42+
return Object.keys(this.map).map((key) => {
4443
const el = this.map[key];
4544
return el ? React.cloneElement(el, { key }) : el;
4645
});

packages/victory-core/src/victory-util/add-events.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { defaults, difference, isEmpty, keys, pick } from "lodash";
2+
import { defaults, difference, isEmpty, pick } from "lodash";
33
import type { ComponentEvent } from "./events";
44
import * as Events from "./events";
55
import isEqual from "react-fast-compare";
@@ -180,15 +180,15 @@ export function addEvents<
180180
}
181181

182182
componentDidMount() {
183-
const globalEventKeys = keys(this.globalEvents);
183+
const globalEventKeys = Object.keys(this.globalEvents);
184184
globalEventKeys.forEach((key) => this.addGlobalListener(key));
185185
this.prevGlobalEventKeys = globalEventKeys;
186186
}
187187

188188
componentDidUpdate(prevProps) {
189189
const calculatedState = this.getStateChanges(prevProps);
190190
this.calculatedState = calculatedState;
191-
const globalEventKeys = keys(this.globalEvents);
191+
const globalEventKeys = Object.keys(this.globalEvents);
192192
const removedGlobalEventKeys = difference(
193193
this.prevGlobalEventKeys,
194194
globalEventKeys,
@@ -285,7 +285,7 @@ export function addEvents<
285285
? sharedEvents.getEventState
286286
: () => undefined;
287287
const baseProps = this.getBaseProps(props, getSharedEventState);
288-
const dataKeys = keys(baseProps).filter((key) => key !== "parent");
288+
const dataKeys = Object.keys(baseProps).filter((key) => key !== "parent");
289289
const hasEvents = props.events || props.sharedEvents || componentEvents;
290290
const events = this.getAllEvents(props);
291291
return {
@@ -310,7 +310,7 @@ export function addEvents<
310310
}
311311

312312
cacheValues(obj) {
313-
keys(obj).forEach((key) => {
313+
Object.keys(obj).forEach((key) => {
314314
this[key] = obj[key];
315315
});
316316
}

packages/victory-core/src/victory-util/events.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-use-before-define */
2-
import { isEmpty, pickBy, omitBy, uniq, keys } from "lodash";
2+
import { isEmpty, pickBy, omitBy, uniq } from "lodash";
33
import type { EventMixinCalculatedValues } from "./add-events";
44
import { isFunction } from "./helpers";
55

@@ -157,12 +157,14 @@ export function getScopedEvents(
157157
}
158158
if (eventReturn.eventKey === "all") {
159159
return newBaseProps[childName]
160-
? keys(newBaseProps[childName]).filter((value) => value !== "parent")
161-
: keys(newBaseProps).filter((value) => value !== "parent");
160+
? Object.keys(newBaseProps[childName]).filter(
161+
(value) => value !== "parent",
162+
)
163+
: Object.keys(newBaseProps).filter((value) => value !== "parent");
162164
} else if (eventReturn.eventKey === undefined && eventKey === "parent") {
163165
return newBaseProps[childName]
164-
? keys(newBaseProps[childName])
165-
: keys(newBaseProps);
166+
? Object.keys(newBaseProps[childName])
167+
: Object.keys(newBaseProps);
166168
}
167169
return eventReturn.eventKey !== undefined
168170
? eventReturn.eventKey
@@ -194,7 +196,7 @@ export function getScopedEvents(
194196
if (state[key] && state[key][target]) {
195197
delete state[key][target];
196198
}
197-
if (state[key] && !keys(state[key]).length) {
199+
if (state[key] && !Object.keys(state[key]).length) {
198200
delete state[key];
199201
}
200202
return state;
@@ -234,7 +236,7 @@ export function getScopedEvents(
234236
// returns an entire mutated state for all children
235237
const allChildNames =
236238
childNames === "all"
237-
? keys(newBaseProps).filter((value) => value !== "parent")
239+
? Object.keys(newBaseProps).filter((value) => value !== "parent")
238240
: childNames;
239241
return Array.isArray(allChildNames)
240242
? allChildNames.reduce((memo, childName) => {
@@ -278,7 +280,7 @@ export function getScopedEvents(
278280
};
279281

280282
// returns a new events object with enhanced event handlers
281-
return keys(events).reduce((memo, event) => {
283+
return Object.keys(events).reduce((memo, event) => {
282284
memo[event] = onEvent;
283285
return memo;
284286
}, {});
@@ -295,7 +297,7 @@ export function getPartialEvents(
295297
): PartialEvents {
296298
if (!events) return {};
297299

298-
return keys(events).reduce((memo, eventName) => {
300+
return Object.keys(events).reduce((memo, eventName) => {
299301
const appliedEvent = (evt) =>
300302
events[eventName](evt, childProps, eventKey, eventName);
301303
memo[eventName] = appliedEvent;
@@ -378,7 +380,7 @@ export function getExternalMutations(
378380
baseState = {},
379381
childName?,
380382
) {
381-
const eventKeys = keys(baseProps);
383+
const eventKeys = Object.keys(baseProps);
382384
return eventKeys.reduce((memo, eventKey) => {
383385
const keyState = baseState[eventKey] || {};
384386
const keyProps = baseProps[eventKey] || {};
@@ -397,7 +399,7 @@ export function getExternalMutations(
397399
} else {
398400
// use keys from both state and props so that elements not intially included in baseProps
399401
// will be used. (i.e. labels)
400-
const targets = uniq(keys(keyProps).concat(keys(keyState)));
402+
const targets = uniq(Object.keys(keyProps).concat(Object.keys(keyState)));
401403
memo[eventKey] = targets.reduce((m, target) => {
402404
const identifier = { eventKey, target, childName };
403405
const mutation = getExternalMutation(

packages/victory-core/src/victory-util/helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-use-before-define */
22
import React, { isValidElement } from "react";
3-
import { defaults, property, pick, keys } from "lodash";
3+
import { defaults, property, pick } from "lodash";
44
import { CallbackArgs } from "../types/callbacks";
55
import { ValueOrAccessor } from "../types/prop-types";
66

@@ -139,10 +139,10 @@ export function evaluateStyle(style, props) {
139139
if (props.disableInlineStyles) {
140140
return {};
141141
}
142-
if (!style || !keys(style).some((value) => isFunction(style[value]))) {
142+
if (!style || !Object.keys(style).some((value) => isFunction(style[value]))) {
143143
return style;
144144
}
145-
return keys(style).reduce((prev, curr) => {
145+
return Object.keys(style).reduce((prev, curr) => {
146146
prev[curr] = evaluateProp(style[curr], props);
147147
return prev;
148148
}, {});

packages/victory-core/src/victory-util/transitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defaults, identity, keys } from "lodash";
1+
import { defaults, identity } from "lodash";
22
import React from "react";
33
import { AnimatePropTypeInterface } from "../types/prop-types";
44

@@ -16,7 +16,7 @@ function getKeyedData(data) {
1616

1717
function getKeyedDataDifference(a, b) {
1818
let hasDifference = false;
19-
const difference = keys(a).reduce((_difference, key) => {
19+
const difference = Object.keys(a).reduce((_difference, key) => {
2020
if (!(key in b)) {
2121
hasDifference = true;
2222
_difference[key] = true;

packages/victory-legend/src/helper-methods.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defaults, groupBy, keys, sum, range } from "lodash";
1+
import { defaults, groupBy, sum, range } from "lodash";
22
import { Helpers, Style, TextSize } from "victory-core";
33
import { VictoryLegendProps } from "./victory-legend";
44

@@ -90,7 +90,7 @@ const getColumnWidths = (props, data) => {
9090
? (gutter.left || 0) + (gutter.right || 0)
9191
: gutter || 0;
9292
const dataByColumn = groupBy(data, "column");
93-
const columns = keys(dataByColumn);
93+
const columns = Object.keys(dataByColumn);
9494
return columns.reduce<number[]>((memo, curr, index) => {
9595
const lengths = dataByColumn[curr].map((d) => {
9696
return d.textSize.width + d.size + d.symbolSpacer + gutterWidth;
@@ -107,7 +107,7 @@ const getRowHeights = (props, data) => {
107107
? (gutter.top || 0) + (gutter.bottom || 0)
108108
: gutter || 0;
109109
const dataByRow = groupBy(data, "row");
110-
return keys(dataByRow).reduce<number[]>((memo, curr, index) => {
110+
return Object.keys(dataByRow).reduce<number[]>((memo, curr, index) => {
111111
const rows = dataByRow[curr];
112112
const lengths = rows.map((d) => {
113113
return d.textSize.height + d.symbolSpacer + gutterHeight;

packages/victory-shared-events/src/victory-shared-events.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defaults, isEmpty, fromPairs, keys, difference } from "lodash";
1+
import { defaults, isEmpty, fromPairs, difference } from "lodash";
22
import React from "react";
33
import {
44
EventCallbackInterface,
@@ -74,13 +74,13 @@ export class VictorySharedEvents extends React.Component<VictorySharedEventsProp
7474
}
7575

7676
componentDidMount() {
77-
const globalEventKeys = keys(this.globalEvents);
77+
const globalEventKeys = Object.keys(this.globalEvents);
7878
globalEventKeys.forEach((key) => this.addGlobalListener(key));
7979
this.prevGlobalEventKeys = globalEventKeys;
8080
}
8181

8282
componentDidUpdate() {
83-
const globalEventKeys = keys(this.globalEvents);
83+
const globalEventKeys = Object.keys(this.globalEvents);
8484
const removedGlobalEventKeys = difference(
8585
this.prevGlobalEventKeys,
8686
globalEventKeys,
@@ -152,7 +152,7 @@ export class VictorySharedEvents extends React.Component<VictorySharedEventsProp
152152
props.externalEventMutations,
153153
baseProps,
154154
this.state,
155-
keys(baseProps),
155+
Object.keys(baseProps),
156156
)
157157
: undefined;
158158
}
@@ -258,7 +258,7 @@ export class VictorySharedEvents extends React.Component<VictorySharedEventsProp
258258
return memo.concat(child);
259259
}, []);
260260
};
261-
const childNames = keys(baseProps);
261+
const childNames = Object.keys(baseProps);
262262
const childComponents = React.Children.toArray(props.children);
263263
return alterChildren(childComponents, childNames);
264264
}

packages/victory-stack/src/helper-methods.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-use-before-define */
2-
import { keys, orderBy } from "lodash";
2+
import { orderBy } from "lodash";
33
import React from "react";
44
import { Helpers, Scale, Wrapper } from "victory-core";
55
import isEqual from "react-fast-compare";
@@ -19,7 +19,7 @@ function fillData(props, datasets) {
1919
});
2020
return prev;
2121
}, {});
22-
const xKeys = keys(xMap).map((k) => Number(k));
22+
const xKeys = Object.keys(xMap).map((k) => Number(k));
2323
const xArr = orderBy(xKeys);
2424

2525
return datasets.map((dataset) => {

0 commit comments

Comments
 (0)