This is an attempt at coming up with a unidirectional state flow pattern that uses the concepts of patterns like Redux, Cycle.js, MVI etc.
Many of my contemporaries have already done amazing work in this area and I've drawn a lot of lessons and learnings from their work already:
- The state of managing state with RxJava - JakeWharton
- MVI patterns with Hannes Dorfmann - Hannes Dorfmann
- LCE: Modeling Data Loading in RxJava - Laimonas
I wanted to achieve the benefits of this pattern without introducing any new libraries or a new framework. How would one familiar with an MVVM model today leverage the principles/benefits of a unidirectional state/data flow? I hope to demo those concepts with this app.
The app is a simple movie search app. Clicking the movie result populates a history list. While this is not an extremely complex app, it isn't a silly Hello World one either, so the hope is that it'll cover regular use cases for a basic application.
I've also started meaninful test cases in the repo.
We use the wonderful OMDB api to fetch movie information.
There are quotas on this api, so please don't use mine :)
- Get an api key for OMDB here
- Add it to you local.properties file (which shouldn't be checked in to a VCS) like so:
# local.properties
OMDB_API_KEY="<API_KEY_GOES_HERE>"
For great movie recommendations, ping me @kau.sh (seriously, I watch a lot of movies).
I gave a talk at MBLT}Dev 2018 on how I went about building this app. Slides can be found here.
This project now uses ksp to reduce the boilerplate in wiring up a new feature. This PR has the details for how this change was made.
All that's needed is writing the implementation of your ViewModel so MyFeatureViewModelImpl: UsfViewModelImpl<E, R, VS, VE>
and adding the @UsfViewModel
annotation. Your ViewModel boilerplate code will be auto-generated.
Take a look at MSMovieViewModelImpl for the View Model logic and MSMovieActivity to see how the viewModel
is invoked.
I gave another talk at Mobilization IX showing how we can use the same concepts on iOS too and wrote my first iOS app to demonstrate these concepts - You can check that out here.