Skip to content

Commit

Permalink
fix: braze debounce update (#912)
Browse files Browse the repository at this point in the history
* update comment
* add logic for enhanced debounce
* refactor

---------

Co-authored-by: Niall Brennan <[email protected]>
  • Loading branch information
niallzato and Niall Brennan authored Feb 8, 2024
1 parent a226dc5 commit 285a3bd
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/plugins/plugin-braze/src/BrazePlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,36 @@ export class BrazePlugin extends DestinationPlugin {
return undefined;
};

private compareObjects(oldTraits: any, newTraits: any): boolean {

Check failure on line 86 in packages/plugins/plugin-braze/src/BrazePlugin.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

Unexpected any. Specify a different type

Check failure on line 86 in packages/plugins/plugin-braze/src/BrazePlugin.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

Unexpected any. Specify a different type
for (let key in newTraits) {

Check failure on line 87 in packages/plugins/plugin-braze/src/BrazePlugin.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

'key' is never reassigned. Use 'const' instead
if (newTraits.hasOwnProperty(key)) {

Check failure on line 88 in packages/plugins/plugin-braze/src/BrazePlugin.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

Unexpected any value in conditional. An explicit comparison or type cast is required
if (typeof newTraits[key] === 'object' && !Array.isArray(newTraits[key])) {
if (!this.compareObjects(oldTraits[key], newTraits[key])) {
return false;
}
} else if (Array.isArray(newTraits[key])) {
for (let i = 0; i < newTraits[key].length; i++) {
if (!this.compareObjects(oldTraits[key][i], newTraits[key][i])) {
return false;
}
}
} else if (oldTraits[key] !== newTraits[key]) {
return false;
}
}
}
return true;
}

identify(event: IdentifyEventType) {
//check to see if anything has changed.
//if it hasn't changed don't send event
let identical = typeof this.lastSeenTraits?.traits === 'undefined' ? false : this.compareObjects(this.lastSeenTraits?.traits, event.traits);

Check failure on line 110 in packages/plugins/plugin-braze/src/BrazePlugin.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

'identical' is never reassigned. Use 'const' instead

if (
this.lastSeenTraits?.userId === event.userId &&
this.lastSeenTraits?.anonymousId === event.anonymousId &&
this.lastSeenTraits?.traits === event.traits
identical
) {
return;
} else {
Expand Down

0 comments on commit 285a3bd

Please sign in to comment.