Skip to content

Instantly share code, notes, and snippets.

@automaticalldramatic
Created April 29, 2020 11:59
Show Gist options
  • Save automaticalldramatic/b29ac50c577e726a244e522393b6a1ef to your computer and use it in GitHub Desktop.
Save automaticalldramatic/b29ac50c577e726a244e522393b6a1ef to your computer and use it in GitHub Desktop.
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