⚙️ Simplifie la logique de la fonction evaluateNode

pull/1121/head
Maxime Quandalle 2020-09-09 12:10:18 +02:00
parent 2236e32674
commit d43ab13942
3 changed files with 21 additions and 13 deletions

View File

@ -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) => (
<span className="value">{nodeValue}</span>
),
isDefault: true
})
export const defaultNode = (nodeValue: EvaluatedNode['nodeValue']) => {
const defaultNode = {
nodeValue,
// eslint-disable-next-line
jsx: ({ nodeValue }: EvaluatedNode) => (
<span className="value">{nodeValue}</span>
),
isDefault: true
}
return { ...defaultNode, evaluate: () => defaultNode }
}
export const parseObject = (recurse, objectShape, value) => {
const recurseOne = key => defaultValue => {

View File

@ -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)

View File

@ -121,6 +121,11 @@ export default function<Names extends string>(
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) => {