-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added StateFlow.onStateSubscription and use dispatchers.main for bett…
…er iOS interop
- Loading branch information
1 parent
cfbd339
commit 19510f3
Showing
16 changed files
with
104 additions
and
53 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
38 changes: 38 additions & 0 deletions
38
reactivestate-core/src/commonMain/kotlin/com/ensody/reactivestate/RefreshableStateFlow.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,38 @@ | ||
package com.ensody.reactivestate | ||
|
||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
/** | ||
* A [StateFlow] which can retrieve a new value e.g. from a backend via [refresh]. | ||
*/ | ||
@ExperimentalReactiveStateApi | ||
public interface RefreshableStateFlow<T> : StateFlow<T> { | ||
/** | ||
* Refreshes the [value]. | ||
* | ||
* @param force Can enforce refreshing the value and bypassing any caching mechanism. | ||
*/ | ||
public suspend fun refresh(force: Boolean = false) | ||
} | ||
|
||
@ExperimentalReactiveStateApi | ||
public fun <T> MutableStateFlow<T>.withRefresh( | ||
block: suspend MutableStateFlow<T>.(force: Boolean) -> Unit, | ||
): RefreshableStateFlow<T> = | ||
DefaultRefreshableStateFlow(this) { block(it) } | ||
|
||
@ExperimentalReactiveStateApi | ||
public fun <T> StateFlow<T>.withRefresh( | ||
block: suspend StateFlow<T>.(force: Boolean) -> Unit, | ||
): RefreshableStateFlow<T> = | ||
DefaultRefreshableStateFlow(this) { block(it) } | ||
|
||
private class DefaultRefreshableStateFlow<T>( | ||
private val delegate: StateFlow<T>, | ||
private val refresher: suspend (force: Boolean) -> Unit, | ||
) : RefreshableStateFlow<T>, StateFlow<T> by delegate { | ||
override suspend fun refresh(force: Boolean) { | ||
refresher(force) | ||
} | ||
} |
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
Oops, something went wrong.