Skip to content

removed DocumentSnapshot.dataMap() #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,6 @@ actual class DocumentSnapshot(val android: com.google.firebase.firestore.Documen
actual fun <T> data(strategy: DeserializationStrategy<T>, serverTimestampBehavior: ServerTimestampBehavior): T =
decode(strategy, android.getData(serverTimestampBehavior.toAndroid()))

actual fun dataMap(serverTimestampBehavior: ServerTimestampBehavior): Map<String, Any?> =
android.getData(serverTimestampBehavior.toAndroid()) ?: emptyMap()

actual inline fun <reified T> get(field: String, serverTimestampBehavior: ServerTimestampBehavior): T =
decode(value = android.get(field, serverTimestampBehavior.toAndroid()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ expect class DocumentSnapshot {
inline fun <reified T: Any> data(serverTimestampBehavior: ServerTimestampBehavior = ServerTimestampBehavior.NONE): T
fun <T> data(strategy: DeserializationStrategy<T>, serverTimestampBehavior: ServerTimestampBehavior = ServerTimestampBehavior.NONE): T

fun dataMap(serverTimestampBehavior: ServerTimestampBehavior = ServerTimestampBehavior.NONE): Map<String, Any?>

val exists: Boolean
val id: String
val reference: DocumentReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class FirebaseFirestoreTest {
val pendingWritesSnapshot = deferredPendingWritesSnapshot.await()
assertTrue(pendingWritesSnapshot.metadata.hasPendingWrites)
assertNull(pendingWritesSnapshot.get<Double?>("time", ServerTimestampBehavior.NONE))
assertNull(pendingWritesSnapshot.dataMap(ServerTimestampBehavior.NONE)["time"])
}

@Test
Expand All @@ -181,7 +180,6 @@ class FirebaseFirestoreTest {
val pendingWritesSnapshot = deferredPendingWritesSnapshot.await()
assertTrue(pendingWritesSnapshot.metadata.hasPendingWrites)
assertNotNull(pendingWritesSnapshot.get<Double?>("time", ServerTimestampBehavior.ESTIMATE))
assertNotNull(pendingWritesSnapshot.dataMap(ServerTimestampBehavior.ESTIMATE)["time"])
assertNotEquals(0.0, pendingWritesSnapshot.data(FirestoreTest.serializer(), ServerTimestampBehavior.ESTIMATE).time)
}

Expand All @@ -203,7 +201,6 @@ class FirebaseFirestoreTest {
val pendingWritesSnapshot = deferredPendingWritesSnapshot.await()
assertTrue(pendingWritesSnapshot.metadata.hasPendingWrites)
assertNull(pendingWritesSnapshot.get<Double?>("time", ServerTimestampBehavior.PREVIOUS))
assertNull(pendingWritesSnapshot.dataMap(ServerTimestampBehavior.PREVIOUS)["time"])
}

@Test
Expand All @@ -223,23 +220,6 @@ class FirebaseFirestoreTest {
assertEquals("AutoId", resultDoc.get("prop1"))
}

@Test
fun testDataMap() = runTest {
val doc = Firebase.firestore
.collection("testDataMap")
.document

doc.set(FirestoreTest.serializer(), FirestoreTest("dataMap", 123.45))

val resultDoc = Firebase.firestore
.collection("testDataMap")
.document(doc.id)
.get()

assertEquals(true, resultDoc.exists)
assertEquals(mapOf("prop1" to "dataMap", "time" to 123.45), resultDoc.dataMap())
}

private suspend fun setupFirestoreData() {
Firebase.firestore.collection("FirebaseFirestoreTest")
.document("one")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,6 @@ actual class DocumentSnapshot(val ios: FIRDocumentSnapshot) {
return decode(strategy, data?.mapValues { (_, value) -> value?.takeIf { it !is NSNull } })
}

actual fun dataMap(serverTimestampBehavior: ServerTimestampBehavior): Map<String, Any?> =
ios.dataWithServerTimestampBehavior(serverTimestampBehavior.toIos())
?.map { (key, value) -> key.toString() to value?.takeIf { it !is NSNull } }
?.toMap()
?: emptyMap()

actual inline fun <reified T> get(field: String, serverTimestampBehavior: ServerTimestampBehavior): T {
val value = ios.valueForField(field, serverTimestampBehavior.toIos())?.takeIf { it !is NSNull }
return decode(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,6 @@ actual class DocumentSnapshot(val js: firebase.firestore.DocumentSnapshot) {
actual fun <T> data(strategy: DeserializationStrategy<T>, serverTimestampBehavior: ServerTimestampBehavior): T =
rethrow { decode(strategy, js.data(getTimestampsOptions(serverTimestampBehavior))) }

actual fun dataMap(serverTimestampBehavior: ServerTimestampBehavior): Map<String, Any?> =
rethrow { mapOf(js.data(getTimestampsOptions(serverTimestampBehavior)).asDynamic()) }

actual inline fun <reified T> get(field: String, serverTimestampBehavior: ServerTimestampBehavior) =
rethrow { decode<T>(value = js.get(field, getTimestampsOptions(serverTimestampBehavior))) }

Expand Down