-
-
Save rustamsmax/b8768f4546d8a4b1eb256402527f6f8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uz.somepackage | |
import com.arkivanov.decompose.ComponentContext | |
import com.arkivanov.mvikotlin.core.binder.BinderLifecycleMode | |
import com.arkivanov.mvikotlin.core.store.Store | |
import com.arkivanov.mvikotlin.extensions.reaktive.bind | |
import com.badoo.reaktive.base.Consumer | |
import com.badoo.reaktive.observable.map | |
import com.badoo.reaktive.subject.publish.PublishSubject | |
import uz.somepackage.DashboardComponent.Dependencies | |
import uz.somepackage.DashboardStore.Intent | |
import uz.somepackage.DashboardStore.State | |
interface DashboardComponent { | |
data class StateModel( | |
val items: List<DashboardItem> | |
) | |
interface Dependencies { | |
val featureLoader: FeatureLoader | |
} | |
val featureA: FeatureAComponent? | |
} | |
fun DashboardComponent( | |
componentContext: ComponentContext, | |
dependencies: Dependencies | |
): DashboardComponent = DashboardComponentImpl(componentContext, dependencies) | |
private class DashboardComponentImpl( | |
componentContext: ComponentContext, | |
dependencies: Dependencies | |
) : DashboardComponent, ComponentContext by componentContext, Dependencies by dependencies { | |
private val store: DashboardStore = TODO() | |
private val featureAOutput = PublishSubject<FeatureAComponent.Output>() | |
override val featureA: FeatureAComponent? = | |
featureLoader.loadFeatureAComponentIfAvailable( | |
componentContext = componentContext, | |
dependencies = object : FeatureAComponent.Dependencies { | |
override val output = featureAOutput | |
} | |
) | |
init { | |
bind(lifecycle, BinderLifecycleMode.CREATE_DESTROY) { | |
featureAOutput.map(featureAOutputToDashboardIntent) bindTo store | |
} | |
} | |
} | |
interface DashboardStore : Store<Intent, State, Nothing> { | |
data class State( | |
val items: List<DashboardItem> = emptyList() | |
) | |
sealed class Intent { | |
data class OnItemChanged(val item: DashboardItem) : Intent() | |
} | |
} | |
interface FeatureAComponent { | |
sealed class Output { | |
data class OnProcessByFeatureA(val item: DashboardItem) : Output() | |
} | |
interface Dependencies { | |
val output: Consumer<Output> | |
} | |
fun onClickProcessByFeatureA(item: DashboardItem) | |
} | |
interface FeatureProvider<T> { | |
fun get(): T | |
} | |
interface FeatureLoader { | |
fun loadFeatureAComponentIfAvailable( | |
componentContext: ComponentContext, | |
dependencies: FeatureAComponent.Dependencies | |
): FeatureAComponent? | |
} | |
interface FeatureChecker { | |
fun featureAAvailable(): Boolean | |
} | |
internal class AndroidFeatureLoader( | |
private val featureChecker: FeatureChecker | |
) : FeatureLoader { | |
override fun loadFeatureAComponentIfAvailable( | |
componentContext: ComponentContext, | |
dependencies: FeatureAComponent.Dependencies | |
): FeatureAComponent? { | |
return if(featureChecker.featureAAvailable()) TODO() else null | |
} | |
} | |
data class DashboardItem(val title: String) | |
private val featureAOutputToDashboardIntent: (FeatureAComponent.Output) -> Intent = { | |
when (it) { | |
is FeatureAComponent.Output.OnProcessByFeatureA -> Intent.OnItemChanged(it.item) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment