variableBuilder.ts 636 B

12345678910111213141516171819202122232425262728293031
  1. import { cloneDeep } from 'lodash';
  2. import { VariableModel } from 'app/features/variables/types';
  3. export class VariableBuilder<T extends VariableModel> {
  4. protected variable: T;
  5. constructor(initialState: T) {
  6. const { id, index, global, ...rest } = initialState;
  7. this.variable = cloneDeep({ ...rest, name: rest.type }) as T;
  8. }
  9. withName(name: string) {
  10. this.variable.name = name;
  11. return this;
  12. }
  13. withId(id: string) {
  14. this.variable.id = id;
  15. return this;
  16. }
  17. withRootStateKey(key: string) {
  18. this.variable.rootStateKey = key;
  19. return this;
  20. }
  21. build(): T {
  22. return this.variable;
  23. }
  24. }