Skip to content

Commit 7910017

Browse files
sleepylemurjerairrest
authored andcommitted
use lodash.find instead of MDN polyfill (#169)
Nicee!!!!!!! Thanks so much!
1 parent e37ea56 commit 7910017

File tree

3 files changed

+8
-49
lines changed

3 files changed

+8
-49
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"url": "https://github.com/jerairrest/react-chartjs-2/issues"
1414
},
1515
"dependencies": {
16+
"lodash.find": "^4.6.0",
1617
"lodash.isequal": "^4.4.0",
1718
"prop-types": "^15.5.8"
1819
},

src/index.js

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import Chart from 'chart.js';
44
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';
516

527

538
class 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);

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5008,6 +5008,10 @@ lodash.filter@^4.4.0:
50085008
version "4.6.0"
50095009
resolved "https://registry.yarnpkg.com/lodash.filter/-/lodash.filter-4.6.0.tgz#668b1d4981603ae1cc5a6fa760143e480b4c4ace"
50105010

5011+
lodash.find@^4.6.0:
5012+
version "4.6.0"
5013+
resolved "https://registry.yarnpkg.com/lodash.find/-/lodash.find-4.6.0.tgz#cb0704d47ab71789ffa0de8b97dd926fb88b13b1"
5014+
50115015
lodash.flatten@^4.2.0:
50125016
version "4.4.0"
50135017
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"

0 commit comments

Comments
 (0)