Skip to content

Instantly share code, notes, and snippets.

@arkivanov
Created April 16, 2020 20:43
Show Gist options
  • Select an option

  • Save arkivanov/746d656d5a629e58afd10a5d1a6f41c6 to your computer and use it in GitHub Desktop.

Select an option

Save arkivanov/746d656d5a629e58afd10a5d1a6f41c6 to your computer and use it in GitHub Desktop.
MviKmpKittenComponent2.kt
class KittenComponent {
private val store =
KittenStoreImpl(
network = KittenStoreNetwork(dataSource = KittenDataSource()),
parser = KittenStoreParser
)
private var view: KittenView? = null
private var startStopScope: DisposableScope? = null
fun onViewCreated(view: KittenView) {
this.view = view
}
fun onStart() {
val view = requireNotNull(view)
startStopScope = disposableScope {
store.subscribeScoped(onNext = view::render)
view.events.map(Event::toIntent).subscribeScoped(onNext = store::onNext)
}
}
fun onStop() {
startStopScope?.dispose()
}
fun onViewDestroyed() {
view = null
}
fun onDestroy() {
store.dispose()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment