-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CoroutineScope parameter to stateIn function (GH-6)
- Loading branch information
1 parent
091dd2a
commit 2cb7c91
Showing
4 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
28 changes: 28 additions & 0 deletions
28
kmm-viewmodel-core/src/commonMain/kotlin/com/rickclephas/kmm/viewmodel/StateFlowUtils.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.rickclephas.kmm.viewmodel | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.plus | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
/** | ||
* @see kotlinx.coroutines.flow.stateIn | ||
*/ | ||
@Suppress("NOTHING_TO_INLINE") | ||
public inline fun <T> Flow<T>.stateIn( | ||
viewModelScope: ViewModelScope, | ||
started: SharingStarted, | ||
initialValue: T | ||
): StateFlow<T> = stateIn(viewModelScope, viewModelScope.coroutineScope, started, initialValue) | ||
|
||
/** | ||
* @see kotlinx.coroutines.flow.stateIn | ||
*/ | ||
@Suppress("NOTHING_TO_INLINE") | ||
public inline fun <T> Flow<T>.stateIn( | ||
viewModelScope: ViewModelScope, | ||
context: CoroutineContext, | ||
started: SharingStarted, | ||
initialValue: T | ||
): StateFlow<T> = stateIn(viewModelScope, viewModelScope.coroutineScope + context, started, initialValue) |