Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Model View Intent: Embracing Reactive Architecture

Yousuf Haque
September 25, 2017

Model View Intent: Embracing Reactive Architecture

Juggling several Rx streams at the same time is incredibly difficult. Model, View, Intent (MVI) is an iteration on the MVP model that fills in some gaps around how to handle multiple streams within one's presenter. It also solidifies the concept of a "State reducer" within the context of android applications. MVI is a spin on various reactive architectures from the web space adapted to solve some of the challenges when building android applications.

Yousuf Haque

September 25, 2017
Tweet

More Decks by Yousuf Haque

Other Decks in Programming

Transcript

  1. Rx is really good at modeling events occurring over time.

    User inputs are events occurring over time
  2. RxBindings is a library by Jake Wharton that lets us

    observe Widgets and Views through observable streams
  3. The gist of Model View Intent 1. User Inputs exposed

    as Observable<Intent> 2. Model takes in the Observable<Intent>, Observable<Data>, Observable<AppState>, and combines into Observable<ViewState> 3. View subscribes to Observable<ViewState> and updates on each emission
  4. We start with an initial state, and simply apply the

    Observable<StateReducer> emissions to reflect new state
  5. We can represent lifecycle events as Rx Streams We can

    use .takeUntil(Observable) to complete view related portions of the stream to avoid leaks
  6. What does this buy you? 1. Many pure functions a.

    Easy to test b. Easy to compose member functions 2. Explicit state, and explicit flow of data a. Time travel debugging b. Easy to trace source of changes 3. Nested dialogs a. Build complex features out of smaller, simpler features
  7. What does it cost you? 1. Heavily dependent on Rx,

    steep learning curve a. Non beginner level knowledge of Rx required 2. Lots of small objects being generated and thrown around a. Intents, states, view states, etc 3. Changes/modifications might take more time than if done imperatively a. Need to code more deliberately b. Takes more time, but prevents bugs
  8. Resources 1. Managing State with RxJava by Jake Wharton a.

    https://www.youtube.com/watch?v=0IKHxjkgop4 2. Borrowing the Best of the Web to Make Native Better by Christina Lee a. https://www.youtube.com/watch?v=GOVMkQp3LZ4 3. Unidirectional data flow architectures by Andre Staltz a. https://www.youtube.com/watch?v=1c6XiQsnh_U b. https://staltz.com/unidirectional-user-interface-architectures.html 4. Reactive Apps with Model View Intent by Hannes Dorfmann a. http://hannesdorfmann.com/android/mosby3-mvi-1 5. My Take on Model View Intent by Zak Taccardi a. https://hackernoon.com/model-view-intent-mvi-part-1-state-renderer-187e270db15c 6. TODO MVI by Yousuf Haque a. https://github.com/yousuf-haque/TodoMvi