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

MVI (Model-View-Intention)

MVI (Model-View-Intention)

Presented on 29 February 2020 at Swift India.
https://www.meetup.com/Swift-Delhi/events/268573479/

Avatar for  Kapil Rathore

 Kapil Rathore

February 29, 2020
Tweet

Other Decks in Programming

Transcript

  1. Kapil Rathore iOS @ Tokopedia MVI (Model-View-Intention) Reactive Unidirectional Architecture

    for your Apps @krkapilrathore @krkapilrathore @kapilrathore
  2. Intention • Take the inputs from the user • Map

    the user inputs to Model friendly events • Eg - button click events, text input events etc.
  3. Model • Take the inputs from Intention • Processes a

    particular business Usecase based on the input • Produces a New State as an output • Only piece of code that is allowed to change the State
  4. • Immutable data structure • Holds all the important information

    required to change the dynamic data on the UI layer • Acts as the single source of truth State
  5. • Takes the output State produced by the Model as

    input • Contains the rendering logic for the emitted state View
  6. Planning Model Usecases • Increment Usecase • Decrement Usecase •

    Reset Counter Usecase • Interval Change Usecase
  7. Summary Pros • Unidirectional & Cyclic Flow of Data •

    Decoupled Code • Predictable (Pure functions + Immutable States) • Highly Testable & Debuggable (Encourages TDD) • User Centric (User drives the architecture) • Reactive (Handles the async code) • Platform Agnostic (Cross platform collaboration)
  8. Summary Cons • Lots of Boilerplate • Where to place

    navigation logic • Complexity (Learning Curve)
  9. References • What if the user was a function? by

    Andre Staltz at JSConf Budapest 2015 • Managing State with RxJava by Jake Wharton • Mobius by Spotify • MVI Series: A Pragmatic Reactive Architecture for Android