Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getRecords(searchText: BehaviorSubject<string>): Observable<any> {
- return searchText.pipe(
- switchMap(st => {
- const fNameRef = this.afs.collection('students', ref => ref.where('fname', '==', st));
- const lNameRef = this.afs.collection('students', ref => ref.where('lname', '==', st));
- const gradeRef = this.afs.collection('students', ref => ref.where('grade', '==', st));
- const combined = combineLatest([
- fNameRef.snapshotChanges(),
- lNameRef.snapshotChanges(),
- gradeRef.snapshotChanges()]
- );
- return combined.pipe(
- switchMap(docs => {
- const [fNameDocs, lNameDocs, gradeDocs] = docs;
- const c = fNameDocs.concat(lNameDocs, gradeDocs);
- return of(c);
- }),
- debounceTime(250),
- tap(arr => console.log(`${arr.length} reads on students collection`)),
- map(changes => {
- return changes.map(c => {
- const data = c.payload.doc.data();
- const id = c.payload.doc.id;
- return { id, ...data };
- });
- })
- );
- }), debounceTime(250));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement