Skip to content

Commit 7832603

Browse files
committed
Update samples to 0.8.0
1 parent 1ac8b67 commit 7832603

File tree

26 files changed

+63
-93
lines changed

26 files changed

+63
-93
lines changed

samples/ktor-all-platforms-app/composeApp/build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
66
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
77
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
8-
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
98
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
109

1110
plugins {
@@ -17,9 +16,9 @@ plugins {
1716
}
1817

1918
kotlin {
20-
@OptIn(ExperimentalWasmDsl::class)
19+
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalWasmDsl::class)
2120
wasmJs {
22-
moduleName = "composeApp"
21+
outputModuleName = "composeApp"
2322
browser {
2423
val projectDirPath = project.projectDir.path
2524
commonWebpackConfig {

samples/ktor-all-platforms-app/composeApp/src/commonMain/kotlin/App.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import kotlinx.rpc.krpc.ktor.client.installKrpc
1818
import kotlinx.rpc.krpc.ktor.client.rpc
1919
import kotlinx.rpc.krpc.ktor.client.rpcConfig
2020
import kotlinx.rpc.krpc.serialization.json.json
21-
import kotlinx.rpc.krpc.streamScoped
2221
import kotlinx.rpc.withService
2322
import ktor_all_platforms_app.composeapp.generated.resources.Res
2423
import ktor_all_platforms_app.composeapp.generated.resources.compose_multiplatform

samples/ktor-all-platforms-app/gradle/libs.versions.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[versions]
2-
kotlin = "2.1.21"
2+
kotlin = "2.2.0"
33

4-
agp = "8.11.0"
5-
android-compileSdk = "35"
4+
agp = "8.11.0-alpha07"
5+
android-compileSdk = "36"
66
android-minSdk = "24"
7-
android-targetSdk = "35"
7+
android-targetSdk = "36"
88
androidx-activityCompose = "1.10.1"
99
androidx-appcompat = "1.7.1"
1010
androidx-constraintlayout = "2.2.1"
@@ -15,11 +15,11 @@ androidx-test-junit = "1.2.1"
1515
compose = "1.8.3"
1616
compose-plugin = "1.8.2"
1717
junit = "4.13.2"
18-
ktor = "3.2.0"
18+
ktor = "3.1.3"
1919
logback = "1.5.18"
2020
serialization = "1.8.1"
2121
coroutines = "1.10.2"
22-
kotlinx-rpc = "0.7.0"
22+
kotlinx-rpc = "0.8.0"
2323

2424
[libraries]
2525
# kotlin

samples/ktor-all-platforms-app/server/src/main/kotlin/kotlinx/rpc/sample/Application.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fun Application.module() {
3030
}
3131
}
3232

33-
registerService<UserService> { ctx -> UserServiceImpl(ctx) }
33+
registerService<UserService> { UserServiceImpl() }
3434
}
3535
}
3636
}

samples/ktor-all-platforms-app/server/src/main/kotlin/kotlinx/rpc/sample/UserServiceImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.Flow
1111
import kotlinx.coroutines.flow.flow
1212
import kotlin.coroutines.CoroutineContext
1313

14-
class UserServiceImpl(override val coroutineContext: CoroutineContext) : UserService {
14+
class UserServiceImpl : UserService {
1515
override suspend fun hello(user: String, userData: UserData): String {
1616
return "Nice to meet you $user, how is it in ${userData.address}?"
1717
}

samples/ktor-all-platforms-app/server/src/test/kotlin/kotlinx/rpc/sample/ApplicationTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ import kotlinx.rpc.krpc.ktor.client.installKrpc
1212
import kotlinx.rpc.krpc.ktor.client.rpc
1313
import kotlinx.rpc.krpc.ktor.client.rpcConfig
1414
import kotlinx.rpc.krpc.serialization.json.json
15-
import kotlinx.rpc.krpc.streamScoped
1615
import kotlinx.rpc.withService
1716
import kotlin.test.Test
1817
import kotlin.test.assertEquals
1918

2019
class ApplicationTest {
2120
@Test
2221
fun testRoot() = testApplication {
22+
application {
23+
module()
24+
}
25+
2326
val service = createClient {
2427
installKrpc()
2528
}.rpc("/api") {

samples/ktor-all-platforms-app/shared/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*/
44

55
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
6+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
67
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
7-
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
88
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
99

1010
plugins {

samples/ktor-all-platforms-app/shared/src/commonMain/kotlin/UserService.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
import kotlinx.coroutines.flow.Flow
6-
import kotlinx.rpc.RemoteService
76
import kotlinx.rpc.annotations.Rpc
87
import kotlinx.serialization.Serializable
98

@@ -14,7 +13,7 @@ data class UserData(
1413
)
1514

1615
@Rpc
17-
interface UserService : RemoteService {
16+
interface UserService {
1817
suspend fun hello(user: String, userData: UserData): String
1918

2019
fun subscribeToNews(): Flow<String>

samples/ktor-android-app/app/src/main/kotlin/kotlinx/rpc/sample/data/Client.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlinx.rpc.krpc.ktor.client.rpc
1313
import kotlinx.rpc.krpc.ktor.client.rpcConfig
1414
import kotlinx.rpc.krpc.serialization.json.json
1515

16-
suspend fun createRpcClient(): RpcClient {
16+
fun createRpcClient(): RpcClient {
1717
return HttpClient(OkHttp) {
1818
installKrpc()
1919
}.rpc {

samples/ktor-android-app/app/src/main/kotlin/kotlinx/rpc/sample/ui/AppViewModel.kt

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package kotlinx.rpc.sample.ui
66

77
import androidx.lifecycle.ViewModel
88
import androidx.lifecycle.viewModelScope
9+
import kotlinx.coroutines.CoroutineScope
910
import kotlinx.rpc.sample.data.createRpcClient
1011
import kotlinx.rpc.sample.ui.state.WelcomeData
1112
import kotlinx.coroutines.Dispatchers
@@ -15,49 +16,40 @@ import kotlinx.coroutines.flow.MutableStateFlow
1516
import kotlinx.coroutines.flow.StateFlow
1617
import kotlinx.coroutines.launch
1718
import kotlinx.rpc.RpcClient
18-
import kotlinx.rpc.krpc.streamScoped
1919
import kotlinx.rpc.withService
2020
import kotlinx.rpc.sample.MyService
2121
import kotlinx.rpc.sample.UserData
2222

2323
class AppViewModel : ViewModel() {
24-
private var rpcClient: RpcClient? = null
25-
private var apiService: MyService? = null
24+
private val rpcClient: RpcClient = createRpcClient()
25+
private val apiService: MyService = rpcClient.withService<MyService>()
2626

2727
private val _uiState = MutableStateFlow<WelcomeData?>(null)
2828
val uiState: StateFlow<WelcomeData?> = _uiState
2929

3030
init {
3131
viewModelScope.launch(Dispatchers.IO) {
32-
rpcClient = createRpcClient()
33-
rpcClient?.let {
34-
apiService = it.withService()
35-
fetchData()
36-
}
32+
fetchData()
3733
}
3834
}
3935

40-
private fun fetchData() {
41-
viewModelScope.launch(Dispatchers.IO) {
42-
delay(2000)
43-
val greetingDeferred = async {
44-
apiService?.hello(
45-
"Alex",
46-
UserData("Berlin", "Smith")
47-
)
48-
}
49-
50-
val serverGreeting = greetingDeferred.await()
51-
52-
val allNews: MutableList<String> = mutableListOf()
53-
apiService?.subscribeToNews()?.collect {
54-
allNews += it
55-
56-
val sendNews = allNews.toMutableList() // fix ConcurrentModificationException
57-
serverGreeting?.let {
58-
_uiState.value = WelcomeData(serverGreeting, sendNews)
59-
}
60-
}
36+
private suspend fun CoroutineScope.fetchData() {
37+
delay(2000)
38+
val greetingDeferred = async {
39+
apiService.hello(
40+
"Alex",
41+
UserData("Berlin", "Smith")
42+
)
43+
}
44+
45+
val serverGreeting = greetingDeferred.await()
46+
47+
val allNews: MutableList<String> = mutableListOf()
48+
apiService.subscribeToNews().collect {
49+
allNews += it
50+
51+
val sendNews = allNews.toMutableList() // fix ConcurrentModificationException
52+
_uiState.value = WelcomeData(serverGreeting, sendNews)
6153
}
6254
}
6355
}

samples/ktor-android-app/common/src/main/kotlin/kotlinx/rpc/sample/MyService.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
package kotlinx.rpc.sample
66

77
import kotlinx.coroutines.flow.Flow
8-
import kotlinx.rpc.RemoteService
98
import kotlinx.rpc.annotations.Rpc
109

1110
@Rpc
12-
interface MyService : RemoteService {
11+
interface MyService {
1312
suspend fun hello(user: String, userData: UserData): String
1413

1514
fun subscribeToNews(): Flow<String>

samples/ktor-android-app/gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
2-
agp = "8.11.0"
3-
kotlin = "2.1.21"
2+
agp = "8.11.0-alpha07"
3+
kotlin = "2.2.0"
44
androidx-activityCompose = "1.10.1"
55
androidx-appcompat = "1.7.1"
66
androidx-constraintlayout = "2.2.1"
@@ -15,7 +15,7 @@ ktor = "3.2.0"
1515
kotlinx-serialization-json = "1.8.1"
1616
kotlinx-coroutines-core = "1.10.2"
1717
logback = "1.5.18"
18-
kotlinx-rpc = "0.7.0"
18+
kotlinx-rpc = "0.8.0"
1919

2020
[libraries]
2121
# kotlin

samples/ktor-android-app/server/src/main/kotlin/kotlinx/rpc/sample/Application.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fun Application.module() {
2424
}
2525
}
2626

27-
registerService<MyService> { ctx -> MyServiceImpl(ctx) }
27+
registerService<MyService> { MyServiceImpl() }
2828
}
2929
}
3030
}

samples/ktor-android-app/server/src/main/kotlin/kotlinx/rpc/sample/MyServiceImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.Flow
99
import kotlinx.coroutines.flow.flow
1010
import kotlin.coroutines.CoroutineContext
1111

12-
class MyServiceImpl(override val coroutineContext: CoroutineContext) : MyService {
12+
class MyServiceImpl : MyService {
1313
override suspend fun hello(user: String, userData: UserData): String {
1414
return "Nice to meet you $user, how is it in ${userData.address}?"
1515
}
@@ -22,4 +22,4 @@ class MyServiceImpl(override val coroutineContext: CoroutineContext) : MyService
2222
}
2323
}
2424
}
25-
}
25+
}

samples/ktor-web-app/common/src/commonMain/kotlin/Common.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
import kotlinx.coroutines.flow.Flow
6-
import kotlinx.rpc.RemoteService
76
import kotlinx.rpc.annotations.Rpc
87
import kotlinx.serialization.Serializable
98

@@ -14,7 +13,7 @@ data class UserData(
1413
)
1514

1615
@Rpc
17-
interface MyService : RemoteService {
16+
interface MyService {
1817
suspend fun hello(user: String, userData: UserData): String
1918

2019
fun subscribeToNews(): Flow<String>

samples/ktor-web-app/frontend/src/jsMain/kotlin/App.kt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
import kotlinx.rpc.RpcClient
65
import kotlinx.rpc.withService
76
import react.FC
87
import react.Props
@@ -11,20 +10,10 @@ import react.useEffectOnce
1110
import react.useState
1211

1312
val App = FC<Props> {
14-
var rpcClient by useState<RpcClient?>(null)
13+
val rpcClient = initRpcClient()
1514

16-
useEffectOnce {
17-
rpcClient = initRpcClient()
18-
}
19-
20-
rpcClient?.also { client ->
21-
AppContainer {
22-
this.apiService = client.withService<MyService>()
23-
}
24-
} ?: run {
25-
div {
26-
+"Establishing connection..."
27-
}
15+
AppContainer {
16+
apiService = rpcClient.withService<MyService>()
2817
}
2918
}
3019

samples/ktor-web-app/frontend/src/jsMain/kotlin/RPC.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import kotlinx.rpc.krpc.ktor.client.rpc
1111
import kotlinx.rpc.krpc.ktor.client.rpcConfig
1212
import kotlinx.rpc.krpc.serialization.json.json
1313

14-
suspend fun initRpcClient(): RpcClient {
14+
fun initRpcClient(): RpcClient {
1515
return HttpClient(Js) {
1616
installKrpc()
1717
}.rpc {

samples/ktor-web-app/gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[versions]
2-
kotlin = "2.1.21"
2+
kotlin = "2.2.0"
33
kotlin-wrappers-bom = "2025.6.11"
44
ktor = "3.2.0"
55
kotlinx-serialization-json = "1.8.1"
66
kotlinx-coroutines-core = "1.10.2"
77
logback = "1.5.18"
8-
kotlinx-rpc = "0.7.0"
8+
kotlinx-rpc = "0.8.0"
99

1010
[libraries]
1111
# kotlin

samples/ktor-web-app/server/src/main/kotlin/Application.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fun Application.module() {
2828
}
2929
}
3030

31-
registerService<MyService> { ctx -> MyServiceImpl(ctx) }
31+
registerService<MyService> { MyServiceImpl() }
3232
}
3333

3434
staticResources("/", "/static") {

samples/ktor-web-app/server/src/main/kotlin/MyServiceImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import kotlinx.coroutines.delay
66
import kotlinx.coroutines.flow.Flow
77
import kotlinx.coroutines.flow.flow
8-
import kotlin.coroutines.CoroutineContext
98

10-
class MyServiceImpl(override val coroutineContext: CoroutineContext) : MyService {
9+
class MyServiceImpl : MyService {
1110
override suspend fun hello(user: String, userData: UserData): String {
1211
return "Nice to meet you $user, how is it in ${userData.address}?"
1312
}

samples/ktor-web-app/server/src/test/kotlin/ApplicationTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import kotlinx.rpc.krpc.ktor.client.installKrpc
88
import kotlinx.rpc.krpc.ktor.client.rpc
99
import kotlinx.rpc.krpc.ktor.client.rpcConfig
1010
import kotlinx.rpc.krpc.serialization.json.json
11-
import kotlinx.rpc.krpc.streamScoped
1211
import kotlinx.rpc.withService
1312
import kotlin.test.Test
1413
import kotlin.test.assertEquals

samples/simple-ktor-app/build.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ kotlin {
2828
}
2929

3030
dependencies {
31-
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-client:0.7.0")
32-
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-server:0.7.0")
33-
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-serialization-json:0.7.0")
31+
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-client:0.8.0")
32+
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-server:0.8.0")
33+
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-serialization-json:0.8.0")
3434

35-
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-ktor-client:0.7.0")
36-
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-ktor-server:0.7.0")
35+
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-ktor-client:0.8.0")
36+
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-ktor-server:0.8.0")
3737

3838
implementation("io.ktor:ktor-client-cio")
3939
implementation("io.ktor:ktor-server-netty-jvm")
4040
implementation("ch.qos.logback:logback-classic:1.5.18")
4141

4242
testImplementation("io.ktor:ktor-server-test-host")
43-
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:2.1.21")
43+
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:2.2.0")
4444
}

0 commit comments

Comments
 (0)