74

GitHub - airbnb/MvRx: MvRx: Android on Autopilot

 5 years ago
source link: https://github.com/airbnb/MvRx
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

MvRx: Android on Autopilot

For full documentation, check out the wiki

MvRx (pronounced mavericks) is the Android framework from Airbnb that we use for nearly all product development at Airbnb.

When we began creating MvRx, our goal was not to create yet another architecture pattern for Airbnb, it was to make building products easier, faster, and more fun. All of our decisions have built on that. We believe that for MvRx to be successful, it must be effective for building everything from the simplest of screens to the most complex in our app.

This is what it looks like:

data class HelloWorldState(val title: String = "Hello World") : MvRxState

class HelloWorldViewModel(initialState: HelloWorldState) : MvRxViewModel<HelloWorldState>(initialState) {
    fun getMoreExcited() = setState { copy(title = "$title!") }
}

class HelloWorldFragment : BaseFragment() {
    private val viewModel: HelloWorldViewModel by fragmentViewModel()

    override fun EpoxyController.buildModels() = withState(viewModel) { state ->
        header {
            title(state.title)
        }
        basicRow { 
            onClick { viewModel.getMoreExcited() }
        }
    }
}

Installation

Gradle is the only supported build configuration, so just add the dependency to your project build.gradle file:

dependencies {
  implementation 'com.airbnb.android:mvrx:0.5.0'
}

The latest version of mvrx is Maven Central

For full documentation, check out the wiki


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK