diff --git a/.changeset/curvy-socks-sip.md b/.changeset/curvy-socks-sip.md new file mode 100644 index 000000000..13fe0ff53 --- /dev/null +++ b/.changeset/curvy-socks-sip.md @@ -0,0 +1,13 @@ +--- +"victory-box-plot": patch +"victory-core": patch +"victory-create-container": patch +"victory-legend": patch +"victory-selection-container": patch +"victory-shared-events": patch +"victory-stack": patch +"victory-voronoi": patch +"victory-voronoi-container": patch +--- + +Replace lodash keys with native code diff --git a/packages/victory-box-plot/src/helper-methods.tsx b/packages/victory-box-plot/src/helper-methods.tsx index eab698552..09171d31c 100644 --- a/packages/victory-box-plot/src/helper-methods.tsx +++ b/packages/victory-box-plot/src/helper-methods.tsx @@ -1,4 +1,4 @@ -import { orderBy, defaults, uniq, groupBy, keys } from "lodash"; +import { orderBy, defaults, uniq, groupBy } from "lodash"; import { Helpers, Scale, Domain, Data, Collection } from "victory-core"; import { min as d3Min, @@ -72,7 +72,7 @@ const processData = (data) => { } else { /* Group data by independent variable and generate summary statistics for each group */ const groupedData = groupBy(data, groupKey); - return keys(groupedData).map((key) => { + return Object.keys(groupedData).map((key) => { const datum = groupedData[key]; const sortedData = orderBy(datum, sortKey); return getSummaryStatistics(sortedData); diff --git a/packages/victory-core/src/victory-portal/portal.tsx b/packages/victory-core/src/victory-portal/portal.tsx index 3195394f4..50b3ed0d0 100644 --- a/packages/victory-core/src/victory-portal/portal.tsx +++ b/packages/victory-core/src/victory-portal/portal.tsx @@ -1,5 +1,4 @@ import React from "react"; -import { keys } from "lodash"; import { PortalContextValue } from "./portal-context"; export interface PortalProps { @@ -40,7 +39,7 @@ export class Portal }; public getChildren() { - return keys(this.map).map((key) => { + return Object.keys(this.map).map((key) => { const el = this.map[key]; return el ? React.cloneElement(el, { key }) : el; }); diff --git a/packages/victory-core/src/victory-util/add-events.tsx b/packages/victory-core/src/victory-util/add-events.tsx index 0f0daefb6..9b698d056 100644 --- a/packages/victory-core/src/victory-util/add-events.tsx +++ b/packages/victory-core/src/victory-util/add-events.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { defaults, difference, isEmpty, keys, pick } from "lodash"; +import { defaults, difference, isEmpty, pick } from "lodash"; import type { ComponentEvent } from "./events"; import * as Events from "./events"; import isEqual from "react-fast-compare"; @@ -180,7 +180,7 @@ export function addEvents< } componentDidMount() { - const globalEventKeys = keys(this.globalEvents); + const globalEventKeys = Object.keys(this.globalEvents); globalEventKeys.forEach((key) => this.addGlobalListener(key)); this.prevGlobalEventKeys = globalEventKeys; } @@ -188,7 +188,7 @@ export function addEvents< componentDidUpdate(prevProps) { const calculatedState = this.getStateChanges(prevProps); this.calculatedState = calculatedState; - const globalEventKeys = keys(this.globalEvents); + const globalEventKeys = Object.keys(this.globalEvents); const removedGlobalEventKeys = difference( this.prevGlobalEventKeys, globalEventKeys, @@ -285,7 +285,7 @@ export function addEvents< ? sharedEvents.getEventState : () => undefined; const baseProps = this.getBaseProps(props, getSharedEventState); - const dataKeys = keys(baseProps).filter((key) => key !== "parent"); + const dataKeys = Object.keys(baseProps).filter((key) => key !== "parent"); const hasEvents = props.events || props.sharedEvents || componentEvents; const events = this.getAllEvents(props); return { @@ -310,7 +310,7 @@ export function addEvents< } cacheValues(obj) { - keys(obj).forEach((key) => { + Object.keys(obj).forEach((key) => { this[key] = obj[key]; }); } diff --git a/packages/victory-core/src/victory-util/events.ts b/packages/victory-core/src/victory-util/events.ts index ddb8e90fe..b12c551e0 100644 --- a/packages/victory-core/src/victory-util/events.ts +++ b/packages/victory-core/src/victory-util/events.ts @@ -1,5 +1,5 @@ /* eslint-disable no-use-before-define */ -import { isEmpty, pickBy, omitBy, uniq, keys } from "lodash"; +import { isEmpty, pickBy, omitBy, uniq } from "lodash"; import type { EventMixinCalculatedValues } from "./add-events"; import { isFunction } from "./helpers"; @@ -157,12 +157,14 @@ export function getScopedEvents( } if (eventReturn.eventKey === "all") { return newBaseProps[childName] - ? keys(newBaseProps[childName]).filter((value) => value !== "parent") - : keys(newBaseProps).filter((value) => value !== "parent"); + ? Object.keys(newBaseProps[childName]).filter( + (value) => value !== "parent", + ) + : Object.keys(newBaseProps).filter((value) => value !== "parent"); } else if (eventReturn.eventKey === undefined && eventKey === "parent") { return newBaseProps[childName] - ? keys(newBaseProps[childName]) - : keys(newBaseProps); + ? Object.keys(newBaseProps[childName]) + : Object.keys(newBaseProps); } return eventReturn.eventKey !== undefined ? eventReturn.eventKey @@ -194,7 +196,7 @@ export function getScopedEvents( if (state[key] && state[key][target]) { delete state[key][target]; } - if (state[key] && !keys(state[key]).length) { + if (state[key] && !Object.keys(state[key]).length) { delete state[key]; } return state; @@ -234,7 +236,7 @@ export function getScopedEvents( // returns an entire mutated state for all children const allChildNames = childNames === "all" - ? keys(newBaseProps).filter((value) => value !== "parent") + ? Object.keys(newBaseProps).filter((value) => value !== "parent") : childNames; return Array.isArray(allChildNames) ? allChildNames.reduce((memo, childName) => { @@ -278,7 +280,7 @@ export function getScopedEvents( }; // returns a new events object with enhanced event handlers - return keys(events).reduce((memo, event) => { + return Object.keys(events).reduce((memo, event) => { memo[event] = onEvent; return memo; }, {}); @@ -295,7 +297,7 @@ export function getPartialEvents( ): PartialEvents { if (!events) return {}; - return keys(events).reduce((memo, eventName) => { + return Object.keys(events).reduce((memo, eventName) => { const appliedEvent = (evt) => events[eventName](evt, childProps, eventKey, eventName); memo[eventName] = appliedEvent; @@ -378,7 +380,7 @@ export function getExternalMutations( baseState = {}, childName?, ) { - const eventKeys = keys(baseProps); + const eventKeys = Object.keys(baseProps); return eventKeys.reduce((memo, eventKey) => { const keyState = baseState[eventKey] || {}; const keyProps = baseProps[eventKey] || {}; @@ -397,7 +399,7 @@ export function getExternalMutations( } else { // use keys from both state and props so that elements not intially included in baseProps // will be used. (i.e. labels) - const targets = uniq(keys(keyProps).concat(keys(keyState))); + const targets = uniq(Object.keys(keyProps).concat(Object.keys(keyState))); memo[eventKey] = targets.reduce((m, target) => { const identifier = { eventKey, target, childName }; const mutation = getExternalMutation( diff --git a/packages/victory-core/src/victory-util/helpers.ts b/packages/victory-core/src/victory-util/helpers.ts index 0e42df739..7a43e70bf 100644 --- a/packages/victory-core/src/victory-util/helpers.ts +++ b/packages/victory-core/src/victory-util/helpers.ts @@ -1,6 +1,6 @@ /* eslint-disable no-use-before-define */ import React, { isValidElement } from "react"; -import { defaults, property, pick, keys } from "lodash"; +import { defaults, property, pick } from "lodash"; import { CallbackArgs } from "../types/callbacks"; import { ValueOrAccessor } from "../types/prop-types"; @@ -139,10 +139,10 @@ export function evaluateStyle(style, props) { if (props.disableInlineStyles) { return {}; } - if (!style || !keys(style).some((value) => isFunction(style[value]))) { + if (!style || !Object.keys(style).some((value) => isFunction(style[value]))) { return style; } - return keys(style).reduce((prev, curr) => { + return Object.keys(style).reduce((prev, curr) => { prev[curr] = evaluateProp(style[curr], props); return prev; }, {}); diff --git a/packages/victory-core/src/victory-util/transitions.ts b/packages/victory-core/src/victory-util/transitions.ts index 700623705..5167d7616 100644 --- a/packages/victory-core/src/victory-util/transitions.ts +++ b/packages/victory-core/src/victory-util/transitions.ts @@ -1,4 +1,4 @@ -import { defaults, identity, keys } from "lodash"; +import { defaults, identity } from "lodash"; import React from "react"; import { AnimatePropTypeInterface } from "../types/prop-types"; @@ -16,7 +16,7 @@ function getKeyedData(data) { function getKeyedDataDifference(a, b) { let hasDifference = false; - const difference = keys(a).reduce((_difference, key) => { + const difference = Object.keys(a).reduce((_difference, key) => { if (!(key in b)) { hasDifference = true; _difference[key] = true; diff --git a/packages/victory-legend/src/helper-methods.ts b/packages/victory-legend/src/helper-methods.ts index 520685136..badbc172c 100644 --- a/packages/victory-legend/src/helper-methods.ts +++ b/packages/victory-legend/src/helper-methods.ts @@ -1,4 +1,4 @@ -import { defaults, groupBy, keys, sum, range } from "lodash"; +import { defaults, groupBy, sum, range } from "lodash"; import { Helpers, Style, TextSize } from "victory-core"; import { VictoryLegendProps } from "./victory-legend"; @@ -90,7 +90,7 @@ const getColumnWidths = (props, data) => { ? (gutter.left || 0) + (gutter.right || 0) : gutter || 0; const dataByColumn = groupBy(data, "column"); - const columns = keys(dataByColumn); + const columns = Object.keys(dataByColumn); return columns.reduce((memo, curr, index) => { const lengths = dataByColumn[curr].map((d) => { return d.textSize.width + d.size + d.symbolSpacer + gutterWidth; @@ -107,7 +107,7 @@ const getRowHeights = (props, data) => { ? (gutter.top || 0) + (gutter.bottom || 0) : gutter || 0; const dataByRow = groupBy(data, "row"); - return keys(dataByRow).reduce((memo, curr, index) => { + return Object.keys(dataByRow).reduce((memo, curr, index) => { const rows = dataByRow[curr]; const lengths = rows.map((d) => { return d.textSize.height + d.symbolSpacer + gutterHeight; diff --git a/packages/victory-shared-events/src/victory-shared-events.tsx b/packages/victory-shared-events/src/victory-shared-events.tsx index 18efeeb37..57e4f8d52 100644 --- a/packages/victory-shared-events/src/victory-shared-events.tsx +++ b/packages/victory-shared-events/src/victory-shared-events.tsx @@ -1,4 +1,4 @@ -import { defaults, isEmpty, fromPairs, keys, difference } from "lodash"; +import { defaults, isEmpty, fromPairs, difference } from "lodash"; import React from "react"; import { EventCallbackInterface, @@ -74,13 +74,13 @@ export class VictorySharedEvents extends React.Component this.addGlobalListener(key)); this.prevGlobalEventKeys = globalEventKeys; } componentDidUpdate() { - const globalEventKeys = keys(this.globalEvents); + const globalEventKeys = Object.keys(this.globalEvents); const removedGlobalEventKeys = difference( this.prevGlobalEventKeys, globalEventKeys, @@ -152,7 +152,7 @@ export class VictorySharedEvents extends React.Component Number(k)); + const xKeys = Object.keys(xMap).map((k) => Number(k)); const xArr = orderBy(xKeys); return datasets.map((dataset) => {