[Architecture] introduce nodeBuilder concept

This commit is contained in:
ganfra 2023-03-07 20:31:16 +01:00
parent 49f624afd3
commit 84bfb14bd9
30 changed files with 153 additions and 59 deletions

View file

@ -18,8 +18,9 @@ package io.element.android.libraries.architecture
import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.Plugin
interface FeatureEntryPoint {
fun node(parentNode: Node, buildContext: BuildContext, plugins: List<Plugin> = emptyList()): Node
interface FeatureEntryPoint
interface SimpleFeatureEntryPoint : FeatureEntryPoint {
fun createNode(parentNode: Node, buildContext: BuildContext): Node
}

View file

@ -19,18 +19,9 @@ package io.element.android.libraries.architecture
import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.Plugin
import com.bumble.appyx.core.plugin.plugins
import kotlin.properties.ReadOnlyProperty
interface NodeInputs
interface NodeInputs : Plugin
interface NodeInputsProvider<I : NodeInputs> : Plugin {
fun inputs(): I
}
inline fun <reified I : NodeInputs> nodeInputsProvider(inputs: I) = object : NodeInputsProvider<I> {
override fun inputs() = inputs
}
fun <I : NodeInputs> nodeInputs() = ReadOnlyProperty<Node, I> { thisRef, _ ->
thisRef.plugins<NodeInputsProvider<I>>().first().inputs()
inline fun <reified I : NodeInputs> Node.inputs(): I {
return plugins<I>().firstOrNull() ?: throw RuntimeException("Make sure to actually pass NodeInputs plugin to your node")
}