From 6ac00c17d66cc78fd9a9f3da1dfdd56529166271 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 25 Jan 2023 17:43:23 +0300 Subject: [PATCH] fix mobx errors --- .../leasing-object/reactions/common.ts | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/apps/web/process/leasing-object/reactions/common.ts b/apps/web/process/leasing-object/reactions/common.ts index 0268629..26bcc2f 100644 --- a/apps/web/process/leasing-object/reactions/common.ts +++ b/apps/web/process/leasing-object/reactions/common.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { gql } from '@apollo/client'; import type * as CRMTypes from 'graphql/crm.types'; -import { autorun, reaction } from 'mobx'; +import { reaction } from 'mobx'; import type { ReactionsContext } from 'process/types'; import { intersects } from 'radash'; import { normalizeOptions } from 'tools'; @@ -84,14 +84,18 @@ const QUERY_GET_CONFIGURATIONS = gql` export default function commonReactions({ store, apolloClient }: ReactionsContext) { const { $calculation } = store; - autorun( - async () => { - const { - brand: brandId, - subsidy: subsidyId, - importProgram: importProgramId, - leaseObjectType: leaseObjectTypeId, - } = $calculation.$values.values; + reaction( + () => { + const { brand, subsidy, importProgram, leaseObjectType } = $calculation.$values.values; + + return { + brandId: brand, + subsidyId: subsidy, + importProgramId: importProgram, + leaseObjectTypeId: leaseObjectType, + }; + }, + async ({ brandId, subsidyId, importProgramId, leaseObjectTypeId }) => { if (!brandId) { $calculation.element('selectModel').reset(); @@ -201,21 +205,21 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex } $calculation.element('selectModel').setOptions(normalizeOptions(models)); - }, - { - delay: 10, } ); - autorun( - async () => { - const { - product: productId, - subsidy: subsidyId, - importProgram: importProgramId, - leaseObjectType: leaseObjectTypeId, - } = $calculation.$values.values; + reaction( + () => { + const { product, subsidy, importProgram, leaseObjectType } = $calculation.$values.values; + return { + productId: product, + subsidyId: subsidy, + importProgramId: importProgram, + leaseObjectTypeId: leaseObjectType, + }; + }, + async ({ productId, subsidyId, importProgramId, leaseObjectTypeId }) => { const { data: { evo_brands }, } = await apolloClient.query< @@ -345,9 +349,6 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex } $calculation.element('selectBrand').setOptions(normalizeOptions(brands)); - }, - { - delay: 10, } );