⚙️ Simplifie la logique de la fonction evaluateNode
parent
2236e32674
commit
d43ab13942
|
@ -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 => {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue