From 6cabf2162528a90845a1dfd74746b236acb4ffed Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Thu, 6 May 2021 12:27:33 +0200 Subject: [PATCH] =?UTF-8?q?:bug:=20Enl=C3=A8ve=20la=20logique=20de=20safe?= =?UTF-8?q?=20valeur=20par=20d=C3=A9faut=20pour=20le=20m=C3=A9canisme=20sy?= =?UTF-8?q?nchronisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit C'est logiquement à la couche "data" de se charger de spécifier les valeurs par défaut si besoin. Publicodes doit juste chercher la clé, et retourner null si elle n'existe pas dans l'objet. --- publicodes/core/source/mecanisms/synchronisation.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/publicodes/core/source/mecanisms/synchronisation.ts b/publicodes/core/source/mecanisms/synchronisation.ts index 8e3458ccc..67d7b8d54 100644 --- a/publicodes/core/source/mecanisms/synchronisation.ts +++ b/publicodes/core/source/mecanisms/synchronisation.ts @@ -16,20 +16,14 @@ const evaluate: EvaluationFunction<'synchronisation'> = function (node: any) { const valuePath = node.explanation.chemin.split(' . ') const path = (obj) => valuePath.reduce((res, prop) => res[prop], obj) const nodeValue = data.nodeValue == null ? null : path(data.nodeValue) - // If the API gave a non null value, then some of its props may be null (the - // API can be composed of multiple API, some failing). Then this prop will be - // set to the default value defined in the API's rule - const safeNodeValue = - nodeValue == null && data.nodeValue != null - ? path(data.explanation.defaultValue) - : nodeValue + const missingVariables = { ...data.missingVariables, ...(data.nodeValue === null ? { [data.dottedName]: 1 } : {}), } const explanation = { ...node.explanation, data } - return { ...node, nodeValue: safeNodeValue, explanation, missingVariables } + return { ...node, nodeValue, explanation, missingVariables } } export const mecanismSynchronisation = (v, context) => {