Refactor | Added extension functions#454
Refactor | Added extension functions#454LinX64 wants to merge 9 commits intoandroid:mainfrom LinX64:refactor_extension_function
Conversation
…ViewModels This commit also includes refactoring for functions, making functions more clear by extracting them inside ViewModels.
There are two extension functions in this file, one is for ViewModels, and another one for using within a CoroutineScope.
| * with the [initialValue]. | ||
| */ | ||
| fun <T> Flow<T>.stateInCoroutineScope( | ||
| viewModelScope: CoroutineScope, |
There was a problem hiding this comment.
| viewModelScope: CoroutineScope, | |
| coroutineScope: CoroutineScope, |
Removed the other extension, and used it with different configuration everywhere.
This was causing a leak of a job, and it was supposed to return Unit!
|
Unsure about adding this API / helper function to the Now in Android app. It just saves you one line of code and the name (currently The ideal API for this would be a context receiver on both Until context receivers aren't widely available in Android and Compose, I'd refrain from adding a helper function for this functionality in a highly visible Android sample. |
|
Closing this PR as it is suggested to use Context receivers as a solution/replacement for the implementation. P.S: This PR can wait for the Context Receivers to be available widely on Android and Kotlin. |
This PR is about polishing codes, and using extension functions for
StateIn()(mostly in ViewModels).Basically, all of the
StateIn()functions inside ViewModels were following/using the same pattern, so I decided to create two extension functions for use in bothViewModels usingviewModelScope, as well asCoroutineScopeoutside ofViewModels.