Lodash upgrade and cleanup (#2990)

* Upgrades lodash
* Replaces some usage of lodash with native functions.
* Adds linting to catch cases where native functions could be used instead of lodash functions
* Renamed testTools to testUtils

Co-authored-by: Joshi <simplyrender@gmail.com>
Co-authored-by: David Tsay <david.e.tsay@nasa.gov>
Co-authored-by: David Tsay <3614296+davetsay@users.noreply.github.com>
Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
Joel McKinnon
2020-05-27 10:59:02 -07:00
committed by GitHub
parent 67bea86bc8
commit 43628ad9d6
75 changed files with 131 additions and 108 deletions

View File

@ -152,7 +152,7 @@ function (
MCTChartController.prototype.destroy = function () {
this.isDestroyed = true;
this.stopListening();
_.invoke(this.lines, 'destroy');
this.lines.forEach(line => line.destroy());
DrawLoader.releaseDrawAPI(this.drawAPI);
};

View File

@ -44,7 +44,7 @@ define([
this.initialize(options);
}
_.extend(Collection.prototype, EventEmitter.prototype);
Object.assign(Collection.prototype, EventEmitter.prototype);
eventHelpers.extend(Collection.prototype);
Collection.extend = extend;
@ -105,12 +105,7 @@ define([
};
Collection.prototype.indexOf = function (model) {
return _.findIndex(
this.models,
function (m) {
return m === model;
}
);
return this.models.findIndex(m => m === model);
};
Collection.prototype.remove = function (model) {

View File

@ -49,7 +49,7 @@ define([
this.initialize(options);
}
_.extend(Model.prototype, EventEmitter.prototype);
Object.assign(Model.prototype, EventEmitter.prototype);
eventHelpers.extend(Model.prototype);
Model.extend = extend;

View File

@ -146,7 +146,7 @@ define([
strategy = 'minmax';
}
options = _.extend({}, { size: 1000, strategy, filters: this.filters }, options || {});
options = Object.assign({}, { size: 1000, strategy, filters: this.filters }, options || {});
if (!this.unsubscribe) {
this.unsubscribe = this.openmct
@ -160,6 +160,7 @@ define([
);
}
/* eslint-disable you-dont-need-lodash-underscore/concat */
return this.openmct
.telemetry
.request(this.domainObject, options)
@ -171,6 +172,7 @@ define([
.value();
this.reset(newPoints);
}.bind(this));
/* eslint-enable you-dont-need-lodash-underscore/concat */
},
/**
* Update x formatter on x change.
@ -270,7 +272,7 @@ define([
* @private
*/
sortedIndex: function (point) {
return _.sortedIndex(this.data, point, this.getXVal);
return _.sortedIndexBy(this.data, point, this.getXVal);
},
/**
* Update min/max stats for the series.

View File

@ -101,11 +101,11 @@ define([
var plotObject = this.plot.get('domainObject');
if (plotObject.type === 'telemetry.plot.overlay') {
var persistedIndex = _.findIndex(plotObject.configuration.series, function (s) {
var persistedIndex = plotObject.configuration.series.findIndex(s => {
return _.isEqual(identifier, s.identifier);
});
var configIndex = _.findIndex(this.models, function (m) {
var configIndex = this.models.findIndex(m => {
return _.isEqual(m.domainObject.identifier, identifier);
});

View File

@ -51,7 +51,7 @@ define([
}
}
_.extend(Draw2D.prototype, EventEmitter.prototype);
Object.assign(Draw2D.prototype, EventEmitter.prototype);
eventHelpers.extend(Draw2D.prototype);
// Convert from logical to physical x coordinates

View File

@ -78,7 +78,7 @@ define([
this.listenTo(this.canvas, "webglcontextlost", this.onContextLost, this);
}
_.extend(DrawWebGL.prototype, EventEmitter.prototype);
Object.assign(DrawWebGL.prototype, EventEmitter.prototype);
eventHelpers.extend(DrawWebGL.prototype);
DrawWebGL.prototype.onContextLost = function (event) {

View File

@ -23,7 +23,7 @@
define([
'../configuration/configStore',
'../lib/eventHelpers',
'../../../../api/objects/object-utils',
'objectUtils',
'lodash'
], function (
configStore,

View File

@ -31,7 +31,7 @@ define([
function dynamicPathForKey(key) {
return function (object, model) {
var modelIdentifier = model.get('identifier');
var index = _.findIndex(object.configuration.series, function (s) {
var index = object.configuration.series.findIndex(s => {
return _.isEqual(s.identifier, modelIdentifier);
});
return 'configuration.series[' + index + '].' + key;

View File

@ -73,10 +73,10 @@ define([
if (range.max === '' || range.max === null || typeof range.max === 'undefined') {
return 'Must specify Maximum';
}
if (_.isNaN(Number(range.min))) {
if (Number.isNaN(Number(range.min))) {
return 'Minimum must be a number.';
}
if (_.isNaN(Number(range.max))) {
if (Number.isNaN(Number(range.max))) {
return 'Maximum must be a number.';
}
if (Number(range.min) > Number(range.max)) {

View File

@ -76,7 +76,7 @@ define([
if (childObj) {
var index = telemetryObjects.indexOf(childObj);
telemetryObjects.splice(index, 1);
$scope.$broadcast('plot:tickWidth', _.max(tickWidthMap));
$scope.$broadcast('plot:tickWidth', Math.max(...Object.values(tickWidthMap)));
}
}