fix calculationstore type
This commit is contained in:
parent
f69e4aeaa4
commit
be071545a6
@ -1,11 +1,11 @@
|
||||
import { IAutorunEffect } from 'core/types/effect';
|
||||
|
||||
const autorunEffects: IAutorunEffect[] = [
|
||||
calculationStore => () => {
|
||||
if (parseInt(calculationStore.values.price) > 25) {
|
||||
calculationStore.setValue('one', 100500);
|
||||
}
|
||||
}
|
||||
// calculationStore => () => {
|
||||
// if (parseInt(calculationStore.values.price) > 25) {
|
||||
// calculationStore.setValue('one', 100500);
|
||||
// }
|
||||
// }
|
||||
];
|
||||
|
||||
export default autorunEffects;
|
||||
|
||||
@ -1,29 +1,74 @@
|
||||
import { IReactionEffect } from 'core/types/effect';
|
||||
import { Status } from 'core/types/elements';
|
||||
import { Status } from 'core/types/statuses';
|
||||
|
||||
const reactionEffects: IReactionEffect[] = [
|
||||
calculationStore => ({
|
||||
expression: () => calculationStore.values.one,
|
||||
effect: one => console.log('one ', one)
|
||||
}),
|
||||
calculationStore => ({
|
||||
expression: () => calculationStore.values.price,
|
||||
effect: price => console.log('price: ', price)
|
||||
}),
|
||||
calculationStore => ({
|
||||
expression: () => calculationStore.values.cbx,
|
||||
effect: cbx => {
|
||||
if (cbx === true) {
|
||||
calculationStore.statuses.cars = Status.Disabled;
|
||||
} else {
|
||||
calculationStore.statuses.cars = Status.Default;
|
||||
expression: () => {
|
||||
const { channel } = calculationStore.values;
|
||||
return channel;
|
||||
},
|
||||
effect: channel => {
|
||||
switch (channel) {
|
||||
case 100000000:
|
||||
calculationStore.setStatus('selectSupplier', Status.Default);
|
||||
calculationStore.setStatus('selectAgent', Status.Default);
|
||||
|
||||
calculationStore.setStatus('selectFinDepartment', Status.Disabled);
|
||||
calculationStore.setValue('finDepartment', undefined);
|
||||
|
||||
calculationStore.setStatus('selectBroker', Status.Disabled);
|
||||
calculationStore.setValue('broker', undefined);
|
||||
break;
|
||||
|
||||
case 100000001:
|
||||
calculationStore.setStatus('selectSupplier', Status.Default);
|
||||
calculationStore.setStatus('selectAgent', Status.Default);
|
||||
|
||||
calculationStore.setStatus('selectFinDepartment', Status.Default);
|
||||
|
||||
calculationStore.setStatus('selectBroker', Status.Disabled);
|
||||
calculationStore.setValue('broker', undefined);
|
||||
break;
|
||||
case 100000002:
|
||||
calculationStore.setStatus('selectSupplier', Status.Disabled);
|
||||
calculationStore.setValue('supplier', undefined);
|
||||
|
||||
calculationStore.setStatus('selectAgent', Status.Default);
|
||||
|
||||
calculationStore.setStatus('selectFinDepartment', Status.Disabled);
|
||||
calculationStore.setValue('finDepartment', undefined);
|
||||
|
||||
calculationStore.setStatus('selectBroker', Status.Disabled);
|
||||
calculationStore.setValue('broker', undefined);
|
||||
break;
|
||||
case 100000003:
|
||||
calculationStore.setStatus('selectSupplier', Status.Disabled);
|
||||
calculationStore.setValue('supplier', undefined);
|
||||
|
||||
calculationStore.setStatus('selectAgent', Status.Default);
|
||||
calculationStore.setValue('agent', undefined);
|
||||
|
||||
calculationStore.setStatus('selectFinDepartment', Status.Disabled);
|
||||
calculationStore.setValue('finDepartment', undefined);
|
||||
|
||||
calculationStore.setStatus('selectBroker', Status.Default);
|
||||
break;
|
||||
case 100000004:
|
||||
default:
|
||||
calculationStore.setStatus('selectSupplier', Status.Disabled);
|
||||
calculationStore.setValue('supplier', undefined);
|
||||
|
||||
calculationStore.setStatus('selectAgent', Status.Disabled);
|
||||
calculationStore.setValue('agent', undefined);
|
||||
|
||||
calculationStore.setStatus('selectFinDepartment', Status.Disabled);
|
||||
calculationStore.setValue('finDepartment', undefined);
|
||||
|
||||
calculationStore.setStatus('selectBroker', Status.Disabled);
|
||||
calculationStore.setValue('broker', undefined);
|
||||
break;
|
||||
}
|
||||
console.log('cbx: ', cbx);
|
||||
}
|
||||
}),
|
||||
calculationStore => ({
|
||||
expression: () => calculationStore.values.cars,
|
||||
effect: cars => console.log('cars: ', cars)
|
||||
})
|
||||
];
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { IWhenEffect } from 'core/types/effect';
|
||||
|
||||
const whenEffects: IWhenEffect[] = [
|
||||
calculationStore => ({
|
||||
predicate: () => parseInt(calculationStore.values.one) === 5,
|
||||
effect: () => console.log(calculationStore.values.one)
|
||||
})
|
||||
// calculationStore => ({
|
||||
// predicate: () => parseInt(calculationStore.values.one) === 5,
|
||||
// effect: () => console.log(calculationStore.values.one)
|
||||
// })
|
||||
];
|
||||
|
||||
export default whenEffects;
|
||||
|
||||
@ -11,8 +11,9 @@ import autorunEffects from './Effects/autorun';
|
||||
import computedEffects from './Effects/computed';
|
||||
import reactionEffects from './Effects/reaction';
|
||||
import whenEffects from './Effects/when';
|
||||
import { ICalculationStore } from 'core/types/stores';
|
||||
|
||||
const CalculationStore = observable(
|
||||
const CalculationStore: ICalculationStore = observable(
|
||||
assignProperties(
|
||||
{
|
||||
values: initialValues,
|
||||
|
||||
@ -1,23 +1,22 @@
|
||||
import CalculationStore from 'client/stores/CalculationStore';
|
||||
import CommonStore from 'client/stores/CommonStore';
|
||||
import { IReactionPublic, Lambda } from 'mobx';
|
||||
import { ICalculationStore } from './stores';
|
||||
|
||||
type TCalculationStore = typeof CalculationStore;
|
||||
type TCommonStore = typeof CommonStore;
|
||||
|
||||
export interface IAutorunEffect {
|
||||
(CalculationStore: TCalculationStore, CommonStore?: TCommonStore): () => void;
|
||||
(CalculationStore: ICalculationStore, CommonStore?: TCommonStore): () => void;
|
||||
}
|
||||
|
||||
export interface IReactionEffect {
|
||||
(CalculationStore: TCalculationStore): {
|
||||
(CalculationStore: ICalculationStore): {
|
||||
expression: (r: IReactionPublic) => any;
|
||||
effect: (arg: any, r: IReactionPublic) => void;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IWhenEffect {
|
||||
(CalculationStore: TCalculationStore): {
|
||||
(CalculationStore: ICalculationStore): {
|
||||
predicate: () => boolean;
|
||||
effect: Lambda;
|
||||
};
|
||||
|
||||
16
src/core/types/stores.ts
Normal file
16
src/core/types/stores.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { TValues, ValuesNames } from './values';
|
||||
import { TElements, ElementsNames } from './elements';
|
||||
import { TStatuses, Status } from './statuses';
|
||||
|
||||
export interface ICalculationStore {
|
||||
values: TValues;
|
||||
options: TElements;
|
||||
statuses: TStatuses;
|
||||
filters: any;
|
||||
|
||||
getValue: (sourceValueName: ValuesNames) => any;
|
||||
getStatus: (elementName: ElementsNames) => Status;
|
||||
|
||||
setValue: (sourceValueName: ValuesNames, newValue: any) => void;
|
||||
setStatus: (elementName: ElementsNames, status: Status) => void;
|
||||
}
|
||||
Reference in New Issue
Block a user