firebase-kotlin-sdk icon indicating copy to clipboard operation
firebase-kotlin-sdk copied to clipboard

Add toObjects/dataObjects (from Firestore KTX) to Firestore

Open EdricChan03 opened this issue 2 years ago • 0 comments
trafficstars

Library Class Member Platforms
firestore Query toObjects Android
firestore Query dataObjects Android
firestore DocumentReference dataObjects Android

I suspect these methods would be handy aliases to the following code:

inline fun <reified T> Query.toObjects() = get().documents.map { it.data<T>() }

// TODO: Implement includeMetadataChanges behaviour
inline fun <reified T> Query.dataObjects(includeMetadataChanges: Boolean) = snapshots.map {
    snapshot -> snapshot.documents.map { it.data<T>() }
}
inline fun <reified T> DocumentReference.dataObjects(includeMetadataChanges: Boolean) = snapshots.map {
    snapshot -> snapshot.data<T>()
}

EdricChan03 avatar Jul 25 '23 12:07 EdricChan03