Skip to content

Commit

Permalink
Fixes in using of 'rootChain' in 'restoreHierarchy'
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanusMokrassar committed Jan 8, 2023
1 parent d9c3dcd commit dd42bb8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* `Versions`:
* `MicroUtils`: `0.16.5`
* Fixes in using of `rootChain` in `restoreHierarchy`
* `JS`:
* Add more logs in `initNavigation`

Expand Down
20 changes: 9 additions & 11 deletions core/src/commonMain/kotlin/repo/HierarchyHandler.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package dev.inmo.navigation.core.repo

import dev.inmo.navigation.core.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.takeWhile

suspend fun <Base> ConfigHolder.Chain<Base>.restoreHierarchy(
node: NavigationNode<out Base, Base>
Expand All @@ -16,13 +13,12 @@ suspend fun <Base> ConfigHolder.Chain<Base>.restoreHierarchy(
}

suspend fun <Base> ConfigHolder.Chain<Base>.restoreHierarchy(
factory: NavigationNodeFactory<Base>
factory: NavigationNodeFactory<Base>,
chainToRestore: NavigationChain<Base> = NavigationChain(null, factory)
): NavigationChain<Base> {
val subchain = NavigationChain(null, factory)
firstNodeConfig.restoreHierarchy(chainToRestore)

firstNodeConfig.restoreHierarchy(subchain)

return subchain
return chainToRestore
}

suspend fun <Base> ConfigHolder.Node<Base>.restoreHierarchy(
Expand Down Expand Up @@ -57,17 +53,19 @@ suspend fun <Base> NavigationNode<out Base, Base>.restoreHierarchy(

suspend fun <T> restoreHierarchy(
holder: ConfigHolder<T>,
factory: NavigationNodeFactory<T>
factory: NavigationNodeFactory<T>,
rootChain: NavigationChain<T> = NavigationChain(null, factory)
): NavigationChain<T>? {
return when (holder) {
is ConfigHolder.Chain -> {
holder.restoreHierarchy(
factory
factory,
rootChain
)
}
is ConfigHolder.Node -> {
holder.restoreHierarchy(
NavigationChain(null, factory)
rootChain
) ?.chain
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/jsMain/kotlin/InitNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ inline fun <reified T : Base, reified Base : NavigationNodeDefaultConfig> initNa

restoreHierarchy<Base>(
existsChain ?: startChain,
factory = resultNodesFactory
factory = resultNodesFactory,
rootChain = rootChain
) ?.start(subscope)
}
}
Expand Down

0 comments on commit dd42bb8

Please sign in to comment.