Skip to content

Commit

Permalink
fix(afs): Gracefully handle duplicate emissions on modified/deleted (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdaniels authored and sulco committed Sep 3, 2018
1 parent 1d46d0d commit ae93948
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/firestore/collection/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,21 @@ export function combineChange<T>(combined: DocumentChange<T>[], change: Document
}
break;
case 'modified':
// When an item changes position we first remove it
// and then add it's new position
if(change.oldIndex !== change.newIndex) {
combined.splice(change.oldIndex, 1);
combined.splice(change.newIndex, 0, change);
} else {
combined.splice(change.newIndex, 1, change);
if (combined[change.oldIndex] == null || combined[change.oldIndex].doc.id == change.doc.id) {
// When an item changes position we first remove it
// and then add it's new position
if(change.oldIndex !== change.newIndex) {
combined.splice(change.oldIndex, 1);
combined.splice(change.newIndex, 0, change);
} else {
combined.splice(change.newIndex, 1, change);
}
}
break;
case 'removed':
combined.splice(change.oldIndex, 1);
if (combined[change.oldIndex] && combined[change.oldIndex].doc.id == change.doc.id) {
combined.splice(change.oldIndex, 1);
}
break;
}
return combined;
Expand Down

0 comments on commit ae93948

Please sign in to comment.