Skip to content

(MVI) Model View Intent

Devrath edited this page May 30, 2021 · 19 revisions

Improvement from MVI towards a better Architecture

  • To overcome the drawbacks of MVC controller overloading with the business logic. Modifications were done to segregate it to a better representation of architecture called Model-View-Presenter.
  • It is a relatively new but popular approach to android application architecture.
  • MVP and MVVM are a little bit similar to MVC to MVI.
  • MVP and MVVM have presenter and view-model respectively to that of controller for MVC.
Contents
MVI specific concepts
How the concept of MVI came into existence
How MVI works
Overview representation of MVI
Detailed representation of MVI
Immutable State

MVI specific concepts

  • Uni-directional data flow.
  • Immutable state.
  • User as a function.
  • Its way of simplifying the flow of information which leads to a comprehensive and systematic approach to architecture.

How the concept of MVI came into existence

  • Many of the advancements in recent times comes from the web-development world.
  • Some namely react, redux, flux, use event-driven and functional way of solving things.
  • They give a unique perspective on how to manage mutable state.
  • Such representation fits into mobile development applications.
  • MVI is closely associated with cycle.js from the web development world.

How MVI works

Most important part of the Architecture - User

  • Much of the code you write in web development is user focused instead of process intensive.
  • Architecture in android usually focus on the process instead of user. The code gives an interface to accept input and send input.
  • Place of the user in mvvm or mvp is not transparent. Usually, the user is the kind of view in these patterns.

In MVI user takes a central role in expressing their intents(intention).

Overview representation of MVI

  • Application starts up and the user starts interacting with it.
  • We call user interaction intents meaning users intents on something to occur based on how they interact with the application. They might type a text or click a button.
  • Our software does something interesting using the intents(intention) of the user and models the data and the output is sent back to the user.
  • Thus there are intents as input and results as output.

Detailed representation of MVI

  • We interpret the user intents as actions that have to be taken inside our application.
  • We perform this translation from intent to action in order to take data within our application.
  • This translation will take users to the repository part, which is network-based, local storage based or both.
  • We use processors to perform actions on our data.
  • The processors produce a result.
  • At this point, the user intent is translated into a result.
  • Now we need to get the results back to the user.

Immutable State

  • Here is the idea of state comes into the picture.
  • State is the current status of all the information shown to the user.
  • In the High level of android application state include loading state, empty state or state of particular data.
  • As the events occur, the states are continuously updated based on the events that have occurred.
  • Instead of maintaining the states as mutable objects in our system, In MVI a new state is calculated for each new event that occurs.
  • NewState = PreviousState + Results
  • The process of combining the states with results is called MVI in android.
  • The new state is passed along the android app which renders the UI to the user
  • Due to this the state is never mutable, instead, it's recalculated and passed to the view for rendering.
  • one of the sources of bugs in software is mutable states. - > Now by using immutable state -> We can eliminate the source of many bugs in software using MVI.

There is always unidirectional flow dow data in the MVI

Clone this wiki locally