Skip to content

Commit d99c197

Browse files
jamesdanielsdavideast
authored andcommitted
Port AF2 duplicate emission changes to rxfire (#1185)
1 parent 9493faa commit d99c197

File tree

1 file changed

+12
-8
lines changed
  • packages/rxfire/firestore/collection

1 file changed

+12
-8
lines changed

packages/rxfire/firestore/collection/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,21 @@ function processIndividualChange(
7575
}
7676
break;
7777
case 'modified':
78-
// When an item changes position we first remove it
79-
// and then add it's new position
80-
if (change.oldIndex !== change.newIndex) {
81-
combined.splice(change.oldIndex, 1);
82-
combined.splice(change.newIndex, 0, change);
83-
} else {
84-
combined[change.newIndex] = change;
78+
if (combined[change.oldIndex] == null || combined[change.oldIndex].doc.id == change.doc.id) {
79+
// When an item changes position we first remove it
80+
// and then add it's new position
81+
if (change.oldIndex !== change.newIndex) {
82+
combined.splice(change.oldIndex, 1);
83+
combined.splice(change.newIndex, 0, change);
84+
} else {
85+
combined[change.newIndex] = change;
86+
}
8587
}
8688
break;
8789
case 'removed':
88-
combined.splice(change.oldIndex, 1);
90+
if (combined[change.oldIndex] && combined[change.oldIndex].doc.id == change.doc.id) {
91+
combined.splice(change.oldIndex, 1);
92+
}
8993
break;
9094
}
9195
return combined;

0 commit comments

Comments
 (0)