make all validation reactions debounced

This commit is contained in:
vchikalkin 2023-04-11 22:55:50 +03:00
parent 09832eec23
commit 891bb889d1
9 changed files with 37 additions and 24 deletions

View File

@ -2,8 +2,8 @@ import { createValidationSchema } from '../validation';
import type { Elements } from '@/Components/Calculation/config/map/values';
import type { ProcessContext } from '@/process/types';
import ValidationHelper from '@/stores/validation/helper';
import { reaction } from 'mobx';
import { uid } from 'radash';
import { debouncedReaction } from 'tools';
const key = uid(7);
@ -13,7 +13,7 @@ export default function reactions(context: ProcessContext) {
const validationSchema = createValidationSchema(context);
const helper = new ValidationHelper();
reaction(
debouncedReaction(
() => $calculation.$values.getValues(['product', 'saleBonus']),
async (values) => {
const validationResult = await validationSchema.safeParseAsync(values);
@ -30,7 +30,8 @@ export default function reactions(context: ProcessContext) {
}
},
{
delay: 100,
delay: 1,
wait: 1000,
}
);
}

View File

@ -2,8 +2,8 @@ import { createValidationSchema } from '../validation';
import type { Elements } from '@/Components/Calculation/config/map/values';
import type { ProcessContext } from '@/process/types';
import ValidationHelper from '@/stores/validation/helper';
import { reaction } from 'mobx';
import { uid } from 'radash';
import { debouncedReaction } from 'tools';
const key = uid(7);
@ -13,7 +13,7 @@ export default function reactions(context: ProcessContext) {
const validationSchema = createValidationSchema(context);
const helper = new ValidationHelper();
reaction(
debouncedReaction(
() => $calculation.$values.getValues(['parmentsDecreasePercent', 'tarif']),
async (values) => {
const validationResult = await validationSchema.safeParseAsync(values);
@ -30,7 +30,8 @@ export default function reactions(context: ProcessContext) {
}
},
{
delay: 100,
delay: 1,
wait: 1000,
}
);
}

View File

@ -12,7 +12,7 @@ import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import { reaction } from 'mobx';
import { uid } from 'radash';
import { makeDisposable, normalizeOptions } from 'tools';
import { debouncedReaction, makeDisposable, normalizeOptions } from 'tools';
dayjs.extend(utc);
@ -522,7 +522,7 @@ export function validation(context: ProcessContext) {
const validationSchema = createValidationSchema(context);
const validationHelper = new ValidationHelper();
reaction(
debouncedReaction(
() =>
$calculation.$values.getValues([
'leaseObjectCategory',
@ -549,7 +549,8 @@ export function validation(context: ProcessContext) {
}
},
{
delay: 100,
delay: 1,
wait: 1000,
}
);
}

View File

@ -7,7 +7,7 @@ import * as CRMTypes from '@/graphql/crm.types';
import ValidationHelper from '@/stores/validation/helper';
import { comparer, reaction, toJS } from 'mobx';
import { uid } from 'radash';
import { normalizeOptions } from 'tools';
import { debouncedReaction, normalizeOptions } from 'tools';
export function common({ store, apolloClient }: ProcessContext) {
const { $calculation, $tables } = store;
@ -274,7 +274,7 @@ export function validation(context: ProcessContext) {
const validationSchema = createValidationSchema(context);
const helper = new ValidationHelper();
reaction(
debouncedReaction(
() => {
const values = $calculation.$values.getValues([
'leasingPeriod',
@ -316,8 +316,9 @@ export function validation(context: ProcessContext) {
}
},
{
delay: 100,
delay: 1,
equals: comparer.structural,
wait: 1000,
}
);
}

View File

@ -2,8 +2,9 @@ import { createValidationSchema } from '../validation';
import type { Elements } from '@/Components/Calculation/config/map/values';
import type { ProcessContext } from '@/process/types';
import ValidationHelper from '@/stores/validation/helper';
import { autorun, reaction } from 'mobx';
import { autorun } from 'mobx';
import { uid } from 'radash';
import { debouncedReaction } from 'tools';
const key = uid(7);
@ -34,7 +35,7 @@ export default function reactions(context: ProcessContext) {
const validationSchema = createValidationSchema(context);
const helper = new ValidationHelper();
reaction(
debouncedReaction(
() =>
$calculation.$values.getValues([
'leaseObjectType',
@ -60,7 +61,8 @@ export default function reactions(context: ProcessContext) {
}
},
{
delay: 100,
delay: 1,
wait: 1000,
}
);
}

View File

@ -2,8 +2,8 @@ import { createValidationSchema } from '../validation';
import type { Elements } from '@/Components/Calculation/config/map/values';
import type { ProcessContext } from '@/process/types';
import ValidationHelper from '@/stores/validation/helper';
import { reaction } from 'mobx';
import { uid } from 'radash';
import { debouncedReaction } from 'tools';
const key = uid(7);
@ -13,7 +13,7 @@ export default function reactions(context: ProcessContext) {
const validationSchema = createValidationSchema(context);
const helper = new ValidationHelper();
reaction(
debouncedReaction(
() =>
$calculation.$values.getValues([
'VATInLeaseObjectPrice',
@ -39,7 +39,8 @@ export default function reactions(context: ProcessContext) {
}
},
{
delay: 100,
delay: 1,
wait: 1000,
}
);
}

View File

@ -246,6 +246,9 @@ export function validation(context: ProcessContext) {
helper.removeErrors();
}
},
{ delay: 1, wait: 1000 }
{
delay: 1,
wait: 1000,
}
);
}

View File

@ -2,8 +2,8 @@ import { createValidationSchema } from '../validation';
import type { Elements } from '@/Components/Calculation/config/map/values';
import type { ProcessContext } from '@/process/types';
import ValidationHelper from '@/stores/validation/helper';
import { reaction } from 'mobx';
import { uid } from 'radash';
import { debouncedReaction } from 'tools';
const key = uid(7);
@ -13,7 +13,7 @@ export default function reactions(context: ProcessContext) {
const validationSchema = createValidationSchema(context);
const helper = new ValidationHelper();
reaction(
debouncedReaction(
() => {
const values = $calculation.$values.getValues([
'calcBrokerRewardCondition',
@ -65,7 +65,8 @@ export default function reactions(context: ProcessContext) {
}
},
{
delay: 100,
delay: 1,
wait: 1000,
}
);
}

View File

@ -5,6 +5,7 @@ import * as CRMTypes from '@/graphql/crm.types';
import ValidationHelper from '@/stores/validation/helper';
import { reaction } from 'mobx';
import { uid } from 'radash';
import { debouncedReaction } from 'tools';
export function common({ store, apolloClient }: ProcessContext) {
const { $calculation } = store;
@ -248,7 +249,7 @@ export function validation(context: ProcessContext) {
const validationSchema = createValidationSchema(context);
const helper = new ValidationHelper();
reaction(
debouncedReaction(
() =>
$calculation.$values.getValues([
'engineHours',
@ -273,7 +274,8 @@ export function validation(context: ProcessContext) {
}
},
{
delay: 100,
delay: 1,
wait: 1000,
}
);
}