Robert Jaros
06/02/2024, 1:59 PMbuild()
used in this class: https://github.com/rjaros/kvision/blob/master/kvision-modules/kvision-routing-ballast/src/jsMain/kotlin/io/kvision/routing/KVRouterViewModel.kt#L53Robert Jaros
06/02/2024, 2:00 PMRobert Jaros
06/02/2024, 2:01 PMRobert Jaros
06/02/2024, 2:22 PMwithRouter
call, but after that a BrowserHashNavigationInterceptor
is added, and the initial state is reset to null.Robert Jaros
06/02/2024, 2:23 PMCasey Brooks
06/02/2024, 3:25 PMCasey Brooks
07/13/2024, 4:00 AM.withViewModel
now returns a new builder instance of TypedBuilder
which helps ensure the type-safety of applying subsequent interceptors. When the config builder functions are called in a chain (which is how I always apply them), everything works out fine, since the operators applied after .withViewModel
operate on the new instance and the operators on Builder
and TypedBuilder
are identical.
But for your snippet, the .apply { }
block returns the original, untyped Builder
assuming that withBrowserHashRouter
and withBrowserHistoryRouter
mutated that object, when in reality those functions return a new object. While I did note the different return type of that function in the v4 migration guide, I completely overlooked the behavioral change that this implied with respect to the mutability of that builder object.
Using .let
instead of .apply
fixes the issue:
BallastViewModelConfiguration.Builder().let {
if (useHash) {
it.withBrowserHashRouter(
routingTable,
initialRoute
)
} else {
it.withBrowserHistoryRouter(
routingTable,
basePath,
initialRoute
)
}
}.build()
Casey Brooks
07/13/2024, 4:09 AM