From a56237c2aed67ea4eafd0df49d82bd8285737a3d Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Mon, 28 Sep 2020 17:10:11 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Sort=20les=20fonctions=20e?= =?UTF-8?q?valuate=20des=20"ruleProps"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publicodes/source/parseRule.tsx | 97 +++++++++++++++++---------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/publicodes/source/parseRule.tsx b/publicodes/source/parseRule.tsx index fe816fc5b..2d8531c3f 100644 --- a/publicodes/source/parseRule.tsx +++ b/publicodes/source/parseRule.tsx @@ -133,31 +133,12 @@ export default function( ? { ...value, evaluate: () => value } : value, formule: value => { - const evaluate = (cache, situation, parsedRules, node) => { - const explanation = evaluateNode( - cache, - situation, - parsedRules, - node.explanation - ), - { nodeValue, unit, missingVariables, temporalValue } = explanation - - return { - ...node, - nodeValue, - unit, - missingVariables, - explanation, - temporalValue - } - } - const child = parse(rules, rule, parsedRules)(value) const jsx = ({ explanation }) => makeJsx(explanation) return { - evaluate, + evaluate: evaluateFormula, jsx, category: 'ruleProp', rulePropType: 'formula', @@ -183,22 +164,7 @@ export default function( replacedBy: [] } parsedRules[dottedName]['rendu non applicable'] = { - evaluate: (cache, situation, parsedRules, node) => { - const isDisabledBy = node.explanation.isDisabledBy.map(disablerNode => - evaluateNode(cache, situation, parsedRules, disablerNode) - ) - const nodeValue = isDisabledBy.some( - x => x.nodeValue !== false && x.nodeValue !== null - ) - const explanation = { ...node.explanation, isDisabledBy } - return { - ...node, - explanation, - nodeValue, - missingVariables: mergeAllMissing(isDisabledBy) - } - }, - + evaluate: evaluateDisabledBy, jsx: ({ explanation: { isDisabledBy } }) => { return ( isDisabledBy.length > 0 && ( @@ -249,20 +215,55 @@ export default function( return parsedRules[dottedName] } -const evolveCond = (dottedName, rule, rules, parsedRules) => value => { - const evaluate = (cache, situation, parsedRules, node) => { - const explanation = evaluateNode( - cache, - situation, - parsedRules, - node.explanation - ), - nodeValue = explanation.nodeValue, - missingVariables = explanation.missingVariables +const evaluateFormula = (cache, situation, parsedRules, node) => { + const explanation = evaluateNode( + cache, + situation, + parsedRules, + node.explanation + ), + { nodeValue, unit, missingVariables, temporalValue } = explanation - return { ...node, nodeValue, explanation, missingVariables } + return { + ...node, + nodeValue, + unit, + missingVariables, + explanation, + temporalValue } +} +const evaluateDisabledBy = (cache, situation, parsedRules, node) => { + const isDisabledBy = node.explanation.isDisabledBy.map(disablerNode => + evaluateNode(cache, situation, parsedRules, disablerNode) + ) + const nodeValue = isDisabledBy.some( + x => x.nodeValue !== false && x.nodeValue !== null + ) + const explanation = { ...node.explanation, isDisabledBy } + return { + ...node, + explanation, + nodeValue, + missingVariables: mergeAllMissing(isDisabledBy) + } +} + +const evaluateEvolveCond = (cache, situation, parsedRules, node) => { + const explanation = evaluateNode( + cache, + situation, + parsedRules, + node.explanation + ), + nodeValue = explanation.nodeValue, + missingVariables = explanation.missingVariables + + return { ...node, nodeValue, explanation, missingVariables } +} + +const evolveCond = (dottedName, rule, rules, parsedRules) => value => { const child = parse(rules, rule, parsedRules)(value) const jsx = ({ nodeValue, explanation, unit }) => ( @@ -276,7 +277,7 @@ const evolveCond = (dottedName, rule, rules, parsedRules) => value => { ) return { - evaluate, + evaluate: evaluateEvolveCond, jsx, category: 'ruleProp', rulePropType: 'cond',