this function is called by the constructor. can someone explain in depth to me what it does?
initializeItems(){
this.travelList$ = this.plsdala.getTravelList()
.snapshotChanges()
.map(
changes => {
return changes.map(c=>({
key: c.payload.key, ...c.payload.val()
})).slice().reverse();
//to reverse order
});
}
snapshotChanges() Metadata provides you the underyling DocumentReference , document id, and array index of the single document. Having the document's id around makes it easier to use data manipulation methods.
In Firestore, you typically have a single collection and multiple documents in that collection. To use Firestore as a key/value store for Workflows, one idea is to use the workflow name as the collection name and use a single document to store all the key/value pairs.
firestore. DocumentReference. < T > A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location.
The AngularFirestoreDocument service is a wrapper around the native Firestore SDK's DocumentReference type. It is a generic service that provides you with a strongly typed set of methods for manipulating and streaming data. This service is designed for use as an @Injectable() .
It is current state of firestore collection. It returns an Observable of data. You would use it whenever you want to be able to get also your metadata as documentID as opposed to using for example valueChanges() which returns Observable containing data saved in document only. It does not contain metadata.
This means that you would usually use valueChanges() to get data and snapshotChanges() whenever you might need metadata, eg. deleting or updating document.
Your code basically gets data and metadata of document and extracts just data from it. Then it reverses the data to go from end of the collection to the beginning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With