Lodash upgrade (#2885)

* upgraded lodash, changed method names
* native implementations as requested
This commit is contained in:
Joel McKinnon 2020-04-23 10:38:44 -07:00 committed by GitHub
parent 04a60cfcbb
commit d103a22fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 39 additions and 24 deletions

View File

@ -8,9 +8,11 @@ module.exports = {
"globals": {
"_": "readonly"
},
"plugins": ["lodash"],
"extends": [
"eslint:recommended",
"plugin:vue/recommended"
"plugin:vue/recommended",
"plugin:lodash/recommended"
],
"parser": "vue-eslint-parser",
"parserOptions": {
@ -22,6 +24,16 @@ module.exports = {
}
},
"rules": {
"lodash/prefer-lodash-method": "off",
"lodash/prefer-lodash-typecheck": "off",
"lodash/prefer-constant": "off",
"lodash/prefer-noop": "off",
"lodash/prefer-matches": "off",
"lodash/prefer-includes": "off",
"lodash/prefer-startswith": "off",
"lodash/prefer-get": "off",
"lodash/prefer-is-nil": "off",
"lodash/import-scope": "off",
"no-bitwise": "error",
"curly": "error",
"eqeqeq": "error",

View File

@ -23,6 +23,7 @@
"d3-time": "1.0.x",
"d3-time-format": "2.1.x",
"eslint": "5.2.0",
"eslint-plugin-lodash": "^6.0.0",
"eslint-plugin-vue": "^6.0.0",
"eventemitter3": "^1.2.0",
"exports-loader": "^0.7.0",
@ -47,7 +48,7 @@
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.0",
"location-bar": "^3.0.1",
"lodash": "^3.10.1",
"lodash": "^4.17.12",
"markdown-toc": "^0.11.7",
"marked": "^0.3.5",
"mini-css-extract-plugin": "^0.4.1",

View File

@ -25,8 +25,7 @@
*/
define(
[
'../../../src/api/objects/object-utils',
'lodash'
'../../../src/api/objects/object-utils'
],
function (
objectUtils,
@ -235,7 +234,8 @@ define(
var defaultRange = metadata.valuesForHints(['range'])[0];
defaultRange = defaultRange ? defaultRange.key : undefined;
var sourceMap = _.indexBy(metadata.values(), 'key');
const keyBy = (array, k) => (array || []).reduce((r, x) => ({ ...r, [k ? x[k] : x]: x }), {});
var sourceMap = keyBy(metadata.values(), 'key');
var isLegacyProvider = telemetryAPI.findRequestProvider(domainObject) ===
telemetryAPI.legacyProvider;
@ -300,7 +300,8 @@ define(
var defaultRange = metadata.valuesForHints(['range'])[0];
defaultRange = defaultRange ? defaultRange.key : undefined;
var sourceMap = _.indexBy(metadata.values(), 'key');
const keyBy = (array, k) => (array || []).reduce((r, x) => ({ ...r, [k ? x[k] : x]: x }), {});
var sourceMap = keyBy(metadata.values(), 'key');
var isLegacyProvider = telemetryAPI.findSubscriptionProvider(domainObject) ===
telemetryAPI.legacyProvider;

View File

@ -196,8 +196,8 @@ define([
* @private
*/
DefaultCompositionProvider.prototype.includes = function (parent, childId) {
return parent.composition.findIndex(composee =>
this.publicAPI.objects.areIdsEqual(composee, childId)) !== -1;
return parent.composition.some(composee =>
this.publicAPI.objects.areIdsEqual(composee, childId));
};
DefaultCompositionProvider.prototype.reorder = function (domainObject, oldIndex, newIndex) {

View File

@ -85,9 +85,9 @@ define([
value: +e.value
};
}), 'e.value');
valueMetadata.values = _.pluck(valueMetadata.enumerations, 'value');
valueMetadata.max = _.max(valueMetadata.values);
valueMetadata.min = _.min(valueMetadata.values);
valueMetadata.values = Object.entries(valueMetadata.enumerations).reduce((a, [key, {value}]) => {a [key] = value; return a}, []);
valueMetadata.max = Math.max(...valueMetadata.values);
valueMetadata.min = Math.min(...valueMetadata.values);
}
valueMetadatas.push(valueMetadata);

View File

@ -370,7 +370,7 @@ define([
TelemetryAPI.prototype.commonValuesForHints = function (metadatas, hints) {
var options = metadatas.map(function (metadata) {
var values = metadata.valuesForHints(hints);
return _.indexBy(values, 'key');
return _.keyBy(values, 'key');
}).reduce(function (a, b) {
var results = {};
Object.keys(a).forEach(function (key) {
@ -383,7 +383,7 @@ define([
var sortKeys = hints.map(function (h) {
return 'hints.' + h;
});
return _.sortByAll(options, sortKeys);
return _.sortBy(options, sortKeys);
};
/**

View File

@ -57,13 +57,13 @@ define([
if (valueMetadata.format === 'enum') {
if (!valueMetadata.values) {
valueMetadata.values = _.pluck(valueMetadata.enumerations, 'value');
valueMetadata.values = Object.entries(valueMetadata.enumerations).reduce((a, [key, {value}]) => {a [key] = value; return a}, []);
}
if (!valueMetadata.hasOwnProperty('max')) {
valueMetadata.max = _.max(valueMetadata.values) + 1;
valueMetadata.max = Math.max(...valueMetadata.values) + 1;
}
if (!valueMetadata.hasOwnProperty('min')) {
valueMetadata.min = _.min(valueMetadata.values) - 1;
valueMetadata.min = Math.min(...valueMetadata.values) - 1;
}
}
@ -121,7 +121,7 @@ define([
return metadata.hints[hint];
}
});
return _.sortByAll(matchingMetadata, ...iteratees);
return _.sortBy(matchingMetadata, ...iteratees);
};
TelemetryMetadataManager.prototype.getFilterableValues = function () {

View File

@ -220,7 +220,7 @@ export default {
return;
}
const index = _.sortedIndex(this.imageHistory, datum, this.timeFormat.format.bind(this.timeFormat));
const index = _.sortedIndexBy(this.imageHistory, datum, this.timeFormat.format.bind(this.timeFormat));
this.imageHistory.splice(index, 0, datum);
},
updateValues(datum) {

View File

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

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)));
}
}
@ -131,6 +131,7 @@ define([
}
tickWidthMap[plotId] = Math.max(width, tickWidthMap[plotId]);
var newTickWidth = _.max(tickWidthMap);
if (newTickWidth !== tickWidth || width !== tickWidth) {
tickWidth = newTickWidth;
$scope.$broadcast('plot:tickWidth', tickWidth);

View File

@ -154,7 +154,7 @@ define([
return _(this.baseState)
.values()
.map(_.clone)
.indexBy('id')
.keyBy('id')
.value();
}.bind(this));
};

View File

@ -100,7 +100,7 @@ define([
hasColumnWithKey(columnKey) {
return _.flatten(Object.values(this.columns))
.findIndex(column => column.getKey() === columnKey) !== -1;
.some(column => column.getKey() === columnKey);
}
getColumns() {

View File

@ -93,7 +93,7 @@ define(
// same time stamp
let potentialDupes = this.rows.slice(startIx, endIx + 1);
// Search potential dupes for exact dupe
isDuplicate = _.findIndex(potentialDupes, _.isEqual.bind(undefined, row)) > -1;
isDuplicate = potentialDupes.some(_.isEqual.bind(undefined, row));
}
if (!isDuplicate) {
@ -201,7 +201,7 @@ define(
sortBy(sortOptions) {
if (arguments.length > 0) {
this.sortOptions = sortOptions;
this.rows = _.sortByOrder(this.rows, (row) => row.getParsedValue(sortOptions.key) , sortOptions.direction);
this.rows = _.orderBy(this.rows, (row) => row.getParsedValue(sortOptions.key) , sortOptions.direction);
this.emit('sort');
}
// Return duplicate to avoid direct modification of underlying object