mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 04:41:50 +08:00

* 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
26 lines
541 B
TypeScript
26 lines
541 B
TypeScript
import { cloneDeep } from 'lodash';
|
|
import { VariableModel } from 'app/features/variables/types';
|
|
|
|
export class VariableBuilder<T extends VariableModel> {
|
|
protected variable: T;
|
|
|
|
constructor(initialState: T) {
|
|
const { id, index, global, ...rest } = initialState;
|
|
this.variable = cloneDeep({ ...rest, name: rest.type }) as T;
|
|
}
|
|
|
|
withName(name: string) {
|
|
this.variable.name = name;
|
|
return this;
|
|
}
|
|
|
|
withId(id: string) {
|
|
this.variable.id = id;
|
|
return this;
|
|
}
|
|
|
|
build(): T {
|
|
return this.variable;
|
|
}
|
|
}
|