Created
April 29, 2020 11:59
-
-
Save automaticalldramatic/b29ac50c577e726a244e522393b6a1ef to your computer and use it in GitHub Desktop.
Gists for the post - https://rizwaniqbal.com/posts/paginating-firestore-collections-with-snapshot-listeners/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private snapshotWatchers: Array<() => void> = []; | |
private syncRequest: Partial<ObservablePaginatedQuery>; | |
private syncCards() { | |
// assume some code here to initialise variables, create a service instance et al | |
// syncRequest is a class variable | |
this.syncRequest = WatchPaginatedCards(); | |
this.syncRequest.cards.pipe().subscribe( | |
t => { | |
// do something with the cards received | |
} | |
); | |
} | |
// to get next page | |
public getNextPage() { | |
const snap = this.syncRequest.nextPage.next(); | |
return snap.value !== undefined && this.snapshotWatchers.push(snap.value); | |
} | |
// to stop listening to changes to a particular page | |
this.snapshotWatcher[3](); | |
//or all | |
() => { | |
for (const snapshot of this.snapshotWatchers) { | |
snapshot(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment