Created
April 16, 2020 20:43
-
-
Save arkivanov/746d656d5a629e58afd10a5d1a6f41c6 to your computer and use it in GitHub Desktop.
MviKmpKittenComponent2.kt
This file contains hidden or 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
| 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