From 842820af5491720a84ffcaeb8a98cf3ae158ea34 Mon Sep 17 00:00:00 2001 From: Chika Date: Wed, 7 Oct 2020 19:11:19 +0300 Subject: [PATCH] optimize mobx store: prevent unnecessary rerender --- src/client/stores/CalculationStore/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/client/stores/CalculationStore/index.ts b/src/client/stores/CalculationStore/index.ts index a7aeae2..e897979 100644 --- a/src/client/stores/CalculationStore/index.ts +++ b/src/client/stores/CalculationStore/index.ts @@ -5,6 +5,7 @@ import { import actionsEffects from 'client/stores/CalculationStore/Effects/action'; // import assignProperties from 'client/tools/assignProps'; import { ICalculationStore } from 'core/types/stores'; +import { isEqual } from 'lodash'; import { autorun, makeAutoObservable, reaction, when } from 'mobx'; import CommonStore from '../CommonStore'; import { @@ -43,11 +44,12 @@ autorunEffects.map(autorunEffect => reactionEffects.map(reactionEffectBuilder => { const reactionEffect = reactionEffectBuilder(CalculationStore); - return reaction( - reactionEffect.expression, - reactionEffect.effect, - reactionEffect.options, - ); + return reaction(reactionEffect.expression, reactionEffect.effect, { + ...reactionEffect.options, + equals: (nextParams, prevParams) => { + return isEqual(nextParams, prevParams); + }, + }); }); whenEffects.map(whenEffectBuilder => {