Skip to content

Commit 536179c

Browse files
authored
remove ktorfit and combine suspend/future/promise implementations into one (#138)
1 parent 2eddd84 commit 536179c

File tree

30 files changed

+853
-1876
lines changed

30 files changed

+853
-1876
lines changed

build.gradle.kts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.vanniktech.maven.publish.SonatypeHost
44
import fr.brouillard.oss.jgitver.Strategies
5+
import love.forte.plugin.suspendtrans.configuration.SuspendTransformConfigurations.kotlinJsExportIgnoreClassInfo
56
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
67
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
78
import ru.vyarus.gradle.plugin.mkdocs.task.MkdocsTask
@@ -17,8 +18,7 @@ plugins {
1718
alias(libs.plugins.dokka)
1819
alias(libs.plugins.mkdocs)
1920
alias(libs.plugins.jgitver)
20-
alias(libs.plugins.ksp)
21-
alias(libs.plugins.ktorfit)
21+
alias(libs.plugins.suspendTransformCompiler)
2222
id("maven-publish")
2323
}
2424

@@ -85,7 +85,6 @@ kotlin {
8585
implementation(libs.kotlinx.serialization.json)
8686
implementation(libs.ktor.client.content.negotiation)
8787
implementation(libs.ktor.serialization.kotlinx.json)
88-
implementation(libs.ktorfit)
8988
}
9089

9190
val nonJsMain by creating { dependsOn(commonMain.get()) }
@@ -123,8 +122,13 @@ kotlin {
123122
}
124123
}
125124

126-
// Gradle complains if we don't have this; unclear why.
127-
tasks.getByName("sourcesJar").dependsOn("kspCommonMainKotlinMetadata")
125+
suspendTransformPlugin {
126+
transformers {
127+
addJvmAsync()
128+
addJvmBlocking()
129+
addJsPromise { addCopyAnnotationExclude { from(kotlinJsExportIgnoreClassInfo) } }
130+
}
131+
}
128132

129133
// Standalone mode is missing certificates, which causes our LiveTest to fail.
130134
// This should resolve it but requires us to start the simulator(s) beforehand.

demo-app/src/commonMain/kotlin/co/pokeapi/pokekotlin/demoapp/DemoApp.kt

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
package co.pokeapi.pokekotlin.demoapp
22

33
import androidx.compose.foundation.clickable
4-
import androidx.compose.foundation.layout.Box
5-
import androidx.compose.foundation.layout.PaddingValues
6-
import androidx.compose.foundation.layout.consumeWindowInsets
7-
import androidx.compose.foundation.layout.fillMaxSize
8-
import androidx.compose.foundation.layout.padding
4+
import androidx.compose.foundation.layout.*
95
import androidx.compose.foundation.lazy.LazyColumn
106
import androidx.compose.foundation.lazy.items
11-
import androidx.compose.material3.CircularProgressIndicator
12-
import androidx.compose.material3.ColorScheme
13-
import androidx.compose.material3.ListItem
14-
import androidx.compose.material3.MaterialTheme
15-
import androidx.compose.material3.Scaffold
16-
import androidx.compose.material3.Text
17-
import androidx.compose.material3.TopAppBar
18-
import androidx.compose.runtime.Composable
19-
import androidx.compose.runtime.LaunchedEffect
20-
import androidx.compose.runtime.getValue
21-
import androidx.compose.runtime.mutableStateOf
22-
import androidx.compose.runtime.remember
23-
import androidx.compose.runtime.setValue
7+
import androidx.compose.material3.*
8+
import androidx.compose.runtime.*
249
import androidx.compose.ui.Alignment
2510
import androidx.compose.ui.Modifier
2611
import androidx.compose.ui.text.style.TextOverflow
@@ -67,7 +52,7 @@ fun PokemonList(padding: PaddingValues, pokemon: NamedApiResourceList) {
6752
LazyColumn(contentPadding = padding) {
6853
items(pokemon.results) { summary ->
6954
var result by remember { mutableStateOf<Result<PokemonSpecies>?>(null) }
70-
LaunchedEffect(Unit) { result = PokeApi.getPokemonSpecies(summary.id) }
55+
LaunchedEffect(Unit) { result = runCatching { PokeApi.getPokemonSpecies(summary.id) } }
7156
result
7257
?.onSuccess { PokemonListItem(it) }
7358
?.onFailure { PokemonListItemError(summary, it.message ?: "Unknown error") }
@@ -104,16 +89,15 @@ fun DemoApp() {
10489
topBar = { TopAppBar(title = { Text("PokeKotlin Demo") }) },
10590
content = { innerPadding ->
10691
var result by remember { mutableStateOf<Result<NamedApiResourceList>?>(null) }
107-
LaunchedEffect(Unit) { result = PokeApi.getPokemonSpeciesList(0, 100000) }
108-
when {
109-
result == null -> CenteredLoading(innerPadding)
110-
result!!.isSuccess -> PokemonList(innerPadding, result!!.getOrThrow())
111-
result!!.isFailure ->
92+
LaunchedEffect(Unit) { result = runCatching { PokeApi.getPokemonSpeciesList(0, 100000) } }
93+
result
94+
?.onSuccess { PokemonList(innerPadding, it) }
95+
?.onFailure {
11296
ErrorMessage(
11397
padding = innerPadding,
11498
message = result!!.exceptionOrNull()!!.message ?: "Unknown error",
11599
)
116-
}
100+
} ?: CenteredLoading(innerPadding)
117101
},
118102
)
119103
}

gradle/libs.versions.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ ktor = "3.1.3"
99
gradle-android = "8.7.2"
1010
gradle-compose = "1.8.1"
1111
gradle-kotlin = "2.1.21"
12-
gradle-ksp = "2.1.21-2.0.1" # first part is Kotlin version
13-
gradle-ktorfit = "2.5.2"
1412
gradle-dokka = "2.0.0"
1513
gradle-jgitver = "0.10.0-rc03"
1614
gradle-mavenPublish = "0.32.0"
1715
gradle-mkdocs = "4.0.1"
1816
gradle-spotless = "7.0.4"
17+
gradle-suspendTransformCompiler = "2.1.20-0.12.0"
1918
tool-prettier = "3.5.3"
2019

2120
[libraries]
@@ -26,7 +25,6 @@ kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutine
2625
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" }
2726
kotlinx-io = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.ref = "kotlinx-io" }
2827
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
29-
ktorfit = { module = "de.jensklingenberg.ktorfit:ktorfit-lib", version.ref = "gradle-ktorfit" }
3028
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
3129
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
3230
ktor-client-winhttp = { module = "io.ktor:ktor-client-winhttp", version.ref = "ktor" }
@@ -44,8 +42,7 @@ jgitver = { id = "fr.brouillard.oss.gradle.jgitver", version.ref = "gradle-jgitv
4442
kotlin-composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "gradle-kotlin" }
4543
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "gradle-kotlin" }
4644
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "gradle-kotlin" }
47-
ksp = { id = "com.google.devtools.ksp", version.ref = "gradle-ksp" }
48-
ktorfit = { id = "de.jensklingenberg.ktorfit", version.ref = "gradle-ktorfit" }
4945
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "gradle-mavenPublish" }
5046
mkdocs = { id = "ru.vyarus.mkdocs-build", version.ref = "gradle-mkdocs" }
5147
spotless = { id = "com.diffplug.spotless", version.ref = "gradle-spotless" }
48+
suspendTransformCompiler = { id = "love.forte.plugin.suspend-transform", version.ref = "gradle-suspendTransformCompiler" }

0 commit comments

Comments
 (0)