@@ -6,7 +6,6 @@ package dev.gitlive.firebase.firestore
66
77import dev.gitlive.firebase.*
88import kotlinx.coroutines.flow.Flow
9- import kotlinx.coroutines.flow.MutableStateFlow
109import kotlinx.coroutines.flow.map
1110import kotlinx.serialization.DeserializationStrategy
1211import kotlinx.serialization.Serializable
@@ -52,30 +51,13 @@ class FirebaseFirestore internal constructor(private val wrapper: NativeFirebase
5251 }
5352 }
5453
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 )) }
7961 fun useEmulator (host : String , port : Int ) = wrapper.useEmulator(host, port)
8062 @Deprecated(" Use settings instead" , replaceWith = ReplaceWith (" settings = firestoreSettings{}" ))
8163 fun setSettings (
@@ -100,22 +82,8 @@ class FirebaseFirestore internal constructor(private val wrapper: NativeFirebase
10082 }
10183 }
10284 }
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()
11987}
12088
12189expect class FirebaseFirestoreSettings {
0 commit comments