Performance: Standardize lodash imports to use destructured members (#33040)

* Performance: Standardize lodash imports to use destructured members
Changes lodash imports of the form `import x from 'lodash/x'` to
`import { x } from 'lodash'` to reduce bundle size.

* Remove unnecessary _ import from Graph component

* Enforce lodash import style

* Fix remaining lodash imports
This commit is contained in:
kay delaney
2021-04-21 08:38:00 +01:00
committed by GitHub
parent 2bb7eb18d1
commit bad048b7ba
299 changed files with 1135 additions and 1137 deletions

View File

@@ -1,4 +1,4 @@
import _ from 'lodash';
import { clone, each, map } from 'lodash';
export class QueryPartDef {
type: string;
@@ -31,7 +31,7 @@ export class QueryPart {
throw { message: 'Could not find query part ' + part.type };
}
part.params = part.params || _.clone(this.def.defaultParams);
part.params = part.params || clone(this.def.defaultParams);
this.params = part.params;
this.text = '';
this.updateText();
@@ -53,7 +53,7 @@ export class QueryPart {
// handle optional parameters
// if string contains ',' and next param is optional, split and update both
if (this.hasMultipleParamsInString(strValue, index)) {
_.each(strValue.split(','), (partVal, idx) => {
each(strValue.split(','), (partVal, idx) => {
this.updateParam(partVal.trim(), idx);
});
return;
@@ -84,7 +84,7 @@ export class QueryPart {
export function functionRenderer(part: any, innerExpr: string) {
const str = part.def.type + '(';
const parameters = _.map(part.params, (value, index) => {
const parameters = map(part.params, (value, index) => {
const paramType = part.def.params[index];
if (paramType.type === 'time') {
if (value === 'auto') {

View File

@@ -1,4 +1,4 @@
import _ from 'lodash';
import { debounce, each, map, partial, escape, unescape } from 'lodash';
import $ from 'jquery';
import coreModule from 'app/core/core_module';
import { promiseToDigest } from '../../utils/promiseToDigest';
@@ -90,7 +90,7 @@ export function queryPartEditorDirective(templateSrv: any) {
if (param.options) {
let options = param.options;
if (param.type === 'int') {
options = _.map(options, (val) => {
options = map(options, (val) => {
return val.toString();
});
}
@@ -99,8 +99,8 @@ export function queryPartEditorDirective(templateSrv: any) {
$scope.$apply(() => {
$scope.handleEvent({ $event: { name: 'get-param-options' } }).then((result: any) => {
const dynamicOptions = _.map(result, (op) => {
return _.escape(op.value);
const dynamicOptions = map(result, (op) => {
return escape(op.value);
});
callback(dynamicOptions);
});
@@ -114,7 +114,7 @@ export function queryPartEditorDirective(templateSrv: any) {
minLength: 0,
items: 1000,
updater: (value: string) => {
value = _.unescape(value);
value = unescape(value);
setTimeout(() => {
inputBlur.call($input[0], paramIndex);
}, 0);
@@ -130,7 +130,7 @@ export function queryPartEditorDirective(templateSrv: any) {
};
if (debounceLookup) {
typeahead.lookup = _.debounce(typeahead.lookup, 500, { leading: true });
typeahead.lookup = debounce(typeahead.lookup, 500, { leading: true });
}
}
@@ -147,7 +147,7 @@ export function queryPartEditorDirective(templateSrv: any) {
};
function addElementsAndCompile() {
_.each(partDef.params, (param: any, index: number) => {
each(partDef.params, (param: any, index: number) => {
if (param.optional && part.params.length <= index) {
return;
}
@@ -163,10 +163,10 @@ export function queryPartEditorDirective(templateSrv: any) {
$paramLink.appendTo($paramsContainer);
$input.appendTo($paramsContainer);
$input.blur(_.partial(inputBlur, index));
$input.blur(partial(inputBlur, index));
$input.keyup(inputKeyDown);
$input.keypress(_.partial(inputKeyPress, index));
$paramLink.click(_.partial(clickFuncParam, index));
$input.keypress(partial(inputKeyPress, index));
$paramLink.click(partial(clickFuncParam, index));
addTypeahead($input, param, index);
});