stores: update OptionsStore methods
This commit is contained in:
parent
2d8aeed99e
commit
0e7fe7814a
@ -6,7 +6,6 @@
|
||||
import type { Elements } from 'Components/Calculation/config/map-values';
|
||||
import defaultOptions from 'config/default-options';
|
||||
import type { BaseOption } from 'Elements/types';
|
||||
import { mergeWith } from 'lodash';
|
||||
import { makeAutoObservable } from 'mobx';
|
||||
import type RootStore from 'stores/root';
|
||||
import type { CalculationOptions, Filter, OptionsFilters } from './types';
|
||||
@ -63,14 +62,31 @@ export default class OptionsStore {
|
||||
return filter ? options && filter(options) : options;
|
||||
}
|
||||
|
||||
setOptions = (elementName: Elements, options: BaseOption[]) => {
|
||||
this.options[elementName] = options;
|
||||
resetOptions = (elementsNames: readonly Elements[]) => {
|
||||
elementsNames.forEach((elementName) => {
|
||||
this.setOption(elementName, defaultOptions[elementName]!);
|
||||
});
|
||||
};
|
||||
|
||||
mergeOptions = (options: Partial<CalculationOptions>) => {
|
||||
mergeWith(this.options, options, (objValue, srcValue) =>
|
||||
objValue === undefined ? srcValue : objValue
|
||||
);
|
||||
setOption = (elementName: Elements, option: BaseOption[]) => {
|
||||
this.options[elementName] = option;
|
||||
};
|
||||
|
||||
setOptions = (
|
||||
options: Partial<CalculationOptions>,
|
||||
settings?: { reset: boolean; exclude: Elements[] }
|
||||
) => {
|
||||
if (settings?.reset) {
|
||||
this.resetOptions(
|
||||
(Object.keys(defaultOptions) as Elements[]).filter(
|
||||
(elementName) => !settings?.exclude.includes(elementName)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
(Object.keys(options) as Elements[]).forEach((elementName) => {
|
||||
this.setOption(elementName, options[elementName]!);
|
||||
});
|
||||
};
|
||||
|
||||
clearOptions = (elementName: Elements) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user