Created
March 16, 2020 16:09
-
-
Save Pluu/de84c5190ed81e9fb8f3d85ee4bb7f20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@MainThread | |
inline fun <reified VM : ViewModel> ComponentActivity.viewModels( | |
noinline factoryProducer: (() -> Factory)? = null | |
): Lazy<VM> { | |
val factoryPromise = factoryProducer ?: { | |
defaultViewModelProviderFactory | |
} | |
return ViewModelLazy(VM::class, { viewModelStore }, factoryPromise) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment