<@UHAJKUSTU> Is there any simple solution for logg...
# decompose
e
@Arkadii Ivanov Is there any simple solution for logging navigation changes in the component tree? Since we don’t have any centralised
router
which could make this logging, I am looking in direction of making a copy of
DefaultStackNavigation
but I really don’t like this solution much. Also it doesn’t cover slot navigation and has a lot of other cons.
a
Currently, I don't see any solution that could be applied globally. You can create a logging wrapper for childFactory, but that needs to be applied in every place.
Or wrap StackNavigation, but same cons here.
e
It would be cool to have the flexibility of current implementation plus features of centralised event-based things like MVI in one place.
😃
Indeed the navigation part of the component being in fact stateful can be implemented in theory as a MVI-like state machine with all it’s features like middleware and logging
Thanks for the feedback!
a
It would be possible if the
children
extension function would be part of the ComponentContext interface. In this case one could create a custom component context and wrap the children call. I will think about it, but currently this looks overcomplicated.
e
Maybe it’s possible to add a parameter to
childStack
method which will allow to pass a lambda for logging stack changes?
but this still is not a global setting
a
Maybe it’s possible to add a parameter to childStack method which will allow to pass a lambda for logging stack changes?
This is essentially equivalent to creating a custom wrapper for StackNavigation. This could be as simple as
Copy code
val nav = LoggingStackNavigation<Config>()
e
by “wrapper” do you mean creating another variant of
DefaultStackNavigation
?
a
Or
Copy code
val nav = StackNavigation<Config>()
val stack = childStack(source = nav.logged(), ...)
Yeah, create a custom implementation that delegates to the standard StackNavigation.
e
yeah, I was originally thinking in that direction. This may help if replace navigation with the wrapper everywhere. thanks!
👍 1
a
This is what I came up with.
Copy code
class LoggingStackNavigation<C : Any>(
    private val delegate: StackNavigation<C> = StackNavigation(),
) : StackNavigation<C>, StackNavigationSource<C> by delegate {
    override fun navigate(
        transformer: (stack: List<C>) -> List<C>,
        onComplete: (newStack: List<C>, oldStack: List<C>) -> Unit,
    ) {
        delegate.navigate(transformer) { newStack, oldStack ->
            println("Stack changed to $newStack. Old stack: $oldStack.")
            onComplete(newStack, oldStack)
        }
    }
}
👍 2
thank you color 1