@@ -2,52 +2,7 @@ import React from 'react';
22import PropTypes from 'prop-types' ;
33import Chart from 'chart.js' ;
44import isEqual from 'lodash.isequal' ;
5-
6-
7- //Taken from MDN
8- if ( ! Array . prototype . find ) {
9- Object . defineProperty ( Array . prototype , 'find' , {
10- value : function ( predicate ) {
11- // 1. Let O be ? ToObject(this value).
12- if ( this == null ) {
13- throw new TypeError ( '"this" is null or not defined' ) ;
14- }
15-
16- var o = Object ( this ) ;
17-
18- // 2. Let len be ? ToLength(? Get(O, "length")).
19- var len = o . length >>> 0 ;
20-
21- // 3. If IsCallable(predicate) is false, throw a TypeError exception.
22- if ( typeof predicate !== 'function' ) {
23- throw new TypeError ( 'predicate must be a function' ) ;
24- }
25-
26- // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
27- var thisArg = arguments [ 1 ] ;
28-
29- // 5. Let k be 0.
30- var k = 0 ;
31-
32- // 6. Repeat, while k < len
33- while ( k < len ) {
34- // a. Let Pk be ! ToString(k).
35- // b. Let kValue be ? Get(O, Pk).
36- // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
37- // d. If testResult is true, return kValue.
38- var kValue = o [ k ] ;
39- if ( predicate . call ( thisArg , kValue , k , o ) ) {
40- return kValue ;
41- }
42- // e. Increase k by 1.
43- k ++ ;
44- }
45-
46- // 7. Return undefined.
47- return undefined ;
48- }
49- } ) ;
50- }
5+ import find from 'lodash.find' ;
516
527
538class ChartComponent extends React . Component {
@@ -68,8 +23,7 @@ class ChartComponent extends React.Component {
6823 plugins : PropTypes . arrayOf ( PropTypes . object ) ,
6924 redraw : PropTypes . bool ,
7025 type : function ( props , propName , componentName ) {
71-
72- if ( ! Object . keys ( Chart . controllers ) . find ( ( chartType ) => chartType === props [ propName ] ) ) {
26+ if ( ! Chart . controllers [ props [ propName ] ] ) {
7327 return new Error (
7428 'Invalid chart type `' + props [ propName ] + '` supplied to' +
7529 ' `' + componentName + '`.'
@@ -218,7 +172,7 @@ class ChartComponent extends React.Component {
218172 // deleted series
219173 currentDatasets . splice ( idx , 1 ) ;
220174 } else {
221- const retainedDataset = nextDatasets . find ( d => this . props . datasetKeyProvider ( d ) === currentDatasetKey ) ;
175+ const retainedDataset = find ( nextDatasets , d => this . props . datasetKeyProvider ( d ) === currentDatasetKey ) ;
222176 if ( retainedDataset ) {
223177 // update it in place if it is a retained dataset
224178 currentDatasets [ idx ] . data . splice ( retainedDataset . data . length ) ;
0 commit comments