Merge pull request #262 from betagouv/racehorse
Amélioration de la mémoisation des sélecteurspull/263/head
commit
c8f96058e1
|
@ -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])
|
||||
|
|
Loading…
Reference in New Issue