rename variables

This commit is contained in:
Chika 2020-09-01 21:21:13 +03:00
parent 2109523a52
commit 65a06b4b4c
5 changed files with 23 additions and 24 deletions

View File

@ -1,6 +1,5 @@
import CalculationStore from 'client/stores/CalculationStore';
import withTitle from 'client/hocs/withTitle';
import Input from 'client/Elements/Input';
import withTitle from 'client/hocs/withTitle';
export default [
{
@ -11,7 +10,7 @@ export default [
Component: withTitle('Price')(Input),
props: {
placeholder: 'Enter price',
sourceValueName: 'price'
bindedValueName: 'price'
}
},
{
@ -19,14 +18,14 @@ export default [
Component: withTitle('One')(Input),
props: {
placeholder: 'Enter one',
sourceValueName: 'one'
bindedValueName: 'one'
}
},
{
name: 'total',
Component: withTitle('Total')(Input),
props: {
computed: 'total'
computedValue: 'total'
}
}
]
@ -38,7 +37,7 @@ export default [
name: 'priceonAnotherTab',
Component: withTitle('Price on another tab')(Input),
props: {
sourceValueName: 'price'
bindedValueName: 'price'
}
}
]

View File

@ -4,31 +4,31 @@ import { observer } from 'mobx-react';
import React, { useEffect, useState } from 'react';
import { useDebounce } from 'use-debounce';
const Input = ({ readonly, placeholder, sourceValueName, computed }) => {
const Input = ({ readonly, placeholder, bindedValueName, computedValue }) => {
const { calculationStore } = useStores();
const [currentValue, setCurrentValue] = useState(undefined);
const [debouncedValue] = useDebounce(currentValue, 850);
const sourceValue = calculationStore.values[sourceValueName];
const sourceValue = calculationStore.values[bindedValueName];
// get value from store
useEffect(() => {
if (!computed) {
if (!computedValue) {
setCurrentValue(sourceValue);
}
}, [computed, sourceValue]);
}, [computedValue, sourceValue]);
// set value to store
useEffect(() => {
if (!computed) {
calculationStore.setValue(sourceValueName, debouncedValue);
if (!computedValue) {
calculationStore.setValue(bindedValueName, debouncedValue);
}
}, [calculationStore, computed, debouncedValue, sourceValueName]);
}, [calculationStore, computedValue, debouncedValue, bindedValueName]);
return (
<AntInput
placeholder={placeholder}
value={computed ? calculationStore[computed]() : currentValue}
value={computedValue ? calculationStore[computedValue]() : currentValue}
onChange={e => {
if (!readonly) {
setCurrentValue(e.target.value);

View File

@ -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;

View File

@ -2,7 +2,7 @@ import assignProperties from 'client/tools/assignProps';
import initialStatuses from 'core/config/initialStatuses';
import initialValues from 'core/config/initialValues';
import { Status } from 'core/types/elements';
import { SourceValueNames } from 'core/types/values';
import { ValuesNames } from 'core/types/values';
import { observable } from 'mobx';
import computedEffects from './Effects/computed';
@ -12,14 +12,14 @@ const CalculationStore = observable(
values: initialValues,
statuses: initialStatuses,
getValue(sourceValueName: SourceValueNames) {
getValue(sourceValueName: ValuesNames) {
return this.values[sourceValueName];
},
getStatus(elementName: string) {
return this.statuses[elementName];
},
setValue(sourceValueName: SourceValueNames, newValue: any) {
setValue(sourceValueName: ValuesNames, newValue: any) {
this.values[sourceValueName] = newValue;
},
setStatus(elementName: string, status: Status) {

View File

@ -1,5 +1,5 @@
export type SourceValueNames = "one" | "two" | "three" | "price";
export type ValuesNames = "one" | "two" | "three" | "price";
export type ValuesMap = {
[valueName in SourceValueNames]?: any;
[valueName in ValuesNames]?: any;
};