Skip to content

Instantly share code, notes, and snippets.

@TroyStopera
Created September 20, 2019 16:58
Show Gist options
  • Save TroyStopera/4f061cce797adc97547c3951e3886d91 to your computer and use it in GitHub Desktop.
Save TroyStopera/4f061cce797adc97547c3951e3886d91 to your computer and use it in GitHub Desktop.
LiveData observe lambda
import androidx.lifecycle.*
fun <T> LiveData<T>.observe(lifecycleOwner: LifecycleOwner, callback: (T) -> Unit): Observer {
val observer = Observer(callback)
this.observe(lifecyleOwner, observer)
return observer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment