From cc1f25e4d71e1c14039dd45dfe9cab3aa9b29642 Mon Sep 17 00:00:00 2001 From: mama Date: Wed, 17 Jan 2018 16:56:30 +0100 Subject: [PATCH] =?UTF-8?q?Recalcul=20des=20r=C3=A9sultats=20en=20temps=20?= =?UTF-8?q?r=C3=A9el=20pendant=20la=20saisie=20num=C3=A9rique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/conversation/FormDecorator.js | 2 +- source/reducers.js | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/source/components/conversation/FormDecorator.js b/source/components/conversation/FormDecorator.js index f477c6c2c..1db92d615 100644 --- a/source/components/conversation/FormDecorator.js +++ b/source/components/conversation/FormDecorator.js @@ -75,11 +75,11 @@ export var FormDecorator = formType => RenderField => props passées à ce dernier, car React 15.2 n'aime pas les attributes inconnus des balises html, dans notre cas. */ + //TODO hack, enables redux-form/CHANGE to update the form state before the traverse functions are run let submit = () => setTimeout(() => stepAction('fold', fieldName), 1), stepProps = { ...this.props.step, inverted, - //TODO hack, enables redux-form/CHANGE to update the form state before the traverse functions are run submit, setFormValue: (value, name = fieldName) => setFormValue(name, value) } diff --git a/source/reducers.js b/source/reducers.js index 4286eaf52..319f34bd2 100644 --- a/source/reducers.js +++ b/source/reducers.js @@ -50,10 +50,17 @@ export let reduceSteps = (tracker, flatRules, answerSource) => ( // Optimization - don't parse on each analysis if (!state.parsedRules) state.parsedRules = parseAll(flatRules) - if (![START_CONVERSATION, STEP_ACTION].includes(action.type)) return state + if ( + ![START_CONVERSATION, STEP_ACTION, '@@redux-form/CHANGE'].includes( + action.type + ) + ) + return state let targetNames = - action.type == START_CONVERSATION ? action.targetNames : state.targetNames + action.type == START_CONVERSATION + ? action.targetNames + : state.targetNames || [] let sim = targetNames.length === 1 ? findRuleByName(flatRules, targetNames[0]) : {}, @@ -66,9 +73,14 @@ export let reduceSteps = (tracker, flatRules, answerSource) => ( situationWithDefaults = assume(intermediateSituation, rulesDefaults) let analysis = analyseMany(state.parsedRules, targetNames)( - situationWithDefaults(state) - ), - nextWithDefaults = getNextSteps(situationWithDefaults(state), analysis), + situationWithDefaults(state) + ) + + if (action.type === '@@redux-form/CHANGE') { + return { ...state, analysis, situationGate: situationWithDefaults(state) } + } + + let nextWithDefaults = getNextSteps(situationWithDefaults(state), analysis), assumptionsMade = !isEmpty(rulesDefaults), done = nextWithDefaults.length == 0