Daniele B
09/24/2020, 6:41 PMKotlin/React
for a few days and I found it interesting.
I was very amazed by the chance of creating HTML/CSS using Kotlin DSL rather than plain HTML/CSS. It is very powerful, as the the HTML and CSS are created automatically in an optimized way, without having to organize CSS classes yourself.
However I was disappointed by the performance
and by the js filesize
.
I am working on a multiplatform project, with a shared ViewModel, which on Android is plugged into a JetpackCompose UI and on iOS into SwiftUI. I am looking for the best way to use my declarativeUI-ready ViewModel on web too, via StateFlow
.
My basic requirements for a web framework are these 5:
• collect a StateFlow emitted by the KMP shared ViewModel
• create HTML components using Kotlin DSL
• use a decent variety of already made web components
• react to ViewModel state changes quickly
• compile to a small JS filesize
I just came across two interesting web frameworks written in Kotlin:
`Fritz2`: https://www.fritz2.dev/
`KVision`: https://kvision.gitbook.io/
I would be very interesting to hear the experiences of people here, and how they compare them in terms of performance and filesize to React/Kotlin:Robert Jaros
09/24/2020, 6:46 PMRobert Jaros
09/24/2020, 6:47 PMRobert Jaros
09/24/2020, 6:49 PMDaniele B
09/24/2020, 6:50 PMDaniele B
09/24/2020, 6:51 PMRobert Jaros
09/24/2020, 6:51 PMDaniele B
09/24/2020, 6:54 PMRobert Jaros
09/24/2020, 6:55 PMRobert Jaros
09/24/2020, 6:56 PMRobert Jaros
09/24/2020, 6:57 PMRobert Jaros
09/24/2020, 6:58 PMRobert Jaros
09/24/2020, 7:00 PMRobert Jaros
09/24/2020, 7:03 PMRobert Jaros
09/24/2020, 7:04 PMRobert Jaros
09/24/2020, 7:05 PMDaniele B
09/24/2020, 7:06 PMRobert Jaros
09/24/2020, 7:07 PMRobert Jaros
09/24/2020, 7:09 PMRobert Jaros
09/24/2020, 7:09 PMRobert Jaros
09/24/2020, 7:10 PMRobert Jaros
09/24/2020, 7:11 PMDaniele B
09/24/2020, 7:44 PMaltavir
09/25/2020, 6:03 AMRobert Jaros
09/25/2020, 7:01 AMaltavir
09/25/2020, 7:04 AMJoost Klitsie
09/25/2020, 8:40 AMDaniele B
09/25/2020, 9:13 AMJoost Klitsie
09/25/2020, 9:19 AMfun <T> StateFlow<T>.collectAsState(
context: CoroutineContext = Dispatchers.Unconfined
): T {
val (state, updateState) = useState<T> { this@collectAsState.value }
useLayoutEffectWithCleanup(emptyList()) {
val job = CoroutineScope(context).launch {
collect {
updateState(it)
}
}
return@useLayoutEffectWithCleanup {
job.cancel()
}
}
return state
}
Joost Klitsie
09/25/2020, 9:19 AMJoost Klitsie
09/25/2020, 9:20 AMJoost Klitsie
09/25/2020, 9:20 AMif (it != appState) {
because the stateFlow is anyway conflatedJoost Klitsie
09/25/2020, 9:21 AMJoost Klitsie
09/25/2020, 9:24 AMval viewModel by instance<EventOverviewContract.Props, EventOverviewContract.ViewModel>( // Injecting my viewmodel and providing props to it
EventOverviewProps(
handler = props.handler
)
)
val viewState = viewModel.viewState.collectAsState() // Now I can render my component base on the viewState
Daniele B
09/25/2020, 9:33 AMDaniele B
09/25/2020, 9:46 AMaltavir
09/25/2020, 10:05 AMDaniele B
09/25/2020, 10:16 AMaltavir
09/25/2020, 10:17 AMaltavir
09/25/2020, 10:18 AMDaniele B
09/25/2020, 10:19 AMDaniele B
09/25/2020, 10:35 AMDaniele B
09/25/2020, 10:35 AMRobert Jaros
09/25/2020, 10:43 AMJoost Klitsie
09/25/2020, 12:28 PM