Skip to content

Commit ad43e4a

Browse files
committed
Refactor remote config code
1 parent 23fa807 commit ad43e4a

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

turbo/src/main/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationLoader.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ internal class TurboPathConfigurationLoader(val context: Context) : CoroutineSco
2929
loadCachedConfigurationForUrl(url, onCompletion)
3030

3131
launch {
32-
repository.getRemoteConfiguration(url)?.let { remoteConfigJson ->
33-
repository.parseFromJson(remoteConfigJson)?.let { config ->
34-
onCompletion(config)
35-
cacheConfigurationForUrl(url, config)
36-
}
32+
repository.getRemoteConfiguration(url)?.let { config ->
33+
onCompletion(config)
34+
cacheConfigurationForUrl(url, config)
3735
}
3836
}
3937
}

turbo/src/main/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepository.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import okhttp3.Request
1616
internal class TurboPathConfigurationRepository {
1717
private val cacheFile = "turbo"
1818

19-
suspend fun getRemoteConfiguration(url: String): String? {
19+
suspend fun getRemoteConfiguration(url: String): TurboPathConfiguration? {
2020
val request = Request.Builder().url(url).build()
2121

2222
return withContext(dispatcherProvider.io) {
23-
issueRequest(request)
23+
issueRequest(request)?.let { parseFromJson(it) }
2424
}
2525
}
2626

turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepositoryTest.kt

+3-8
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ class TurboPathConfigurationRepositoryTest : BaseRepositoryTest() {
3535

3636
runBlocking {
3737
launch(Dispatchers.Main) {
38-
val json = repository.getRemoteConfiguration(baseUrl())
39-
assertThat(json).isNotNull()
40-
41-
val config = repository.parseFromJson(json!!)
38+
val config = repository.getRemoteConfiguration(baseUrl())
39+
assertThat(config).isNotNull()
4240
assertThat(config?.rules?.size).isEqualTo(2)
4341
}
4442
}
@@ -50,10 +48,7 @@ class TurboPathConfigurationRepositoryTest : BaseRepositoryTest() {
5048

5149
runBlocking {
5250
launch(Dispatchers.Main) {
53-
val json = repository.getRemoteConfiguration(baseUrl())
54-
assertThat(json).isNotNull()
55-
56-
val config = repository.parseFromJson(json!!)
51+
val config = repository.getRemoteConfiguration(baseUrl())
5752
assertThat(config).isNull()
5853
}
5954
}

0 commit comments

Comments
 (0)