This repository has been archived on 2025-05-09. You can view files and clone it, but cannot push or open issues or pull requests.
2022-04-06 10:42:45 +03:00

45 lines
1.5 KiB
TypeScript

import { injectFinGapReactions } from 'client/process/fingap/reactions';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { isEqual } from 'lodash';
import { autorun, makeAutoObservable, reaction, when } from 'mobx';
import staticData from './Data/static';
import tables from './Data/tables';
import values from './Data/values';
import autorunEffects from './Effects/autorun';
import computedEffects from './Effects/computed';
import reactionEffects from './Effects/reactions';
import whenEffects from './Effects/when';
import init from './init';
import subStores from './subStores';
const { calculationProcess } = subStores;
const CalculationStore: ICalculationStore = makeAutoObservable(
Object.assign({ init }, staticData, values, tables, computedEffects, {
stores: subStores,
}),
);
autorunEffects.map(autorunEffect => autorun(autorunEffect(CalculationStore)));
reactionEffects.map(reactionEffectBuilder => {
const reactionEffect = reactionEffectBuilder(
CalculationStore,
calculationProcess,
);
return reaction(reactionEffect.expression, reactionEffect.effect, {
...reactionEffect.options,
equals:
reactionEffect.options?.equals ||
((nextParams, prevParams) => isEqual(nextParams, prevParams)),
});
});
injectFinGapReactions(CalculationStore);
whenEffects.map(whenEffectBuilder => {
const whenEffect = whenEffectBuilder(CalculationStore);
return when(whenEffect.predicate, whenEffect.effect);
});
export default CalculationStore;