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

Introduction to MVI Architecture

Hitesh Das
December 18, 2020

Introduction to MVI Architecture

Hitesh Das

December 18, 2020
Tweet

More Decks by Hitesh Das

Other Decks in Technology

Transcript

  1. Introduction Model holds single or multiple dynamic data structures and

    the business logic associated with it. View, same as other architecture patterns, is the interface for displaying/rendering information to the end user by listening to the outputs of the model or state. Intent (≠Android Intents) is an action or event from either the end user interacting with the user Interface or the system with a desired result. And, Last but not the least, User; Either the actor interacting with the software system or the system itself. user(view(model(intent(user()))))
  2. What is MVI? A reactive architecture pattern where the model

    is updated based on some interactions from user or the system and the view is updated based on states emitted from the model. Finite State Machine (FSM) Consider this to be finite state machine that has a limited or finite no of possible states.
  3. Why MVI? - One of the integral part of MVVM

    architecture is the ViewModel. - Nevertheless, the concept of model defined in MVC pattern is not being followed religiously. - The view is not driven by the model, directly. View can observe multiple observable properties from ViewModel for state changes which causes state overlapping issues - Sometimes two different states are shown unexpectedly, both error and loader state).
  4. The State Overlapping problem MVI pattern solves the state problem

    by adding the actual ‘model’ layer which is observed by view for state changes. As this model is an immutable and single source of truth for the current view state, overlapping of states will not happen.
  5. Unidirectional One of the core concepts of MVI is Unidirectional

    Data flow. Some of the benefits of unidirectional flow are: 1. It reduces Edge Cases. 2. It solves the State Problem. 3. It enforces Single Responsibility Principle (refer S.O.L.I.D Principles). Hence, MVI provides a more decoupled architecture pattern.
  6. Single Immutable State MVI also provides a Single Immutable State

    which is more predictable. Also, it simplifies logic surface, enhancing maintainability and testability of the project. With Single Entry and Exit Point, MVI also consolidates points for : 1. Validation 2. Analytics collection 3. Debugging.
  7. Reactive MVI is based on reactive mechanism. The action performed

    by the user/system are considered as a part of MVI architecture. In layman terms, our View observes and reacts to any change in the state of the model as a result of some action either by the user or the system.
  8. Final Verdict We have learnt about the MVI principles, components

    and finally the boilerplate with Android LiveData based approach. It may seem like adding more complexity than straight forward processing of the actions. But, in the long run, it will pay off as debugging cum tracking down the root cause of any issue/crash will be super easy as we can add or track new features easily.