@@ -33,19 +33,20 @@ fun <Key : Any, Network : Any, Output : Any> storeBuilderFromFetcherSourceOfTrut
3333 sourceOfTruth : SourceOfTruth <Key , Network , Output >,
3434 memoryCache : Cache <Key , Output >,
3535): StoreBuilder <Key , Output > =
36- RealStoreBuilder (fetcher, sourceOfTruth, memoryCache)
36+ RealStoreBuilder <Key , Network , Output , Network >(fetcher, sourceOfTruth, memoryCache)
37+
38+ fun <Key : Any , Network : Any , Output : Any , Local : Any > storeBuilderFromFetcherSourceOfTruthMemoryCacheAndConverter (
39+ fetcher : Fetcher <Key , Network >,
40+ sourceOfTruth : SourceOfTruth <Key , Local , Output >,
41+ memoryCache : Cache <Key , Output >? ,
42+ converter : Converter <Network , Local , Output >,
43+ ): StoreBuilder <Key , Output > = RealStoreBuilder (fetcher, sourceOfTruth, memoryCache, converter)
3744
3845internal class RealStoreBuilder <Key : Any , Network : Any , Output : Any , Local : Any >(
3946 private val fetcher : Fetcher <Key , Network >,
4047 private val sourceOfTruth : SourceOfTruth <Key , Local , Output >? = null ,
4148 private val memoryCache : Cache <Key , Output >? = null ,
42- private val converter : Converter <Network , Local , Output > = object :
43- Converter <Network , Local , Output > {
44- override fun fromOutputToLocal(output: Output ): Local =
45- throw IllegalStateException ("non mutable store never call this function")
46-
47- override fun fromNetworkToLocal(network: Network ): Local = network as Local
48- }
49+ private val converter : Converter <Network , Local , Output >? = null
4950) : StoreBuilder<Key, Output> {
5051 private var scope: CoroutineScope ? = null
5152 private var cachePolicy: MemoryPolicy <Key , Output >? = StoreDefaults .memoryPolicy
@@ -75,7 +76,7 @@ internal class RealStoreBuilder<Key : Any, Network : Any, Output : Any, Local :
7576 scope = scope ? : GlobalScope ,
7677 sourceOfTruth = sourceOfTruth,
7778 fetcher = fetcher,
78- converter = converter,
79+ converter = converter? : defaultConverter() ,
7980 validator = validator,
8081 memCache = memoryCache ? : cachePolicy?.let {
8182 CacheBuilder <Key , Output >().apply {
@@ -132,4 +133,11 @@ internal class RealStoreBuilder<Key : Any, Network : Any, Output : Any, Local :
132133 }
133134 }
134135 }
136+
137+ private fun <Network : Any , Local : Any , Output : Any > defaultConverter () = object : Converter <Network , Local , Output > {
138+ override fun fromOutputToLocal (output : Output ): Local =
139+ throw IllegalStateException (" non mutable store never call this function" )
140+
141+ override fun fromNetworkToLocal (network : Network ): Local = network as Local
142+ }
135143}
0 commit comments