Skip to content

Commit 314c595

Browse files
rosslaverydavideast
authored andcommitted
fix(FirebaseListFactory): prevent first item being duplicated when it changes (angular#140)
1 parent 08dc5ab commit 314c595

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/utils/firebase_list_factory.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ describe('FirebaseListFactory', () => {
169169
).toEqual([val2, val1, val3]);
170170
});
171171

172+
it('should not duplicate the first item if it is the one that changed', () => {
173+
expect(
174+
onChildChanged([val1, val2, val3], val1, null)
175+
).not.toEqual([val1, val1, val2, val3]);
176+
});
172177

173178
it('should not mutate the input array', () => {
174179
var inputArr = [val1, val2];

src/utils/firebase_list_factory.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export function onChildChanged(arr:any[], child:any, prevKey:string): any[] {
9494
return arr.reduce((accumulator:any[], val:any, i:number) => {
9595
if (!prevKey && i==0) {
9696
accumulator.push(child);
97-
accumulator.push(val);
97+
if (val.key() !== child.key()) {
98+
accumulator.push(val);
99+
}
98100
} else if(val.key() === prevKey) {
99101
accumulator.push(val);
100102
accumulator.push(child);

0 commit comments

Comments
 (0)