From c6141db9fcdabb385da80abd9b5cd3963df3b357 Mon Sep 17 00:00:00 2001 From: Shams mosowi Date: Thu, 18 Mar 2021 17:13:55 +1000 Subject: [PATCH] fix derivative bug --- ft_build/functions/src/derivatives/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ft_build/functions/src/derivatives/index.ts b/ft_build/functions/src/derivatives/index.ts index a14e2856..9273e280 100644 --- a/ft_build/functions/src/derivatives/index.ts +++ b/ft_build/functions/src/derivatives/index.ts @@ -7,7 +7,7 @@ const shouldEvaluateReducer = (listeners, before, after) => if (acc) return true; else return ( - JSON.stringify(before[currField]) !== JSON.stringify(after[currField]) + JSON.stringify(before?.[currField]) !== JSON.stringify(after[currField]) ); }, false); @@ -23,14 +23,16 @@ const derivative = ( utilFns: any; }) => any; }[] -) => async (change: functions.Change) => { +) => async ( + change: functions.Change, +) => { try { const beforeData = change.before?.data(); const afterData = change.after?.data(); const ref = change.after ? change.after.ref : change.before.ref; const update = await functionConfig.reduce( async (accUpdates: any, currDerivative) => { - const shouldEval = shouldEvaluateReducer( + const shouldEval = (!beforeData && afterData) || shouldEvaluateReducer( currDerivative.listenerFields, beforeData, afterData