Last active
April 29, 2020 12:10
-
-
Save automaticalldramatic/e1e1e773662faafdecfbbb8e05452c83 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
// this method accepts the property to order by. In our example, this would be priority | |
// sortByDesc('priority') | |
sortByDesc(prop: string) { | |
return this.returnedCardsArr.sort((a, b) => a[prop] < b[prop] ? 1 : a[prop] === b[prop] ? 0 : -1); | |
} | |
// also a slightly verbose way of keeping only unique IDs replacing the ones received from the new call - cause the data also might have changed. | |
for (const card of c) { | |
if (!this.uniqueMap.has(card.id)) { | |
this.uniqueMap.set(card.id, true); | |
this.returnedCardsArr.push(card); | |
continue; | |
} | |
this.returnedCardsArr = this.returnedCardsArr.filter((foundCard) => foundCard.id !== card.id); | |
this.returnedCardsArr.push(card); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment