Skip to content

Commit 34b5da6

Browse files
committed
Getting value and empty emissions sorted
1 parent d93c0b5 commit 34b5da6

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/firestore/collection/changes.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ export function sortedChanges<T>(query: Query, events: DocumentChangeType[]): Ob
3737
return [{ type: 'metadata', payload: changes.payload.metadata } as DocumentChangeOrMetadata<T>];
3838
}
3939
}),
40-
tap(() => firstEmission = false),
41-
tap(change => console.log("change", change)),
4240
scan((current, changes) => combineChanges(current, changes, events), new Array<DocumentChange<T>>()),
4341
map(changes => changes.map(c => ({ type: c.type, payload: c } as DocumentChangeAction<T>))),
44-
tap(change => console.log("c&m", change)),
42+
filter(actions => actions.length > 0 || !firstEmission || events.indexOf('value') > 0 ),
43+
tap(() => firstEmission = false)
4544
);
4645
}
4746

src/firestore/collection/collection.spec.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ describe('AngularFirestoreCollection', () => {
225225
const { randomCollectionName, ref, stocks, names } =
226226
await collectionHarness(afs, ITEMS, ref => ref.orderBy('price', 'desc'));
227227
const sub = stocks.snapshotChanges().subscribe(data => {
228+
console.log(data);
228229
count = count + 1;
229230
// the first time should all be 'added'
230231
if(count === 1) {
@@ -249,8 +250,7 @@ describe('AngularFirestoreCollection', () => {
249250
const ITEMS = 10;
250251
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
251252

252-
const sub = stocks.snapshotChanges(['modified']).pipe(skip(1)).subscribe(data => {
253-
sub.unsubscribe();
253+
const sub = stocks.snapshotChanges(['modified']).pipe(take(1)).subscribe(data => {
254254
const change = data.filter(x => x.payload.doc.id === names[0])[0];
255255
expect(data.length).toEqual(1);
256256
expect(change.payload.doc.data().price).toEqual(2);
@@ -266,20 +266,17 @@ describe('AngularFirestoreCollection', () => {
266266
const { randomCollectionName, ref, stocks, names } = await collectionHarness(afs, ITEMS);
267267
var count = 0;
268268

269-
stocks.snapshotChanges(['modified', 'metadata']).pipe(take(3)).subscribe(data => {
270-
console.log("data", pending, data);
271-
if (count == 0) {
272-
delayUpdate(stocks, names[0], { price: 4 });
273-
} else {
274-
const change = data.filter(x => x.payload.doc.id === names[0])[0];
275-
console.log(pending, change.payload.doc.metadata);
276-
expect(data.length).toEqual(1);
277-
expect(change.payload.doc.data().price).toEqual(4);
278-
expect(change.type).toEqual('modified');
279-
expect(change.payload.doc.metadata.hasPendingWrites).toEqual(count == 1);
280-
expect(change.payload.doc.metadata.fromCache).toEqual(count == 1);
281-
}
269+
stocks.snapshotChanges(['modified', 'metadata']).pipe(take(2)).subscribe(data => {
270+
const change = data.filter(x => x.payload.doc.id === names[0])[0];
271+
console.log(pending, change.payload.doc.metadata);
272+
expect(data.length).toEqual(1);
273+
expect(change.payload.doc.data().price).toEqual(4);
274+
expect(change.type).toEqual('modified');
275+
expect(change.payload.doc.metadata.hasPendingWrites).toEqual(count == 0);
276+
expect(change.payload.doc.metadata.fromCache).toEqual(count == 0);
282277
});
278+
279+
delayUpdate(stocks, names[0], { price: 4 });
283280

284281
});
285282

0 commit comments

Comments
 (0)