Skip to content

Commit

Permalink
feat: remove lodash (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen authored Oct 19, 2021
1 parent e803b22 commit 5594170
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .size-limit
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
{
"path": "dist/index.js",
"limit": "9.5 KB",
"limit": "1.5 KB",
"import": "Chart"
},
{
Expand All @@ -18,7 +18,7 @@
},
{
"path": "dist/index.modern.js",
"limit": "9.5 KB",
"limit": "1.5 KB",
"import": "Chart"
}
]
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
"release": "standard-version",
"cleanPublish": "yarn test && clean-publish"
},
"dependencies": {
"lodash": "^4.17.19"
},
"dependencies": {},
"peerDependencies": {
"chart.js": "^3.5.0",
"react": "^16.8.0 || ^17.0.0"
Expand Down
17 changes: 8 additions & 9 deletions src/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import React, {
import type { Ref, MouseEvent } from 'react';
import ChartJS from 'chart.js/auto';
import type { ChartData, ChartType, DefaultDataPoint } from 'chart.js';
import merge from 'lodash/merge';
import assign from 'lodash/assign';
import find from 'lodash/find';

import { Props, ChartJSOrUndefined, TypedChartComponent } from './types';

Expand Down Expand Up @@ -49,7 +46,7 @@ function ChartComponent<
: {
datasets: [],
};
} else return merge({}, data);
} else return data;
}, [data, canvas.current]);

const [chart, setChart] = useState<TypedChartJS>();
Expand Down Expand Up @@ -125,12 +122,11 @@ function ChartComponent<
const { datasets: currentDataSets = [] } = chart.config.data;

// copy values
assign(chart.config.data, newChartData);
Object.assign(chart.config.data, newChartData);

chart.config.data.datasets = newDataSets.map((newDataSet: any) => {
// given the new set, find it's current match
const currentDataSet = find(
currentDataSets,
const currentDataSet = currentDataSets.find(
d => d.label === newDataSet.label && d.type === newDataSet.type
);

Expand All @@ -146,10 +142,13 @@ function ChartComponent<
}

// copy in values
assign(currentDataSet.data, newDataSet.data);
Object.assign(currentDataSet.data, newDataSet.data);

// apply dataset changes, but keep copied data
assign(currentDataSet, { ...newDataSet, data: currentDataSet.data });
Object.assign(currentDataSet, {
...newDataSet,
data: currentDataSet.data,
});
return currentDataSet;
});

Expand Down

0 comments on commit 5594170

Please sign in to comment.