Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   getRecords(searchText: BehaviorSubject<string>): Observable<any> {
  2.     return searchText.pipe(
  3.       switchMap(st => {
  4.  
  5.         const fNameRef = this.afs.collection('students', ref => ref.where('fname', '==', st));
  6.         const lNameRef = this.afs.collection('students', ref => ref.where('lname', '==', st));
  7.         const gradeRef = this.afs.collection('students', ref => ref.where('grade', '==', st));
  8.  
  9.         const combined = combineLatest([
  10.         fNameRef.snapshotChanges(),
  11.         lNameRef.snapshotChanges(),
  12.         gradeRef.snapshotChanges()]
  13.         );
  14.  
  15.         return combined.pipe(
  16.           switchMap(docs => {
  17.           const [fNameDocs, lNameDocs, gradeDocs] = docs;
  18.           const c = fNameDocs.concat(lNameDocs, gradeDocs);
  19.           return of(c);
  20.           }),
  21.           debounceTime(250),
  22.           tap(arr => console.log(`${arr.length} reads on students collection`)),
  23.           map(changes => {
  24.           return changes.map(c => {
  25.             const data = c.payload.doc.data();
  26.             const id = c.payload.doc.id;
  27.             return { id, ...data };
  28.             });
  29.           })
  30.         );
  31.       }));
  32.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement