From a53851e300a98cdc31f9df61c9ec805bdb4ac74c Mon Sep 17 00:00:00 2001 From: Mael Date: Tue, 4 Sep 2018 17:17:36 +0200 Subject: [PATCH] :bug: :gear: Correction de l'algorithme des variations --- source/engine/mecanisms.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index f407375bf..02ef137ea 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -1,5 +1,6 @@ import { reduce, + reduced, mergeWith, objOf, toPairs, @@ -159,11 +160,17 @@ export let mecanismVariations = (recurse, k, v, devariate) => { : evaluateNode(cache, situationGate, parsedRules, prop) ), evaluatedExplanation = map(evaluateVariation, node.explanation), - satisfiedVariation = find( - variation => - !variation.condition || variation.condition.nodeValue === true, - evaluatedExplanation - ), + satisfiedVariation = reduce( + (_, variation) => + variation.condition == undefined + ? reduced(variation) // We've reached the eventual defaut case + : variation.condition.nodeValue === null + ? reduced(null) // one case has missing variables => we can't go further + : variation.condition.nodeValue === true + ? reduced(variation) + : null, + null + )(evaluatedExplanation), nodeValue = satisfiedVariation ? satisfiedVariation.consequence.nodeValue : null