Skip to content

Commit

Permalink
Merge pull request #16 from alphicc/config
Browse files Browse the repository at this point in the history
config : add config to router
  • Loading branch information
alphicc committed Jun 28, 2023
2 parents c862f6a + a25341a commit 0ddc2d4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![MAVEN](https://img.shields.io/badge/Maven-v2.1.2-blue) ![Platform](https://img.shields.io/badge/platform-android-green?color=lightgray) ![API](https://img.shields.io/badge/API-21-brightgreen?color=brightgreen) ![Platform](https://img.shields.io/badge/platform-desktop-green?color=lightgray)
![MAVEN](https://img.shields.io/badge/Maven-v2.2.0-blue) ![Platform](https://img.shields.io/badge/platform-android-green?color=lightgray) ![API](https://img.shields.io/badge/API-21-brightgreen?color=brightgreen) ![Platform](https://img.shields.io/badge/platform-desktop-green?color=lightgray)
<h1 align="center">
<img height="300" src="https://raw.githubusercontent.com/alphicc/Brick/main/media/logo.png"/>
<br>
Expand Down
10 changes: 10 additions & 0 deletions brick/src/commonMain/kotlin/com/alphicc/brick/RouterConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.alphicc.brick

data class RouterConfig(
val broadcastFlowReplay: Int,
val broadcastFlowExtraBufferCapacity: Int
) {
companion object {
fun default(): RouterConfig = RouterConfig(broadcastFlowReplay = 1, broadcastFlowExtraBufferCapacity = 10)
}
}
5 changes: 4 additions & 1 deletion brick/src/commonMain/kotlin/com/alphicc/brick/TreeRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface TreeRouter : ContainerConnector, CompositeComponentRouter, ComponentRo

fun branch(containerComponentKey: String): TreeRouter

fun branch(containerComponentKey: String, config: RouterConfig): TreeRouter

fun setOverlay(component: Component<*>)

fun <A> setOverlay(component: Component<*>, argument: A)
Expand All @@ -26,6 +28,7 @@ interface TreeRouter : ContainerConnector, CompositeComponentRouter, ComponentRo
suspend fun <A> passBroadcastArgument(argument: A)

companion object {
fun new(): TreeRouter = TreeRouterImpl()
fun new(): TreeRouter = TreeRouterImpl(config = RouterConfig.default())
fun new(config: RouterConfig): TreeRouter = TreeRouterImpl(config = config)
}
}
15 changes: 11 additions & 4 deletions brick/src/commonMain/kotlin/com/alphicc/brick/TreeRouterImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import kotlinx.coroutines.flow.StateFlow

internal class TreeRouterImpl(
override val initialComponent: Component<*>? = null,
override val parentRouter: TreeRouter? = null
override val parentRouter: TreeRouter? = null,
config: RouterConfig
) : TreeRouter {

private val keyManager = KeyManager()
Expand All @@ -17,7 +18,10 @@ internal class TreeRouterImpl(
private val _currentComponentFlow: MutableStateFlow<Component<*>?> = MutableStateFlow(null)
private val _currentChildFlow: MutableStateFlow<List<Component<*>>> = MutableStateFlow(emptyList())
private val _isRouterEmpty: MutableStateFlow<Boolean> = MutableStateFlow(true)
private val _broadcastFlow: MutableSharedFlow<Any> = MutableSharedFlow(replay = 1, extraBufferCapacity = 10)
private val _broadcastFlow: MutableSharedFlow<Any> = MutableSharedFlow(
replay = config.broadcastFlowReplay,
extraBufferCapacity = config.broadcastFlowExtraBufferCapacity
)

private val childRouters: AtomicRef<List<Pair<String, TreeRouter>>> = atomic(emptyList())
private val tree: AtomicRef<List<Node>> = atomic(emptyList())
Expand Down Expand Up @@ -102,8 +106,11 @@ internal class TreeRouterImpl(
fetchNode()
}

override fun branch(containerComponentKey: String): TreeRouter {
val newRouter = TreeRouterImpl(initialComponent, this)
override fun branch(containerComponentKey: String): TreeRouter =
branch(containerComponentKey, RouterConfig.default())

override fun branch(containerComponentKey: String, config: RouterConfig): TreeRouter {
val newRouter = TreeRouterImpl(initialComponent, this, config)
val childRouters = childRouters.value.toMutableList()
childRouters.add(containerComponentKey to newRouter)
this.childRouters.value = childRouters
Expand Down
2 changes: 1 addition & 1 deletion desktop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "io.github.alphicc"
version = "2.1.2"
version = "2.2.0"

kotlin {
jvm {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gradle_tools_version=7.0.4
publish_plugin_version=0.18.0

GROUP=io.github.alphicc
VERSION_NAME=2.1.2
VERSION_NAME=2.2.0

POM_NAME=Brick
POM_DESCRIPTION=Brick - Navigation library for Jetpack Compose.
Expand Down

0 comments on commit 0ddc2d4

Please sign in to comment.