From c9d7059179d243a4050d22ae30d61040c7b7d68f Mon Sep 17 00:00:00 2001 From: Mael Date: Mon, 1 Oct 2018 08:51:12 +0000 Subject: [PATCH] :sparkles: Simplification du code Simplification relative, car le filtrage des variables n'est pas abouti du tout --- source/engine/treat.js | 15 +++------------ source/engine/treatVariable.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/source/engine/treat.js b/source/engine/treat.js index fe55305ea..f47ff05ce 100644 --- a/source/engine/treat.js +++ b/source/engine/treat.js @@ -91,12 +91,8 @@ export let treatString = (rules, rule) => rawNode => { if (parseResult.category == 'variable') return treatVariable(rules, rule)(parseResult) - if (parseResult.category == 'filteredVariable') { - return treatFilteredVariable(rules, rule)( - parseResult.filter, - parseResult.variable - ) - } + if (parseResult.category == 'filteredVariable') + return treatFilteredVariable(rules, rule) if (parseResult.category == 'negatedVariable') return treatNegatedVariable( treatVariable(rules, rule)(parseResult.variable) @@ -156,17 +152,12 @@ export let treatString = (rules, rule) => rawNode => { return rewriteNode(node, nodeValue, explanation, missingVariables) } - let treatFilteredVariableClosure = parseResult => - treatFilteredVariable(rules, rule)( - parseResult.filter, - parseResult.variable - ) let explanation = parseResult.explanation.map( cond([ [propEq('category', 'variable'), treatVariable(rules, rule)], [ propEq('category', 'filteredVariable'), - treatFilteredVariableClosure + treatFilteredVariable(rules, rule) ], [ propEq('category', 'value'), diff --git a/source/engine/treatVariable.js b/source/engine/treatVariable.js index 3792ed33b..5bb09ecb8 100644 --- a/source/engine/treatVariable.js +++ b/source/engine/treatVariable.js @@ -143,22 +143,25 @@ export let treatVariableTimeless = (rules, rule, filter) => parseResult => { } // TODO - this is becoming overly specific -export let treatFilteredVariable = (rules, rule) => (filter, parseResult) => { +export let treatFilteredVariable = (rules, rule) => parseResult => { let evaluateFiltered = originalEval => ( cache, situation, parsedRules, node ) => { - let newSituation = name => (name == 'sys.filter' ? filter : situation(name)) + let newSituation = name => + name == 'sys.filter' ? parseResult.filter : situation(name) return originalEval(cache, newSituation, parsedRules, node) } - let node = treatVariable(rules, rule, filter)(parseResult), + let node = treatVariable(rules, rule, parseResult.filter)( + parseResult.variable + ), // Decorate node with the composante filter (either who is paying, either tax free) cotisation = { ...node.cotisation, - 'dû par': filter, - 'impôt sur le revenu': filter + 'dû par': parseResult.filter, + 'impôt sur le revenu': parseResult.filter } return {