diff --git a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/MutableStoreBuilder.kt b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/MutableStoreBuilder.kt index b40b86cc6..860b80c64 100644 --- a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/MutableStoreBuilder.kt +++ b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/MutableStoreBuilder.kt @@ -43,10 +43,10 @@ interface MutableStoreBuilder from( + fun from( fetcher: Fetcher, - sourceOfTruth: SourceOfTruth - ): MutableStoreBuilder = + sourceOfTruth: SourceOfTruth + ): MutableStoreBuilder = mutableStoreBuilderFromFetcherAndSourceOfTruth(fetcher = fetcher, sourceOfTruth = sourceOfTruth) } } \ No newline at end of file diff --git a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreBuilder.kt b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreBuilder.kt index d61cfe00f..a5a8407b7 100644 --- a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreBuilder.kt +++ b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreBuilder.kt @@ -25,6 +25,9 @@ import org.mobilenativefoundation.store.store5.impl.storeBuilderFromFetcherAndSo interface StoreBuilder { fun build(): Store + + fun toMutableStoreBuilder(): MutableStoreBuilder + /** * A store multicasts same [Output] value to many consumers (Similar to RxJava.share()), by default * [Store] will open a global scope for management of shared responses, if instead you'd like to control diff --git a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealMutableStoreBuilder.kt b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealMutableStoreBuilder.kt index 3edd67bf2..b532e10b7 100644 --- a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealMutableStoreBuilder.kt +++ b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealMutableStoreBuilder.kt @@ -16,12 +16,16 @@ import org.mobilenativefoundation.store.store5.Validator import org.mobilenativefoundation.store.store5.impl.extensions.asMutableStore -fun mutableStoreBuilderFromFetcherAndSourceOfTruth( +fun mutableStoreBuilderFromFetcher( + fetcher: Fetcher, +): MutableStoreBuilder = RealMutableStoreBuilder(fetcher) + + +fun mutableStoreBuilderFromFetcherAndSourceOfTruth( fetcher: Fetcher, sourceOfTruth: SourceOfTruth, ): MutableStoreBuilder = RealMutableStoreBuilder(fetcher, sourceOfTruth) - internal class RealMutableStoreBuilder( private val fetcher: Fetcher, private val sourceOfTruth: SourceOfTruth? = null, diff --git a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStoreBuilder.kt b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStoreBuilder.kt index 0158069a3..b07b5ff01 100644 --- a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStoreBuilder.kt +++ b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStoreBuilder.kt @@ -1,3 +1,5 @@ +@file:Suppress("UNCHECKED_CAST") + package org.mobilenativefoundation.store.store5.impl import kotlinx.coroutines.CoroutineScope @@ -5,6 +7,7 @@ import kotlinx.coroutines.GlobalScope import org.mobilenativefoundation.store.store5.Converter import org.mobilenativefoundation.store.store5.Fetcher import org.mobilenativefoundation.store.store5.MemoryPolicy +import org.mobilenativefoundation.store.store5.MutableStoreBuilder import org.mobilenativefoundation.store.store5.SourceOfTruth import org.mobilenativefoundation.store.store5.Store import org.mobilenativefoundation.store.store5.StoreBuilder @@ -60,4 +63,39 @@ internal class RealStoreBuilder toMutableStoreBuilder(): MutableStoreBuilder { + val storeBuilder = this + fetcher as Fetcher + return if (sourceOfTruth == null) { + mutableStoreBuilderFromFetcher(fetcher).apply { + if (storeBuilder.scope != null) { + scope(storeBuilder.scope!!) + } + + if (storeBuilder.cachePolicy != null) { + cachePolicy(storeBuilder.cachePolicy) + } + + if (storeBuilder.validator != null) { + validator(storeBuilder.validator!!) + } + } + } else { + sourceOfTruth as SourceOfTruth + mutableStoreBuilderFromFetcherAndSourceOfTruth(fetcher, sourceOfTruth).apply { + if (storeBuilder.scope != null) { + scope(storeBuilder.scope!!) + } + + if (storeBuilder.cachePolicy != null) { + cachePolicy(storeBuilder.cachePolicy) + } + + if (storeBuilder.validator != null) { + validator(storeBuilder.validator!!) + } + } + } + } }