FREENOW Blog
Published in

FREENOW Blog

React to UI events in a non-reactive way

Photo by Nadir sYzYgY on Unsplash

The current ways

MVP Contract
MVP View
MVP Presenter
  • The View to Presenter communication seems quite complex as we need to wrap UI events in a stream of events just for the sake of throttling.
  • The View interface is now polluted with providers of this stream of events.
  • Dependency of RxJava in the concrete View.
  • As part of the waste of these reactive operations, we need to take care of the disposables. Probably not a problem if your project is mostly reactive, however, it’s still cumbersome having to write all of this code just to receive a UI event.

A new hope

MVP Contract | ViewIntentCallback
MVP View | ViewIntentCallback
MVP Presenter | ViewIntentCallback

How does the ViewIntentCallback work under the hood?

  • The ViewIntent interface helps us constraint the whole approach to a specific type, that way we make sure we are only sending and receiving the view intentions we define in our features.
  • The ViewIntentBinder type alias is just a convenient name for the lambda that we need to pass to our receiver function, the sender function ultimately uses this lambda to emit our intentions.
  • The Sender interface provides us with the send function which will allow us to pass an intention and apply a throttling mechanism if needed.
  • The Receive interface provides us with the operator fun that receives the lambda (aka ViewIntentBinder) whenever our Presenter initializes.
Contract
Orchestrator
Throttling Contract
Throttling Orchestrator

Conclusion

--

--

We provide mobility that sets people free.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store