Skip to content

Integrating MvRx In Your App

Gabriel Peal edited this page Oct 30, 2019 · 15 revisions

Steps Required

Update Your Base Activity

This is no longer required as of MvRx 1.3.0

Update Your Base Fragment

Similar to your Activity, MvRx ships with a BaseMvRxFragment that has the necessary setup code. It is recommended that you make your base fragment just extend this. It adds very little overhead when not using MvRx and ensures that things will be set up correctly.

If this is not practical for your app, you can copy implementation details from that class into your own base Fragment. The reason we don't ship it is because we recommend that apps have their own BaseFragment in which they can put shared code like logging or helper methods. We do, however, recommend that that class extend BaseMvRxFragment

Create Your Own Base ViewModel

MvRx runs a number of debug checks to ensure that your usage of MvRx is correct. In order for that to run, you must create your own base ViewModel that passes in the correct value for debugMode. An example of this would look like this:

abstract class MvRxViewModel<S : MvRxState>(initialState: S) : BaseMvRxViewModel<S>(initialState, debugMode = BuildConfig.DEBUG)

All this does is ensure that the debug checks are run at the right time and exposes a new ViewModel for your features to extend.

We can't ship a MvRxViewModel directly because you have to use the BuildConfig class from your own application.