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) => {