From d43ab139421e58454cfadaaf1a5cc5f0da84ae27 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Wed, 9 Sep 2020 12:10:18 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Simplifie=20la=20logique?= =?UTF-8?q?=20de=20la=20fonction=20evaluateNode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publicodes/source/evaluation.tsx | 24 ++++++++++++------------ publicodes/source/mecanisms/reduction.ts | 5 ++++- publicodes/source/parseRule.tsx | 5 +++++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/publicodes/source/evaluation.tsx b/publicodes/source/evaluation.tsx index 0f99f60b4..13b9695f7 100644 --- a/publicodes/source/evaluation.tsx +++ b/publicodes/source/evaluation.tsx @@ -38,10 +38,7 @@ export const mergeMissing = (left, right) => mergeWith(add, left || {}, right || {}) export const evaluateNode = (cache, situation, parsedRules, node) => { - const evaluatedNode = node.evaluate - ? node.evaluate(cache, situation, parsedRules, node) - : node - return evaluatedNode + return node.evaluate(cache, situation, parsedRules, node) } function convertNodesToSameUnit(nodes, contextRule, mecanismName) { @@ -126,14 +123,17 @@ export const evaluateArrayWithFilter = (evaluationFilter, reducer, start) => ( ) } -export const defaultNode = (nodeValue: EvaluatedNode['nodeValue']) => ({ - nodeValue, - // eslint-disable-next-line - jsx: ({ nodeValue }: EvaluatedNode) => ( - {nodeValue} - ), - isDefault: true -}) +export const defaultNode = (nodeValue: EvaluatedNode['nodeValue']) => { + const defaultNode = { + nodeValue, + // eslint-disable-next-line + jsx: ({ nodeValue }: EvaluatedNode) => ( + {nodeValue} + ), + isDefault: true + } + return { ...defaultNode, evaluate: () => defaultNode } +} export const parseObject = (recurse, objectShape, value) => { const recurseOne = key => defaultValue => { diff --git a/publicodes/source/mecanisms/reduction.ts b/publicodes/source/mecanisms/reduction.ts index 238a3efed..b95f6e88e 100644 --- a/publicodes/source/mecanisms/reduction.ts +++ b/publicodes/source/mecanisms/reduction.ts @@ -86,7 +86,10 @@ export const mecanismReduction = (recurse, v) => { explanation = v.décote ? { ...base, - décote: map(recurse, v.décote) + décote: { + ...map(recurse, v.décote), + evaluate: () => map(recurse, v.décote) + } } : base, evaluate = evaluateObject(objectShape, effect) diff --git a/publicodes/source/parseRule.tsx b/publicodes/source/parseRule.tsx index f3ed56685..d5328e3e9 100644 --- a/publicodes/source/parseRule.tsx +++ b/publicodes/source/parseRule.tsx @@ -121,6 +121,11 @@ export default function( defaultValue: value => typeof value === 'string' ? parse(rules, rule, parsedRules)(value) + : // TODO : An "object" default value is only used in the + // "synchronisation" mecanism. This should be refactored to not use the + // attribute "defaultValue" + typeof value === 'object' + ? { ...value, evaluate: () => value } : value, formule: value => { const evaluate = (cache, situation, parsedRules, node) => {