refactor(calculationstore): import actions dynamically

remove actions from calculationStore and import in component dynamically
This commit is contained in:
Chika 2021-04-27 13:19:40 +03:00
parent 204f9c077d
commit 9cf409df2c
5 changed files with 18 additions and 29 deletions

View File

@ -1,7 +1,12 @@
import { useStores } from '../useStores';
import { action as resolveAction } from 'core/tools/resolve';
export const useAction = ({ actionName }) => {
const { calculationStore } = useStores();
const action = calculationStore.actions[actionName];
const action = () => {
resolveAction({ storeName: 'CalculationStore', actionName }).then(
({ default: resolvedAction }) => {
resolvedAction();
},
);
};
return { action };
};

View File

@ -8,10 +8,11 @@ import { toJS } from 'mobx';
import CalculationStore, { calculationUrls } from '../..';
import customValues from '../lib/customValues';
import { quoteFields } from '../lib/queries';
import calculate from './calculate';
export default async () => {
const { values, tables, actions } = CalculationStore;
const calculationRes = await actions.calculate();
const { values, tables } = CalculationStore;
const calculationRes = await calculate();
if (!calculationRes) {
return;

View File

@ -1,11 +0,0 @@
import calculate from './calculate';
import createKP from './createKP';
import createLead from './createLead';
export default {
actions: {
calculate,
createKP,
createLead,
},
};

View File

@ -9,7 +9,6 @@ import { autorun, makeAutoObservable, reaction } from 'mobx';
import staticData from './Data/static';
import tables from './Data/tables';
import values from './Data/values';
import actionsEffects from './Effects/actions';
import autorunEffects from './Effects/autorun';
import computedEffects from './Effects/computed';
import reactionEffects from './Effects/reactions';
@ -47,19 +46,11 @@ export const calculationUrls = makeAutoObservable({
});
const CalculationStore: ICalculationStore = makeAutoObservable(
Object.assign(
{},
staticData,
values,
tables,
computedEffects,
actionsEffects,
{
stores: {
calculationProcess,
},
Object.assign({}, staticData, values, tables, computedEffects, {
stores: {
calculationProcess,
},
),
}),
);
autorunEffects.map(autorunEffect => autorun(autorunEffect(CalculationStore)));

View File

@ -2,3 +2,6 @@ import { lazy } from 'react';
export const container = name =>
lazy(() => import(`client/Containers/${name}`));
export const action = ({ storeName, actionName }) =>
import(`client/stores/${storeName}/Effects/actions/${actionName}`);