Robert Jaros
12/14/2022, 5:13 PM/
, /active
, and /completed
.Robert Jaros
12/14/2022, 5:13 PMRobert Jaros
12/14/2022, 5:13 PMRobert Jaros
12/14/2022, 5:18 PMval routerState: Backstack<TodoRoute> by router.observeStates().collectAsState()
collectAsState()
is not foundRobert Jaros
12/14/2022, 5:18 PMCasey Brooks
12/14/2022, 5:18 PMCasey Brooks
12/14/2022, 5:20 PMcollectAsState()
is a Compose API, an extension function on StateFlow
. observeAsState()
returns a StateFlow
, which is the important bit, and you can collect the states from it however works best with your UIRobert Jaros
12/14/2022, 5:20 PMRobert Jaros
12/14/2022, 5:22 PMCasey Brooks
12/14/2022, 5:22 PMRobert Jaros
12/14/2022, 5:22 PMCasey Brooks
12/14/2022, 5:26 PMRobert Jaros
12/14/2022, 5:28 PMRobert Jaros
12/14/2022, 5:28 PMCasey Brooks
12/14/2022, 5:29 PMCasey Brooks
12/14/2022, 5:30 PMCasey Brooks
12/14/2022, 5:30 PMRoute
is the matcher, and a Destination
is a URL that is matched to a Route
Robert Jaros
12/14/2022, 5:30 PMCasey Brooks
12/14/2022, 5:30 PMRobert Jaros
12/14/2022, 5:34 PMRobert Jaros
12/14/2022, 5:35 PMrouter.observeStates().onEach {
val destination = it.backstack.lastOrNull()
// I've got destination but I want route :)
}.launchIn(scope)
Robert Jaros
12/14/2022, 5:38 PMrouter.observeStates().onEach {
it.backstack.renderCurrentDestination(
route = { route: TodoRoute ->
when(route) {
TodoRoute.All -> TODO()
TodoRoute.Active -> TODO()
TodoRoute.Completed -> TODO()
}
},
notFound = { },
)
}.launchIn(scope)
Is this ok?Casey Brooks
12/14/2022, 5:45 PMval router: Router<TodoRoute> = ...
val vm: BallastViewModel<TodoContract.Inputs, TodoContract.Events, TodoContract.State> = ...
router.observeStates().onEach {
it.backstack.renderCurrentDestination(
route = { route: TodoRoute ->
when(route) {
TodoRoute.All -> { vm.trySend(TodoContract.Inputs.ShowAll) }
TodoRoute.Active -> { vm.trySend(TodoContract.Inputs.ShowActive) }
TodoRoute.Completed -> { vm.trySend(TodoContract.Inputs.ShowCompleted) }
}
},
notFound = { },
)
}.launchIn(scope)
vm.observeStates().onEach { todoState ->
updateUi(todoState)
}.launchIn(scope)
Robert Jaros
12/14/2022, 5:46 PMRobert Jaros
12/14/2022, 5:47 PMRobert Jaros
12/14/2022, 5:48 PM[TodoScreen] Input Queued: [object Object]
this is how input is logged in the browser when routing is activatedRobert Jaros
12/14/2022, 5:49 PM[TodoScreen] Input Queued: ToggleActive(index=1)
Robert Jaros
12/14/2022, 5:49 PMRobert Jaros
12/14/2022, 5:50 PMCasey Brooks
12/14/2022, 5:50 PMtoString()
of an object, which is unfortunately terrible in JS for most standard classes. Data classes have an intellijgible .toString()
generated by Kotlin, but for objects or normal classes, yeah, its just using the platformâs default representation for .toString()
Casey Brooks
12/14/2022, 5:50 PMRobert Jaros
12/14/2022, 5:50 PMCasey Brooks
12/14/2022, 5:51 PM.toString()
Robert Jaros
12/14/2022, 5:52 PMCasey Brooks
12/14/2022, 5:52 PMRobert Jaros
12/14/2022, 5:53 PMRobert Jaros
12/14/2022, 5:53 PMUncaught TypeError: Mn().m5s_1 is undefined
Casey Brooks
12/14/2022, 5:55 PMRobert Jaros
12/14/2022, 5:56 PMRobert Jaros
12/14/2022, 5:56 PMCasey Brooks
12/14/2022, 5:57 PMCasey Brooks
12/14/2022, 5:58 PMRobert Jaros
12/14/2022, 6:04 PMwithBrowserHashRouter
Robert Jaros
12/14/2022, 6:04 PMRobert Jaros
12/14/2022, 6:04 PMRobert Jaros
12/14/2022, 6:05 PMUncaught TypeError: Companion_getInstance_0().m5s_1 is undefined
applyOrigin file:///home/rjaros/git/kvision-examples/todomvc-ballast/build/distributions/main.bundle.js:38066
Casey Brooks
12/14/2022, 6:11 PMio.ktor:ktor-http
dependency, which Iâm using to parse URLs in common code. I think I might see part of the problem, though Iâm not quite sure how to address it.
URLBuilder.applyOrigin refers to a private property in its companion object. Iâm wondering if originUrl
has not been initialized at the point applyOrigin()
is called. So likely some kind of JS initialization order issue, maybe?Robert Jaros
12/14/2022, 6:11 PMCasey Brooks
12/14/2022, 6:12 PMCasey Brooks
12/14/2022, 6:14 PMRobert Jaros
12/14/2022, 6:17 PMRobert Jaros
12/14/2022, 6:20 PMCasey Brooks
12/14/2022, 6:23 PMktor-http
also depends on ktor-utils
, which is quite a large module. Ktor is licensed under Apache, so maybe I can just copy the couple of files I need for URL parsingâŚRobert Jaros
12/14/2022, 6:33 PMRobert Jaros
12/14/2022, 6:36 PMRobert Jaros
12/14/2022, 6:36 PMCasey Brooks
12/14/2022, 6:41 PMCasey Brooks
12/14/2022, 6:43 PM