From 80f17196504590cfb1d69405810c45260cba5ba4 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 25 May 2018 19:20:42 -0400 Subject: [PATCH 1/2] Fixed shouldComponentUpdate Ensure the function always returns true or false --- src/chart.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/chart.js b/src/chart.js index 4b32600..a46f076 100644 --- a/src/chart.js +++ b/src/chart.js @@ -131,11 +131,14 @@ export default class Chart extends React.Component { width != nextProps.width || !isEqual(options, nextProps.options) || !isEqual(plugins, nextProps.plugins)) { + var chart = this.state.chart if (nextProps.redraw) { chart.destroy() this.initializeChart(nextProps) - } else { + return true + } + else { var dataKey = nextProps.dataKey || dataKeys[chart.config.type] updatePoints(nextProps, chart, dataKey) if (chart.scales) { @@ -145,6 +148,7 @@ export default class Chart extends React.Component { return false } } + return false } handleOnClick = (event) => { From 2954262f4cfcc502601424333dc2b3f8f5a41590 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 26 May 2018 11:20:52 -0400 Subject: [PATCH 2/2] Resolved React's lint warnings --- src/chart.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/chart.js b/src/chart.js index a46f076..31af1a5 100644 --- a/src/chart.js +++ b/src/chart.js @@ -12,7 +12,6 @@ const dataKeys = { var updatePoints = function(nextProps, chart, dataKey) { var name = chart.config.type - var nextProps = nextProps if (name === 'polarArea' || name === 'pie' || name === 'doughnut') { nextProps.data.datasets.forEach(function(segment, segmentIndex) { @@ -35,7 +34,7 @@ var updatePoints = function(nextProps, chart, dataKey) { removeData(chart) nextProps.data.datasets.forEach(function(set, setIndex) { set.data.forEach(function(val, pointIndex) { - if (typeof(chart.data.datasets[setIndex][dataKey][pointIndex]) == "undefined") { + if (typeof(chart.data.datasets[setIndex][dataKey][pointIndex]) === 'undefined') { addData(nextProps, chart, setIndex) } else { chart.data.datasets[setIndex][dataKey][pointIndex] = val @@ -47,7 +46,7 @@ var updatePoints = function(nextProps, chart, dataKey) { chart.data.datasets.pop() } nextProps.data.datasets.forEach(function(set, setIndex) { - if (typeof(chart.data.datasets[setIndex]) == "undefined") { + if (typeof(chart.data.datasets[setIndex]) === 'undefined') { chart.data.datasets.push(nextProps.data.datasets[setIndex]) } else { chart.data.datasets[setIndex][dataKey] = set.data @@ -58,7 +57,7 @@ var updatePoints = function(nextProps, chart, dataKey) { chart.data.datasets.pop() } nextProps.data.datasets.forEach(function(set, setIndex){ - if (typeof(chart.data.datasets[setIndex]) == "undefined") { + if (typeof(chart.data.datasets[setIndex]) === 'undefined') { chart.data.datasets.push(nextProps.data.datasets[setIndex]) } else { chart.data.datasets[setIndex] = nextProps.data.datasets[setIndex] @@ -71,7 +70,7 @@ var updatePoints = function(nextProps, chart, dataKey) { } nextProps.data.datasets.forEach(function(set, setIndex) { set.data.forEach(function(val, pointIndex) { - if (typeof(chart.data.datasets[setIndex][dataKey][pointIndex]) == "undefined") { + if (typeof(chart.data.datasets[setIndex][dataKey][pointIndex]) === 'undefined') { addData(nextProps, chart, setIndex) } else { chart.data.datasets[setIndex][dataKey][pointIndex] = val @@ -125,10 +124,10 @@ export default class Chart extends React.Component { plugins } = this.props if (!isEqual(data.datasets, nextProps.data.datasets) || - nextProps.redraw == true || - type != nextProps.type || - height != nextProps.height || - width != nextProps.width || + nextProps.redraw === true || + type !== nextProps.type || + height !== nextProps.height || + width !== nextProps.width || !isEqual(options, nextProps.options) || !isEqual(plugins, nextProps.plugins)) { @@ -194,5 +193,8 @@ export default class Chart extends React.Component { var ctx = el.getContext("2d") var chart = new Chart(ctx, {type: nextProps.type, data: nextProps.data, options: nextProps.options || {}, plugins: nextProps.plugins || {}}) this.state.chart = chart; + // this.setState({ + // chart: chart + // }) } } \ No newline at end of file