diff --git a/web/src/jsMain/kotlin/ca/derekellis/reroute/home/HomeView.kt b/web/src/jsMain/kotlin/ca/derekellis/reroute/home/HomeView.kt index c268be1..8319760 100644 --- a/web/src/jsMain/kotlin/ca/derekellis/reroute/home/HomeView.kt +++ b/web/src/jsMain/kotlin/ca/derekellis/reroute/home/HomeView.kt @@ -5,7 +5,7 @@ import ca.derekellis.reroute.ui.View class HomeView : View { @Composable - override fun Content(model: Unit?, emit: (Unit) -> Unit) { + override fun Content(model: Unit, emit: (Unit) -> Unit) { /* No-op */ } } diff --git a/web/src/jsMain/kotlin/ca/derekellis/reroute/map/MapView.kt b/web/src/jsMain/kotlin/ca/derekellis/reroute/map/MapView.kt index 706785d..60c0633 100644 --- a/web/src/jsMain/kotlin/ca/derekellis/reroute/map/MapView.kt +++ b/web/src/jsMain/kotlin/ca/derekellis/reroute/map/MapView.kt @@ -27,9 +27,7 @@ import org.jetbrains.compose.web.dom.Div @Inject class MapView : View { @Composable - override fun Content(model: MapViewModel?, emit: (MapViewEvent) -> Unit) { - model ?: return - + override fun Content(model: MapViewModel, emit: (MapViewEvent) -> Unit) { val mapState = rememberMapboxState(center = LngLat(-75.7181, 45.3922), zoom = 11.0) LaunchedEffect(model.targetStop) { diff --git a/web/src/jsMain/kotlin/ca/derekellis/reroute/search/SearchView.kt b/web/src/jsMain/kotlin/ca/derekellis/reroute/search/SearchView.kt index 2135adb..50419c7 100644 --- a/web/src/jsMain/kotlin/ca/derekellis/reroute/search/SearchView.kt +++ b/web/src/jsMain/kotlin/ca/derekellis/reroute/search/SearchView.kt @@ -39,9 +39,7 @@ import org.jetbrains.compose.web.dom.Input class SearchView : View { @Composable - override fun Content(model: SearchViewModel?, emit: (SearchViewEvent) -> Unit) { - model ?: return - + override fun Content(model: SearchViewModel, emit: (SearchViewEvent) -> Unit) { var isFocused by remember { mutableStateOf(false) } Style(SearchStyleSheet) diff --git a/web/src/jsMain/kotlin/ca/derekellis/reroute/stops/StopView.kt b/web/src/jsMain/kotlin/ca/derekellis/reroute/stops/StopView.kt index b3b2a80..6290337 100644 --- a/web/src/jsMain/kotlin/ca/derekellis/reroute/stops/StopView.kt +++ b/web/src/jsMain/kotlin/ca/derekellis/reroute/stops/StopView.kt @@ -14,9 +14,7 @@ import org.jetbrains.compose.web.dom.Text class StopView : View { @Composable - override fun Content(model: StopViewModel?, emit: (StopViewEvent) -> Unit) { - model ?: return - + override fun Content(model: StopViewModel, emit: (StopViewEvent) -> Unit) { Style(StopsStyleSheet) InfoPanel(onClose = { emit(Close) }) { StopContent(model) @@ -31,7 +29,7 @@ private fun StopContent(model: StopViewModel) { when (model) { is StopViewModel.Loaded -> { H1 { Text(model.stop.name) } - H2 { Text(model.stop.code ?: "") } + H2 { Text(model.stop.code) } Div { Text(model.stop.id) } Hr() model.groupedRoutes.forEach { routes -> RouteInfo(routes) } diff --git a/web/src/jsMain/kotlin/ca/derekellis/reroute/ui/ScreenWrapper.kt b/web/src/jsMain/kotlin/ca/derekellis/reroute/ui/ScreenWrapper.kt index bd64cba..4c52e67 100644 --- a/web/src/jsMain/kotlin/ca/derekellis/reroute/ui/ScreenWrapper.kt +++ b/web/src/jsMain/kotlin/ca/derekellis/reroute/ui/ScreenWrapper.kt @@ -1,15 +1,9 @@ package ca.derekellis.reroute.ui import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue -import app.cash.molecule.RecompositionClock -import app.cash.molecule.moleculeFlow -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.flow.consumeAsFlow -import kotlinx.coroutines.flow.filterNotNull +import androidx.compose.runtime.remember +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.asSharedFlow import me.tatarka.inject.annotations.Inject @Inject @@ -17,19 +11,14 @@ class ScreenWrapper( private val presenter: Presenter, private val view: View, ) { - private val eventsChannel = Channel() - private val events = eventsChannel.consumeAsFlow().filterNotNull() - - private val models = moleculeFlow(RecompositionClock.ContextClock) { presenter.produceModel(events) } - private var model by mutableStateOf(null) - @Composable fun screen() { - LaunchedEffect(presenter) { - models.collect { model = it } - } + val triggerFlow = remember { MutableSharedFlow(replay = 1) } + val listenerFlow = remember { triggerFlow.asSharedFlow() } + + val model = presenter.produceModel(listenerFlow) - view.Content(model) { eventsChannel.trySend(it) } + view.Content(model) { triggerFlow.tryEmit(it) } } override fun equals(other: Any?): Boolean { diff --git a/web/src/jsMain/kotlin/ca/derekellis/reroute/ui/View.kt b/web/src/jsMain/kotlin/ca/derekellis/reroute/ui/View.kt index bf13301..6eaab05 100644 --- a/web/src/jsMain/kotlin/ca/derekellis/reroute/ui/View.kt +++ b/web/src/jsMain/kotlin/ca/derekellis/reroute/ui/View.kt @@ -4,5 +4,5 @@ import androidx.compose.runtime.Composable interface View { @Composable - fun Content(model: ViewModel?, emit: (ViewEvent) -> Unit) + fun Content(model: ViewModel, emit: (ViewEvent) -> Unit) }