JimK
10/11/2020, 2:19 PMArkadii Ivanov
10/11/2020, 2:33 PMJimK
10/11/2020, 2:44 PMArkadii Ivanov
10/11/2020, 2:57 PMJimK
10/11/2020, 2:58 PMJimK
10/11/2020, 3:00 PMArkadii Ivanov
10/11/2020, 3:03 PMJimK
10/11/2020, 3:08 PMArkadii Ivanov
10/19/2020, 10:41 PMComponentContext
then you use the following approach:
interface AppComponentContext : ComponentContext {
val database: Database
}
fun AppComponentContext.appComponentContext(context: ComponentContext): AppComponentContext =
object : AppComponentContext, ComponentContext by context {
override val database: Database = this@appComponentContext.database
}
fun AppComponentContext.child(key: String): AppComponentContext =
appComponentContext(child(key))
fun <C : Parcelable, T : Any> AppComponentContext.appRouter(
initialConfiguration: C,
configurationClass: KClass<out C>,
key: String = "DefaultRouter",
handleBackButton: Boolean = false,
componentFactory: (configuration: C, AppComponentContext) -> T
): Router<C, T> =
router(
initialConfiguration = initialConfiguration,
configurationClass = configurationClass,
key = key,
handleBackButton = handleBackButton
) { configuration, componentContext ->
componentFactory(configuration, appComponentContext(componentContext))
}
inline fun <reified C : Parcelable, T : Any> AppComponentContext.appRouter(
initialConfiguration: C,
key: String = "DefaultRouter",
handleBackButton: Boolean = false,
noinline componentFactory: (configuration: C, AppComponentContext) -> T
): Router<C, T> =
appRouter(
initialConfiguration = initialConfiguration,
configurationClass = C::class,
key = key,
handleBackButton = handleBackButton,
componentFactory = componentFactory
)
Arkadii Ivanov
10/19/2020, 10:48 PMambient
from Decompose can be easily implemented with the following code:
interface AppComponentContext : ComponentContext {
val ambient: Map<KClass<*>, Any>
}
inline operator fun <reified T : Any> AppComponentContext.plus(value: T): AppComponentContext =
object : AppComponentContext, ComponentContext by this {
override val ambient: Map<KClass<*>, Any> =
this@plus.ambient + (T::class to value)
}
inline fun <reified T : Any> AppComponentContext.ambientOrNull(): T? = ambient[T::class] as T?
inline fun <reified T : Any> AppComponentContext.ambient(): T = requireNotNull(ambientOrNull())
Please not, there is no compile time safety in this case. Which I believe is very important.Arkadii Ivanov
10/19/2020, 10:50 PMambient
thing into Decompose itself.JimK
10/19/2020, 10:55 PMrsktash
01/21/2021, 12:26 PMrsktash
01/21/2021, 12:35 PMArkadii Ivanov
01/21/2021, 2:21 PM