Skip to content

Commit 81cd3c9

Browse files
paddymulclaude
andcommitted
perf: convert lodash-es to named imports for tree-shaking
Replace `import * as _ from "lodash-es"` with named imports like `import { map, filter, keys } from "lodash-es"` across all files. Remove unused lodash imports from 10 files that didn't use any lodash functions. This ensures all bundlers (including esbuild) can tree-shake unused lodash functions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent acbe4c7 commit 81cd3c9

22 files changed

Lines changed: 83 additions & 93 deletions

packages/buckaroo-js-core/src/components/BuckarooWidgetInfinite.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useMemo, useState } from "react";
2-
import * as _ from "lodash-es";
32
import { OperationResult } from "./DependentTabs";
43
import { ColumnsEditor } from "./ColumnsEditor";
54

packages/buckaroo-js-core/src/components/DCFCell.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useState } from "react";
2-
import * as _ from "lodash-es";
32
import { OperationResult } from "./DependentTabs";
43
import { ColumnsEditor } from "./ColumnsEditor";
54

packages/buckaroo-js-core/src/components/DFViewerParts/ChartCell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as _ from "lodash-es";
1+
import { isArray } from "lodash-es";
22
import React from "react";
33
import { createPortal } from "react-dom";
44

@@ -125,7 +125,7 @@ export const getChartCell = (multiChartCellProps: ChartDisplayerA) => {
125125
const potentialHistogramArr = props.value;
126126
//for key "index", the value is "histogram"
127127
// this causes ReChart to blow up, so we check to see if it's an array
128-
if (potentialHistogramArr === undefined || !_.isArray(potentialHistogramArr)) {
128+
if (potentialHistogramArr === undefined || !isArray(potentialHistogramArr)) {
129129
return <span></span>;
130130
}
131131
const histogramArr = potentialHistogramArr as LineObservation[];

packages/buckaroo-js-core/src/components/DFViewerParts/DFViewerDataHelper.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IDatasource, IGetRowsParams } from "@ag-grid-community/core";
2-
import * as _ from "lodash-es";
2+
import { keys, times, reduce } from "lodash-es";
33

44
export type RawDataWrapper = {
55
data: any[];
@@ -48,11 +48,11 @@ export const createDatasourceWrapper = (data: DFData, delay_in_milliseconds: num
4848
};
4949

5050
export const dictOfArraystoDFData = (dict: Record<string, any[]>): DFData => {
51-
const keys = _.keys(dict);
52-
const length = dict[keys[0]].length;
51+
const dictKeys = keys(dict);
52+
const length = dict[dictKeys[0]].length;
5353

54-
return _.times(length, index => {
55-
return _.reduce(keys, (result, key) => {
54+
return times(length, index => {
55+
return reduce(dictKeys, (result, key) => {
5656
result[key] = dict[key][index];
5757
return result;
5858
}, {} as Record<string, any>);

packages/buckaroo-js-core/src/components/DFViewerParts/DFViewerInfinite.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
useEffect,
55
useRef,
66
} from "react";
7-
import * as _ from "lodash-es";
87
import { DFData, DFDataRow, DFViewerConfig, SDFT } from "./DFWhole";
98

109
import { getCellRendererSelector, dfToAgrid, extractPinnedRows, extractSDFT } from "./gridUtils";

packages/buckaroo-js-core/src/components/DFViewerParts/DFWhole.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// I'm not sure about adding underlying types too
22

33
import { ColDef, ColGroupDef, GridOptions } from "@ag-grid-community/core";
4-
import * as _ from "lodash-es";
54

65
type AGGrid_ColDef = ColDef;
76
export type ColDefOrGroup = ColDef|ColGroupDef

packages/buckaroo-js-core/src/components/DFViewerParts/Displayer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
StringDisplayerA,
99
ObjDisplayerA,
1010
} from "./DFWhole";
11-
import * as _ from "lodash-es";
11+
import { includes, isArray, isBoolean, isDate, isObject, map } from "lodash-es";
1212

1313
import { HistogramCell } from "./HistogramCell";
1414
import { Base64PNGDisplayer, LinkCellRenderer, SVGDisplayer } from "./OtherRenderers";
@@ -43,12 +43,12 @@ export const getStringFormatter = (args: StringDisplayerA) => {
4343
};
4444

4545
const dictDisplayer = (val: Record<string, any>): string => {
46-
const objBody = _.map(val, (value, key) => `'${key}': ${objDisplayer(value)}`).join(",");
46+
const objBody = map(val, (value, key) => `'${key}': ${objDisplayer(value)}`).join(",");
4747
return `{ ${objBody} }`;
4848
};
4949

5050
export const isValidDate = (possibleDate: any): boolean => {
51-
if (_.isDate(possibleDate) && isFinite(possibleDate.getTime())) {
51+
if (isDate(possibleDate) && isFinite(possibleDate.getTime())) {
5252
return true;
5353
}
5454
return false;
@@ -72,11 +72,11 @@ export const dateDisplayerDefault = (d: Date): string => {
7272
const objDisplayer = (val: any | any[]): string => {
7373
if (val === undefined || val === null) {
7474
return "None";
75-
} else if (_.isArray(val)) {
75+
} else if (isArray(val)) {
7676
return `[ ${val.map(objDisplayer).join(", ")}]`;
77-
} else if (_.isBoolean(val)) {
77+
} else if (isBoolean(val)) {
7878
return boolDisplayer(val);
79-
} else if (_.isObject(val)) {
79+
} else if (isObject(val)) {
8080
return dictDisplayer(val);
8181
} else {
8282
return val.toString();
@@ -138,7 +138,7 @@ export const getFloatFormatter = (hint: FloatDisplayerA) => {
138138
}
139139

140140
const res: string = floatFormatter.format(params.value);
141-
if (!_.includes(res, ".")) {
141+
if (!includes(res, ".")) {
142142
const padLength = res.length + hint.max_fraction_digits + 1;
143143
return res.padEnd(padLength);
144144
} else {
@@ -220,7 +220,7 @@ export function getCellRenderer(crArgs: CellRendererArgs) {
220220
}
221221

222222
export function getFormatterFromArgs(dispArgs: DisplayerArgs) {
223-
if (_.includes(cellRendererDisplayers, dispArgs.displayer)) {
223+
if (includes(cellRendererDisplayers, dispArgs.displayer)) {
224224
return undefined;
225225
}
226226
const fArgs = dispArgs as FormatterArgs;

packages/buckaroo-js-core/src/components/DFViewerParts/HistogramCell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as _ from "lodash-es";
1+
import { isArray } from "lodash-es";
22
import React from "react";
33
import { createPortal } from "react-dom";
44

@@ -91,7 +91,7 @@ export const HistogramCell = (props:
9191
const potentialHistogramArr = props.value;
9292
//for key "index", the value is "histogram"
9393
// this causes ReChart to blow up, so we check to see if it's an array
94-
if (potentialHistogramArr === undefined || !_.isArray(potentialHistogramArr)) {
94+
if (potentialHistogramArr === undefined || !isArray(potentialHistogramArr)) {
9595
return <span></span>;
9696
}
9797
const histogramArr = potentialHistogramArr as HistogramBar[];

packages/buckaroo-js-core/src/components/DFViewerParts/OtherRenderers.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as _ from "lodash-es";
21
import { ValueFormatterFunc } from "@ag-grid-community/core";
32

43
export const getTextCellRenderer = (formatter: ValueFormatterFunc<any>) => {

packages/buckaroo-js-core/src/components/DFViewerParts/SmartRowCache.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as _ from "lodash-es";
21
//import { describe, expect } from 'jest';
32
import {
43
Segment,

0 commit comments

Comments
 (0)