From 4f4fa1041944565abc422983d2b6f21f6e932b45 Mon Sep 17 00:00:00 2001 From: Mael Date: Wed, 20 Jun 2018 15:35:06 +0200 Subject: [PATCH] =?UTF-8?q?:racehorse:=20Am=C3=A9lioration=20de=20la=20m?= =?UTF-8?q?=C3=A9moisation=20des=20s=C3=A9lecteurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/selectors/analyseSelectors.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/source/selectors/analyseSelectors.js b/source/selectors/analyseSelectors.js index 73fa3fa3f..e8cbab5b3 100644 --- a/source/selectors/analyseSelectors.js +++ b/source/selectors/analyseSelectors.js @@ -1,4 +1,4 @@ -import { createSelector } from 'reselect' +import { createSelector, createSelectorCreator, defaultMemoize } from 'reselect' import { collectMissingVariablesByTarget, getNextSteps @@ -6,7 +6,7 @@ import { import { analyseMany, analyse, parseAll } from 'Engine/traverse' -import { head, isEmpty, pick } from 'ramda' +import { head, isEmpty, pick, equals } from 'ramda' import { getFormValues } from 'redux-form' import { @@ -19,6 +19,9 @@ import { disambiguateExampleSituation } from 'Engine/rules' +// create a "selector creator" that uses deep equal instead of === +const createDeepEqualSelector = createSelectorCreator(defaultMemoize, equals) + /* * * We must here compute parsedRules, flatRules, analyse which contains both targets and cache objects @@ -41,7 +44,11 @@ let ruleDefaultsSelector = createSelector([flatRulesSelector], rules => ) let targetNamesSelector = state => state.targetNames -export let situationSelector = getFormValues('conversation') + +export let situationSelector = createDeepEqualSelector( + getFormValues('conversation'), + x => x +) export let noUserInputSelector = createSelector( [situationSelector], @@ -53,10 +60,13 @@ export let formattedSituationSelector = createSelector( (rules, situation) => formatInputs(rules, nestedSituationToPathMap(situation)) ) -let validatedStepsSelector = state => [ - ...state.conversationSteps.foldedSteps, - state.activeTargetInput -] +let validatedStepsSelector = createSelector( + [ + state => state.conversationSteps.foldedSteps, + state => state.activeTargetInput + ], + (foldedSteps, target) => [...foldedSteps, target] +) export let validatedSituationSelector = createSelector( [formattedSituationSelector, validatedStepsSelector], @@ -107,7 +117,7 @@ export let exampleAnalysisSelector = createSelector( ) let makeAnalysisSelector = situationSelector => - createSelector( + createDeepEqualSelector( [parsedRulesSelector, targetNamesSelector, situationSelector], (parsedRules, targetNames, situation) => analyseMany(parsedRules, targetNames)(dottedName => situation[dottedName])