Skip to content

Instantly share code, notes, and snippets.

@hasanmohdkhan
Forked from adam-hurwitz/Fragment.kt
Created July 7, 2020 20:58
Show Gist options
  • Save hasanmohdkhan/f6c2e73c5a4e9b2f0a076a442ab6045d to your computer and use it in GitHub Desktop.
Save hasanmohdkhan/f6c2e73c5a4e9b2f0a076a442ab6045d to your computer and use it in GitHub Desktop.
Optimizing ViewModel with Lifecycle 2.2.0: Declaring VM val
class Fragment : Fragment() {
private val viewModel: SomeViewModel by viewModels()
private fun observeViewState() {
viewModel.viewState.observe(viewLifecycleOwner) { viewState ->
//viewState used here.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment