37 lines
970 B
TypeScript
37 lines
970 B
TypeScript
import type RootStore from '../../root';
|
|
import type { CalculationValues, Values } from './types';
|
|
import defaultValues from '@/config/default-values';
|
|
import { makeAutoObservable } from 'mobx';
|
|
|
|
export default class ValuesStore {
|
|
private root: RootStore;
|
|
public values: CalculationValues = defaultValues;
|
|
|
|
constructor(rootStore: RootStore) {
|
|
makeAutoObservable(this);
|
|
this.root = rootStore;
|
|
}
|
|
|
|
public hydrate = (initialValues: CalculationValues) => {
|
|
this.values = initialValues;
|
|
};
|
|
|
|
public setValues = (params: { values: CalculationValues }) => {
|
|
const { values } = params;
|
|
|
|
this.values = values;
|
|
};
|
|
|
|
public getValue<V extends Values>(valueName: V) {
|
|
return this.values[valueName];
|
|
}
|
|
|
|
public setValue = <V extends Values>(valueName: V, value: CalculationValues[V]) => {
|
|
this.values[valueName] = value;
|
|
};
|
|
|
|
public resetValue = (valueName: Values) => {
|
|
this.setValue(valueName, defaultValues[valueName]);
|
|
};
|
|
}
|