From 65a06b4b4c2c06aeefabcccf65f765f6699a1ddc Mon Sep 17 00:00:00 2001 From: Chika Date: Tue, 1 Sep 2020 21:21:13 +0300 Subject: [PATCH] rename variables --- .../Containers/Calculation/Sections/index.ts | 11 +++++------ src/client/Elements/Input.jsx | 16 ++++++++-------- .../stores/CalculationStore/Effects/autorun.ts | 10 +++++----- src/client/stores/CalculationStore/index.ts | 6 +++--- src/core/types/values.ts | 4 ++-- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/client/Containers/Calculation/Sections/index.ts b/src/client/Containers/Calculation/Sections/index.ts index 7003d4a..8739469 100644 --- a/src/client/Containers/Calculation/Sections/index.ts +++ b/src/client/Containers/Calculation/Sections/index.ts @@ -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' } } ] diff --git a/src/client/Elements/Input.jsx b/src/client/Elements/Input.jsx index f4fb370..b8e8095 100644 --- a/src/client/Elements/Input.jsx +++ b/src/client/Elements/Input.jsx @@ -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 ( { if (!readonly) { setCurrentValue(e.target.value); diff --git a/src/client/stores/CalculationStore/Effects/autorun.ts b/src/client/stores/CalculationStore/Effects/autorun.ts index 2fba7d5..3dcb669 100644 --- a/src/client/stores/CalculationStore/Effects/autorun.ts +++ b/src/client/stores/CalculationStore/Effects/autorun.ts @@ -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; diff --git a/src/client/stores/CalculationStore/index.ts b/src/client/stores/CalculationStore/index.ts index 30c8a9a..b5be97a 100644 --- a/src/client/stores/CalculationStore/index.ts +++ b/src/client/stores/CalculationStore/index.ts @@ -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) { diff --git a/src/core/types/values.ts b/src/core/types/values.ts index a370382..c7f7a71 100644 --- a/src/core/types/values.ts +++ b/src/core/types/values.ts @@ -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; };