Skip to content

Instantly share code, notes, and snippets.

@sanogueralorenzo
Last active February 8, 2020 11:56
Show Gist options
  • Save sanogueralorenzo/03707bd493bbcdbbf8b38cfc81a64ecd to your computer and use it in GitHub Desktop.
Save sanogueralorenzo/03707bd493bbcdbbf8b38cfc81a64ecd to your computer and use it in GitHub Desktop.
fun <T> MutableLiveData<Resource<T>>.setSuccess(data: T? = null) =
postValue(Resource(ResourceState.SUCCESS, data))
fun <T> MutableLiveData<Resource<T>>.setLoading() =
postValue(Resource(ResourceState.LOADING, value?.data))
fun <T> MutableLiveData<Resource<T>>.setError(message: String? = null) =
postValue(Resource(ResourceState.ERROR, value?.data, message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment