Skip to content

Commit

Permalink
feat(REPLICATE_ATTRIBUTES): Ensure tracked value has changed before u…
Browse files Browse the repository at this point in the history
…pdating
  • Loading branch information
anishkny committed Dec 2, 2020
1 parent 32296b2 commit 4211e8b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rules/replicateAttributes.ts
Expand Up @@ -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
Expand All @@ -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;
}
});
Expand Down

0 comments on commit 4211e8b

Please sign in to comment.