
iosMain.com.estiven.firebase_firestore.DocumentReference.kt Maven / Gradle / Ivy
Go to download
FirebaseKMM is a Firebase Extension that supports cross-platform projects also based on Firebase Kotlin SDK, allowing you to directly from iOS and Android.
package com.estiven.firebase_firestore
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
actual class DocumentReference(val iOS: NativeDocumentReference) {
actual val id
get() = iOS.documentID
actual val parent
get() = CollectionReference(iOS.parent)
actual val path
get() = iOS.path
actual val firestore
get() = FirebaseFirestore(iOS.firestore)
actual suspend fun delete() = await { iOS.deleteDocumentWithCompletion(it) }
@Suppress("UNCHECKED_CAST")
actual suspend fun set(data: Any) = iOS.setData(data as Map)
actual suspend fun update(data: MutableMap) =
await { iOS.updateData(data.toMap(), it) }
actual suspend fun get() =
DocumentSnapshot(awaitResult { iOS.getDocumentWithCompletion(it) })
actual suspend fun get(source: Source) =
DocumentSnapshot(awaitResult { iOS.getDocumentWithSource(source, it) })
actual fun collection(collectionPath: String) =
CollectionReference(iOS.collectionWithPath(collectionPath))
actual val snapshotListener
get() = callbackFlow {
val listener = iOS.addSnapshotListener { firDocumentSnapshot, nsError ->
if (nsError != null) close(Exception(nsError.toString()))
if (firDocumentSnapshot != null) trySend(DocumentSnapshot(firDocumentSnapshot))
}
awaitClose { listener.remove() }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy