Skip to content

Instantly share code, notes, and snippets.

@tolmachevroman
Last active November 26, 2017 05:15
Show Gist options
  • Save tolmachevroman/cd2b8d57929012de9651bb783c2069dc to your computer and use it in GitHub Desktop.
Save tolmachevroman/cd2b8d57929012de9651bb783c2069dc to your computer and use it in GitHub Desktop.
Medium Post 2. RestaurantsViewModel
class RestaurantsViewModel @Inject constructor(private val repository: RestaurantsRepository) : ViewModel() {
var initialized = false
var cuisineInput: MutableLiveData<Int> = MutableLiveData()
val restaurants: LiveData<Resource<List<Restaurant>>> = Transformations
.switchMap(cuisineInput) { cuisine ->
initialized = true; repository.getRestaurants(cuisine)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment