From 3890689f5cae7a8cd04c325f7e4b167781ac1892 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 17 Nov 2022 21:13:51 +0300 Subject: [PATCH] minor refactoring --- build.gradle.kts | 2 +- src/commonMain/kotlin/model.kt | 6 ++++-- src/jsMain/kotlin/client.kt | 6 ++++-- .../{center.sciprog.application => }/server.kt | 13 +++++-------- 4 files changed, 14 insertions(+), 13 deletions(-) rename src/jvmMain/kotlin/{center.sciprog.application => }/server.kt (88%) diff --git a/build.gradle.kts b/build.gradle.kts index 6592ab3..615a9a2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,6 @@ group = "center.sciprog" version = "1.0-SNAPSHOT" repositories { - jcenter() mavenCentral() maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") } @@ -72,6 +71,7 @@ application { tasks.named("jvmProcessResources") { val jsBrowserDistribution = tasks.named("jsBrowserDistribution") + include("*.js") from(jsBrowserDistribution) } diff --git a/src/commonMain/kotlin/model.kt b/src/commonMain/kotlin/model.kt index 48d1f5f..102236a 100644 --- a/src/commonMain/kotlin/model.kt +++ b/src/commonMain/kotlin/model.kt @@ -1,13 +1,15 @@ +package fullstack.kotlin.demo + import kotlinx.serialization.Serializable @Serializable sealed interface ControlEvent @Serializable -data class IntControlEvent(val value: Int) : ControlEvent +data class CounterControlEvent(val value: Int) : ControlEvent @Serializable sealed interface DataEvent @Serializable -data class IntDataEvent(val value: Int) : DataEvent \ No newline at end of file +data class CounterDataEvent(val value: Int) : DataEvent \ No newline at end of file diff --git a/src/jsMain/kotlin/client.kt b/src/jsMain/kotlin/client.kt index 1882411..58feb53 100644 --- a/src/jsMain/kotlin/client.kt +++ b/src/jsMain/kotlin/client.kt @@ -1,3 +1,5 @@ +package fullstack.kotlin.demo + import androidx.compose.runtime.* import io.ktor.client.engine.js.Js import io.rsocket.kotlin.RSocket @@ -50,14 +52,14 @@ suspend fun main() { fun setCount(value: Int) { count = value scope.launch { - sendEvent(IntControlEvent(value)) + sendEvent(CounterControlEvent(value)) } } LaunchedEffect(Unit){ dataFlow.onEach { event -> println("Received $event") - if (event is IntDataEvent) { + if (event is CounterDataEvent) { count = event.value } }.launchIn(scope) diff --git a/src/jvmMain/kotlin/center.sciprog.application/server.kt b/src/jvmMain/kotlin/server.kt similarity index 88% rename from src/jvmMain/kotlin/center.sciprog.application/server.kt rename to src/jvmMain/kotlin/server.kt index 977e957..0ffa857 100644 --- a/src/jvmMain/kotlin/center.sciprog.application/server.kt +++ b/src/jvmMain/kotlin/server.kt @@ -1,9 +1,5 @@ -package center.sciprog.application +package fullstack.kotlin.demo -import ControlEvent -import DataEvent -import IntControlEvent -import IntDataEvent import io.ktor.http.HttpStatusCode import io.ktor.server.application.call import io.ktor.server.application.install @@ -54,9 +50,9 @@ fun main() { controlFlow.onEach { event -> println("Received $event") - if (event is IntControlEvent) { + if (event is CounterControlEvent) { counterState = event.value - dataFlow.emit(IntDataEvent(event.value)) + dataFlow.emit(CounterDataEvent(event.value)) } }.launchIn(this) @@ -78,7 +74,8 @@ fun main() { } //handler for request/stream requestStream { _: Payload -> - merge(flowOf(IntDataEvent(counterState)), dataFlow).map { event -> + merge(flowOf(CounterDataEvent(counterState)), dataFlow).map { event -> + println("Sent $event") buildPayload { data(Json.encodeToString(event)) }