🐛 Corrige le hot-reload lors de l'édition des règles

Fix #912
pull/917/head
Maxime Quandalle 2020-03-05 12:21:25 +01:00
parent 65a9058e28
commit 2c4b8ea2d7
No known key found for this signature in database
GPG Key ID: 428641C03D29CA10
2 changed files with 14 additions and 6 deletions

View File

@ -6,6 +6,8 @@ import {
collectDefaults,
disambiguateExampleSituation,
findRuleByDottedName,
rules as rulesEn,
rulesFr,
splitName
} from 'Engine/rules'
import { analyse, analyseMany, parseAll } from 'Engine/traverse'
@ -31,14 +33,23 @@ import { RootState, Simulation } from 'Reducers/rootReducer'
import { createSelector, createSelectorCreator, defaultMemoize } from 'reselect'
import { DottedName } from 'Types/rule'
import { mapOrApply } from '../utils'
// create a "selector creator" that uses deep equal instead of ===
const createDeepEqualSelector = createSelectorCreator(defaultMemoize, equals)
let configSelector = (state: RootState) => state.simulation?.config || {}
// We must here compute parsedRules, flatRules, analyse which contains both targets and cache objects
export let flatRulesSelector = (state: RootState) => state.rules
// We used to systematically put the rules in the Redux state but it broke hot
// reloading (the Redux store was re-created every time we changed the rules,
// and the situation was reseted). We now support both putting the rules in the
// state (for tests, library, etc.), and we default to a side-effect value (for
// hot-reloading on developement). See
// https://github.com/betagouv/mon-entreprise/issues/912
export let flatRulesSelector = (state: RootState) =>
state.rules ?? (state.lang === 'en' ? rulesEn : rulesFr)
// We must here compute parsedRules, flatRules, analyse which contains both
// targets and cache objects
export let parsedRulesSelector = createSelector([flatRulesSelector], rules =>
parseAll(rules)
)

View File

@ -1,6 +1,5 @@
import Route404 from 'Components/Route404'
import { SitePathsContext } from 'Components/utils/withSitePaths'
import { rules as baseRulesEn, rulesFr as baseRulesFr } from 'Engine/rules'
import 'iframe-resizer'
import createRavenMiddleware from 'raven-for-redux'
import Raven from 'raven-js'
@ -60,7 +59,6 @@ function InFranceRoute({ basename, language }) {
getSessionStorage()?.setItem('lang', language)
}, [language])
const paths = constructLocalizedSitePath(language)
const rules = language === 'en' ? baseRulesEn : baseRulesFr
return (
<Provider
basename={basename}
@ -74,8 +72,7 @@ function InFranceRoute({ basename, language }) {
}}
initialStore={{
...retrievePersistedState(),
previousSimulation: retrievePersistedSimulation(),
rules
previousSimulation: retrievePersistedSimulation()
}}
>
<RouterSwitch />