Skip to content

Commit 93d4e9e

Browse files
committed
Replace lodash.isEqual checks with Object.is
1 parent 044f4a1 commit 93d4e9e

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

packages/react-jsx-highcharts/src/components/BaseChart/BaseChart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect, useRef, useLayoutEffect } from 'react';
22
import PropTypes from 'prop-types';
33
import debounce from '../../utils/debounce-raf';
4-
import { isEqual, attempt } from 'lodash-es'
4+
import { attempt } from 'lodash-es'
55
import ChartContext from '../ChartContext';
66
import { validChartTypes } from '../../utils/propTypeValidators'
77
import usePrevious from '../UsePrevious';
@@ -62,7 +62,7 @@ const BaseChart = ({ children = null, callback, className = '', ...restProps}) =
6262
const { plotOptions } = restProps;
6363
const myChart = chartRef.current;
6464
const needsRedraw = providerValueRef.current.needsRedraw;
65-
if (isEqual(prevProps.plotOptions, plotOptions) === false && myChart) {
65+
if (Object.is(prevProps.plotOptions, plotOptions) === false && myChart) {
6666
myChart.update({ plotOptions }, false);
6767
needsRedraw();
6868
}

packages/react-jsx-highcharts/src/components/Series/Series.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { memo, useRef, useState, useEffect } from 'react';
22
import PropTypes from 'prop-types';
33
import uuid from 'uuid/v4';
4-
import { isEqual } from 'lodash-es';
54
import { attempt } from 'lodash-es';
65
import SeriesContext from '../SeriesContext';
76
import { getNonEventHandlerProps, getEventsConfig } from '../../utils/events';
@@ -78,7 +77,7 @@ const Series = memo(({
7877

7978
let doRedraw = false;
8079
// Using setData is more performant than update
81-
if (isEqual(data, prevProps.data) === false) {
80+
if (Object.is(data, prevProps.data) === false) {
8281
series.setData(data, false);
8382
doRedraw = true;
8483
}

packages/react-jsx-highcharts/src/utils/getModifiedProps.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isEqual } from 'lodash-es';
21
import { pickBy } from 'lodash-es';
32

43
export default function getModifiedProps (prevProps, currProps, childrenIsText = false) {
@@ -7,10 +6,10 @@ export default function getModifiedProps (prevProps, currProps, childrenIsText =
76
const modifiedProps = pickBy(rest, (value, propName) => {
87
if (!prevProps) return true;
98

10-
return isEqual(value, prevProps[propName]) === false;
9+
return Object.is(value, prevProps[propName]) === false;
1110
});
1211

13-
if (childrenIsText && (!prevProps || isEqual(prevProps.children, children) === false)) {
12+
if (childrenIsText && (!prevProps || Object.is(prevProps.children, children) === false)) {
1413
modifiedProps.text = children;
1514
}
1615

packages/react-jsx-highcharts/test/components/Series/Series.spec.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,36 @@ describe('<Series />', () => {
149149
expect(testContext.needsRedraw).toHaveBeenCalledTimes(1);
150150
});
151151

152-
it('should NOT use the setData method if the data hasn\'t changed', () => {
152+
it('should NOT use the setData method if the data reference hasn\'t changed', () => {
153+
const data = [1, 2, 3];
153154
const wrapper = mount(
154155
<ProvidedSeries
155-
id="mySeries" data={[1, 2, 3]} />
156+
id="mySeries" data={data} />
156157
);
157-
testContext.seriesStubs.update.mockReset();
158+
testContext.seriesStubs.update.mockClear();
158159
testContext.needsRedraw.mockClear();
159-
wrapper.setProps({ data: [1, 2, 3] });
160+
testContext.seriesStubs.setData.mockClear();
161+
wrapper.setProps({ data });
160162
expect(testContext.seriesStubs.setData).not.toHaveBeenCalled();
161163
expect(testContext.seriesStubs.update).not.toHaveBeenCalled();
162164
expect(testContext.seriesStubs.setVisible).not.toHaveBeenCalled();
163165
expect(testContext.needsRedraw).not.toHaveBeenCalled();
164166
});
165167

168+
it('should use the setData method if the data reference has changed', () => {
169+
const wrapper = mount(
170+
<ProvidedSeries
171+
id="mySeries" data={[1, 2, 3]} />
172+
);
173+
testContext.seriesStubs.update.mockClear();
174+
testContext.needsRedraw.mockClear();
175+
wrapper.setProps({ data: [1, 2, 3] });
176+
expect(testContext.seriesStubs.setData).toHaveBeenCalled();
177+
expect(testContext.seriesStubs.update).not.toHaveBeenCalled();
178+
expect(testContext.seriesStubs.setVisible).not.toHaveBeenCalled();
179+
expect(testContext.needsRedraw).toHaveBeenCalled();
180+
});
181+
166182
it('should use the setVisible method on the correct series when the visibility changes', () => {
167183
const wrapper = mount(
168184
<ProvidedSeries

0 commit comments

Comments
 (0)