@@ -2,52 +2,7 @@ import React from 'react';
2
2
import PropTypes from 'prop-types' ;
3
3
import Chart from 'chart.js' ;
4
4
import 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' ;
51
6
52
7
53
8
class ChartComponent extends React . Component {
@@ -68,8 +23,7 @@ class ChartComponent extends React.Component {
68
23
plugins : PropTypes . arrayOf ( PropTypes . object ) ,
69
24
redraw : PropTypes . bool ,
70
25
type : function ( props , propName , componentName ) {
71
-
72
- if ( ! Object . keys ( Chart . controllers ) . find ( ( chartType ) => chartType === props [ propName ] ) ) {
26
+ if ( ! Chart . controllers [ props [ propName ] ] ) {
73
27
return new Error (
74
28
'Invalid chart type `' + props [ propName ] + '` supplied to' +
75
29
' `' + componentName + '`.'
@@ -218,7 +172,7 @@ class ChartComponent extends React.Component {
218
172
// deleted series
219
173
currentDatasets . splice ( idx , 1 ) ;
220
174
} else {
221
- const retainedDataset = nextDatasets . find ( d => this . props . datasetKeyProvider ( d ) === currentDatasetKey ) ;
175
+ const retainedDataset = find ( nextDatasets , d => this . props . datasetKeyProvider ( d ) === currentDatasetKey ) ;
222
176
if ( retainedDataset ) {
223
177
// update it in place if it is a retained dataset
224
178
currentDatasets [ idx ] . data . splice ( retainedDataset . data . length ) ;
0 commit comments