Skip to content

Commit f6b41ca

Browse files
committed
Removed IllegalStateException
1 parent 96df881 commit f6b41ca

File tree

2 files changed

+9
-55
lines changed
  • firebase-firestore/src
    • commonMain/kotlin/dev/gitlive/firebase/firestore
    • commonTest/kotlin/dev/gitlive/firebase/firestore

2 files changed

+9
-55
lines changed

firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package dev.gitlive.firebase.firestore
66

77
import dev.gitlive.firebase.*
88
import kotlinx.coroutines.flow.Flow
9-
import kotlinx.coroutines.flow.MutableStateFlow
109
import kotlinx.coroutines.flow.map
1110
import kotlinx.serialization.DeserializationStrategy
1211
import 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

12189
expect class FirebaseFirestoreSettings {

firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import kotlin.test.AfterTest
2828
import kotlin.test.BeforeTest
2929
import kotlin.test.Test
3030
import kotlin.test.assertEquals
31-
import kotlin.test.assertFailsWith
3231
import kotlin.test.assertNotEquals
3332
import kotlin.test.assertNotNull
3433
import kotlin.test.assertNull
@@ -720,19 +719,6 @@ class FirebaseFirestoreTest {
720719
assertEquals(updatedData.documentReference.path, updatedSavedData.documentReference.path)
721720
}
722721

723-
@Test
724-
fun testUpdateSettings() = runTest {
725-
firestore.settings = firestoreSettings(firestore.settings) {
726-
cacheSettings = persistentCacheSettings { }
727-
}
728-
firestore.enableNetwork()
729-
assertFailsWith<IllegalStateException> {
730-
firestore.settings = firestoreSettings(firestore.settings) {
731-
cacheSettings = memoryCacheSettings { }
732-
}
733-
}
734-
}
735-
736722
@Serializable
737723
data class TestDataWithDocumentReference(
738724
val uid: String,

0 commit comments

Comments
 (0)