Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/utils/firebase_list_factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ describe('FirebaseListFactory', () => {
).toEqual([val2, val1, val3]);
});

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

it('should not mutate the input array', () => {
var inputArr = [val1, val2];
Expand Down
4 changes: 3 additions & 1 deletion src/utils/firebase_list_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export function onChildChanged(arr:any[], child:any, prevKey:string): any[] {
return arr.reduce((accumulator:any[], val:any, i:number) => {
if (!prevKey && i==0) {
accumulator.push(child);
accumulator.push(val);
if (val.key() !== child.key()) {
accumulator.push(val);
}
} else if(val.key() === prevKey) {
accumulator.push(val);
accumulator.push(child);
Expand Down