Created
September 12, 2023 16:08
-
-
Save thomashorta/c1b2521328b762a0d34f84bc90ca0a6e to your computer and use it in GitHub Desktop.
Idea for a ViewModelSlice class that has a Coroutine Scope which is the same as the ViewModel it's "attached" to
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
open class ViewModelSlice { | |
protected lateinit var viewModelScope: CoroutineScope | |
private set | |
fun init(viewModel: ViewModel) { | |
viewModelScope = viewModel.viewModelScope | |
afterInit() | |
} | |
protected open fun afterInit() {} | |
companion object { | |
fun ViewModel.sliceInit(vararg slices: ViewModelSlice) { | |
slices.forEach { it.init(this) } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment