Skip to content

Instantly share code, notes, and snippets.

class Presenter<S>(state: S) {
private val _state = BehaviorRelay.createDefault(state)
val state: Observable get() = _state
protected fun setState(reducer: S.() -> S) {
// Enforce main thread to avoid synchronization
//
val oldState = stateRelay.value!!
stateRelay.accept(oldState.reducer())
}
@AppScope
@Component(modules = [..., MessageModule::class])
interface AppComponentImpl : AppComponent, Feature1AppComponent, Feature2AppComponent, ...
@AppScope
@Component(modules = [..., MessageModule::class])
interface AppComponentImpl : AppComponent, Feature1AppComponent, Feature2AppComponent, ...
interface Feature1AppComponent : AppComponent { <------
val messageRepository: MessageRepository
}
@ChatControllerScope
@Component(
dependencies = [Feature1AppComponent::class], <------
modules = [Feature1ControllerModule::class]
)
internal interface Feature1ControllerComponent {
@Feature1ControllerScope
@Component(dependencies = [???::class], modules = [Feature1Module::class])
interface Feature1ControllerComponent {
val viewModel: InviteViewModel
...
}
:app
_______________/__________________
/ / / /
:feature1 :feature2 :feature3 ... :featureN
/_________/________/______________/
/ / /
:messages / /
/____________/______________/
/
:base
interface Feature1AppComponent : AppComponent {
val messageRepository: MessageRepository
}
:app
_______________/__________________
/ / / /
:feature1 :feature2 :feature3 ... :featureN
/_________/________/______________/
/
:base
@Module
object MessageModule {
@AppScope
@Provides
@JvmStatic
fun messageRepository(...): MessageRepository {
return MessageRepository(...)
}
}
@Module
object MessageModule {
@AppScope
@Provides
@JvmStatic
fun messageModule(...): MessageRepository {
return MessageRepository(...)
}
}