File tree Expand file tree Collapse file tree 3 files changed +7
-6
lines changed
androidMain/kotlin/dev/teamhub/firebase/database
commonMain/kotlin/dev/teamhub/firebase/database
jsMain/kotlin/dev/teamhub/firebase/database Expand file tree Collapse file tree 3 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ import kotlinx.coroutines.flow.callbackFlow
12
12
import kotlinx.coroutines.tasks.await
13
13
import kotlinx.serialization.DeserializationStrategy
14
14
import kotlinx.serialization.SerializationStrategy
15
- import kotlinx.serialization.serializer
16
15
17
16
actual val Firebase .database
18
17
get() = FirebaseDatabase (com.google.firebase.database.FirebaseDatabase .getInstance())
@@ -54,8 +53,8 @@ actual class DatabaseReference internal constructor(val android: com.google.fire
54
53
awaitClose { android.removeEventListener(listener) }
55
54
}
56
55
57
- actual suspend inline fun < reified T : Any > setValue (value : T ) =
58
- android.setValue(encode(T :: class .serializer(), value)).await().run { Unit }
56
+ actual suspend fun setValue (value : Any? ) =
57
+ android.setValue(encode(value)).await().run { Unit }
59
58
60
59
actual suspend inline fun <reified T > setValue (strategy : SerializationStrategy <T >, value : T ) =
61
60
android.setValue(encode(strategy, value)).await().run { Unit }
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ expect class DatabaseReference {
30
30
fun onDisconnect (): OnDisconnect
31
31
val snapshots: Flow <DataSnapshot >
32
32
@ImplicitReflectionSerializer
33
- suspend inline fun < reified T : Any > setValue (value : T )
33
+ suspend fun setValue (value : Any? )
34
34
suspend inline fun <reified T > setValue (strategy : SerializationStrategy <T >, value : T )
35
35
@ImplicitReflectionSerializer
36
36
suspend fun updateChildren (update : Map <String , Any ?>)
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import kotlinx.serialization.DynamicObjectParser
11
11
import kotlinx.serialization.SerializationStrategy
12
12
import kotlinx.serialization.json.Json
13
13
import kotlinx.serialization.json.JsonConfiguration
14
+ import kotlinx.serialization.modules.getContextualOrDefault
14
15
import kotlinx.serialization.stringify
15
16
16
17
actual val Firebase .database
@@ -43,8 +44,9 @@ actual class DatabaseReference internal constructor(val js: firebase.database.Re
43
44
44
45
actual suspend fun removeValue () = rethrow { js.remove().await() }
45
46
46
- actual suspend inline fun <reified T : Any > setValue (value : T ) =
47
- rethrow { js.set(JSON .parse(json.stringify(value))).await() }
47
+ actual suspend fun setValue (value : Any? ) = rethrow {
48
+ js.set(value?.let { JSON .parse<Any >(json.stringify(json.context.getContextualOrDefault(value), it)) }).await()
49
+ }
48
50
49
51
actual suspend inline fun <reified T > setValue (strategy : SerializationStrategy <T >, value : T ) =
50
52
rethrow { js.set(JSON .parse(json.stringify(strategy, value))).await() }
You can’t perform that action at this time.
0 commit comments