Skip to content

Instantly share code, notes, and snippets.

Avatar

ursusursus

View GitHub Profile
View gist:11ec56dbf6cdfaba12c59409147b7584
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())
}
View AppComponentImpl.kt
@AppScope
@Component(modules = [..., MessageModule::class])
interface AppComponentImpl : AppComponent, Feature1AppComponent, Feature2AppComponent, ...
View AppComponentImpl.kt
@AppScope
@Component(modules = [..., MessageModule::class])
interface AppComponentImpl : AppComponent, Feature1AppComponent, Feature2AppComponent, ...
View Feature1.kt
interface Feature1AppComponent : AppComponent { <------
val messageRepository: MessageRepository
}
@ChatControllerScope
@Component(
dependencies = [Feature1AppComponent::class], <------
modules = [Feature1ControllerModule::class]
)
internal interface Feature1ControllerComponent {
View Feature1.kt
@Feature1ControllerScope
@Component(dependencies = [???::class], modules = [Feature1Module::class])
interface Feature1ControllerComponent {
val viewModel: InviteViewModel
...
}
View gist:c42027a4898a706147f4d1dc9bcb8f27
:app
_______________/__________________
/ / / /
:feature1 :feature2 :feature3 ... :featureN
/_________/________/______________/
/ / /
:messages / /
/____________/______________/
/
:base
View Feature1.kt
interface Feature1AppComponent : AppComponent {
val messageRepository: MessageRepository
}
View gist:cdb3da5fa211f463878deaaf2a897856
:app
_______________/__________________
/ / / /
:feature1 :feature2 :feature3 ... :featureN
/_________/________/______________/
/
:base
View MessageModule.kt
@Module
object MessageModule {
@AppScope
@Provides
@JvmStatic
fun messageRepository(...): MessageRepository {
return MessageRepository(...)
}
}
View MessageModule.kt
@Module
object MessageModule {
@AppScope
@Provides
@JvmStatic
fun messageModule(...): MessageRepository {
return MessageRepository(...)
}
}