@@ -6,7 +6,6 @@ package dev.gitlive.firebase.firestore
6
6
7
7
import dev.gitlive.firebase.*
8
8
import kotlinx.coroutines.flow.Flow
9
- import kotlinx.coroutines.flow.MutableStateFlow
10
9
import kotlinx.coroutines.flow.map
11
10
import kotlinx.serialization.DeserializationStrategy
12
11
import kotlinx.serialization.Serializable
@@ -52,30 +51,13 @@ class FirebaseFirestore internal constructor(private val wrapper: NativeFirebase
52
51
}
53
52
}
54
53
55
- // Should probably use atomic from atomicfu
56
- private val isConfigured = MutableStateFlow (false )
57
-
58
- fun collection (collectionPath : String ): CollectionReference = ensureConfigured {
59
- CollectionReference (wrapper.collection(collectionPath))
60
- }
61
- fun collectionGroup (collectionId : String ): Query = ensureConfigured {
62
- Query (wrapper.collectionGroup(collectionId))
63
- }
64
- fun document (documentPath : String ): DocumentReference = ensureConfigured {
65
- DocumentReference (wrapper.document(documentPath))
66
- }
67
- fun batch (): WriteBatch = ensureConfigured {
68
- WriteBatch (wrapper.batch())
69
- }
70
- fun setLoggingEnabled (loggingEnabled : Boolean ) = ensureConfigured {
71
- wrapper.setLoggingEnabled(loggingEnabled)
72
- }
73
- suspend fun clearPersistence () = ensureConfiguredSuspended {
74
- wrapper.clearPersistence()
75
- }
76
- suspend fun <T > runTransaction (func : suspend Transaction .() -> T ): T = ensureConfiguredSuspended {
77
- wrapper.runTransaction { func(Transaction (this )) }
78
- }
54
+ fun collection (collectionPath : String ): CollectionReference = CollectionReference (wrapper.collection(collectionPath))
55
+ fun collectionGroup (collectionId : String ): Query = Query (wrapper.collectionGroup(collectionId))
56
+ fun document (documentPath : String ): DocumentReference = DocumentReference (wrapper.document(documentPath))
57
+ fun batch (): WriteBatch = WriteBatch (wrapper.batch())
58
+ fun setLoggingEnabled (loggingEnabled : Boolean ) = wrapper.setLoggingEnabled(loggingEnabled)
59
+ suspend fun clearPersistence () = wrapper.clearPersistence()
60
+ suspend fun <T > runTransaction (func : suspend Transaction .() -> T ): T = wrapper.runTransaction { func(Transaction (this )) }
79
61
fun useEmulator (host : String , port : Int ) = wrapper.useEmulator(host, port)
80
62
@Deprecated(" Use settings instead" , replaceWith = ReplaceWith (" settings = firestoreSettings{}" ))
81
63
fun setSettings (
@@ -100,22 +82,8 @@ class FirebaseFirestore internal constructor(private val wrapper: NativeFirebase
100
82
}
101
83
}
102
84
}
103
- suspend fun disableNetwork () = ensureConfiguredSuspended {
104
- wrapper.disableNetwork()
105
- }
106
- suspend fun enableNetwork () = ensureConfiguredSuspended {
107
- wrapper.enableNetwork()
108
- }
109
-
110
- private fun <T > ensureConfigured (action : () -> T ): T {
111
- isConfigured.compareAndSet(expect = false , update = true )
112
- return action()
113
- }
114
-
115
- private suspend fun <T > ensureConfiguredSuspended (action : suspend () -> T ): T {
116
- isConfigured.compareAndSet(expect = false , update = true )
117
- return action()
118
- }
85
+ suspend fun disableNetwork () = wrapper.disableNetwork()
86
+ suspend fun enableNetwork () = wrapper.enableNetwork()
119
87
}
120
88
121
89
expect class FirebaseFirestoreSettings {
0 commit comments