From 4211e8b72568325c6076b9ccf37968799eafde82 Mon Sep 17 00:00:00 2001 From: Anish Karandikar Date: Tue, 1 Dec 2020 16:01:54 -0800 Subject: [PATCH] feat(REPLICATE_ATTRIBUTES): Ensure tracked value has changed before updating --- src/rules/replicateAttributes.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rules/replicateAttributes.ts b/src/rules/replicateAttributes.ts index 4fb7e99..7dc8924 100644 --- a/src/rules/replicateAttributes.ts +++ b/src/rules/replicateAttributes.ts @@ -61,6 +61,7 @@ export function integrifyReplicateAttributes( .onUpdate((change, context) => { const masterId = context.params.masterId; const newValue = change.after.data(); + const oldValue = change.before.data(); console.log( `integrify: Detected update in [${rule.source.collection}], id [${masterId}], new value:`, newValue @@ -77,7 +78,10 @@ export function integrifyReplicateAttributes( // Check if atleast one of the attributes to be replicated was changed let relevantUpdate = false; Object.keys(newValue).forEach((changedAttribute) => { - if (trackedMasterAttributes[changedAttribute]) { + if ( + trackedMasterAttributes[changedAttribute] && + newValue[changedAttribute] !== oldValue[changedAttribute] + ) { relevantUpdate = true; } });