⚙️ Sort les fonctions evaluate des "ruleProps"

pull/1124/head
Maxime Quandalle 2020-09-28 17:10:11 +01:00
parent 33eb6c32db
commit a56237c2ae
1 changed files with 49 additions and 48 deletions

View File

@ -133,31 +133,12 @@ export default function<Names extends string>(
? { ...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<Names extends string>(
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<Names extends string>(
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',