2021-04-21 08:38:00 +01:00
|
|
|
import { cloneDeep } from 'lodash';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2020-06-04 13:44:48 +02:00
|
|
|
import { VariableModel } from 'app/features/variables/types';
|
2020-03-23 09:00:36 +01:00
|
|
|
|
|
|
|
|
export class VariableBuilder<T extends VariableModel> {
|
|
|
|
|
protected variable: T;
|
|
|
|
|
|
|
|
|
|
constructor(initialState: T) {
|
2020-03-23 13:45:08 +01:00
|
|
|
const { id, index, global, ...rest } = initialState;
|
2020-03-23 09:00:36 +01:00
|
|
|
this.variable = cloneDeep({ ...rest, name: rest.type }) as T;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
withName(name: string) {
|
|
|
|
|
this.variable.name = name;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 13:45:08 +01:00
|
|
|
withId(id: string) {
|
|
|
|
|
this.variable.id = id;
|
2020-03-23 09:00:36 +01:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-18 06:06:04 +01:00
|
|
|
withRootStateKey(key: string) {
|
|
|
|
|
this.variable.rootStateKey = key;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 09:00:36 +01:00
|
|
|
build(): T {
|
|
|
|
|
return this.variable;
|
|
|
|
|
}
|
|
|
|
|
}
|