Last active
September 13, 2018 18:14
-
-
Save kshirsagarps/eede6384f63e11ccb0eab318cd78b809 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
class SimpleActivity : AppCompatActivity() { | |
private var store = Store(0) | |
private val subscriptions = CompositeSubscription() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_counter) | |
setTitle(R.string.simple_activity_name) | |
subscriptions.add(states(store).observeOn(mainThread()) | |
.subscribe({ it -> counterText.text = it.toString() }, this::onError)) | |
subscriptions.add(RxView.clicks(incrementButton) | |
.flatMap { IncrementCounterCommand().actions() as Observable<Action<Int>> } | |
.subscribe(store::dispatch, this::onError)) | |
subscriptions.add(RxView.clicks(decrementButton) | |
.flatMap { DecrementCounterCommand().actions() as Observable<Action<Int>> } | |
.subscribe(store::dispatch, this::onError)) | |
} | |
override fun onDestroy() { | |
subscriptions.unsubscribe(); | |
super.onDestroy() | |
} | |
private fun onError(throwable: Throwable) = Unit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment