Skip to content

Instantly share code, notes, and snippets.

@rachitmishra
Last active December 27, 2018 09:26
Show Gist options
  • Save rachitmishra/6f795a5581f1c71c71673b94e4624d23 to your computer and use it in GitHub Desktop.
Save rachitmishra/6f795a5581f1c71c71673b94e4624d23 to your computer and use it in GitHub Desktop.
Extensions

Event Observer

inline fun <T> LiveData<Event<T>>.observeEvent(owner: LifecycleOwner, crossinline onEventUnhandledContent: (T) -> Unit) {
    observe(owner, Observer { it?.getContentIfNotHandled()?.let(onEventUnhandledContent) })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment