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