Skip to content

Instantly share code, notes, and snippets.

@kshirsagarps
Last active September 13, 2018 18:14
Show Gist options
  • Save kshirsagarps/eede6384f63e11ccb0eab318cd78b809 to your computer and use it in GitHub Desktop.
Save kshirsagarps/eede6384f63e11ccb0eab318cd78b809 to your computer and use it in GitHub Desktop.
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