Skip to content

Commit f2b97a6

Browse files
authored
Merge pull request #52 from cashapp/jw/minimal-docs/2021-11-10
Minimal KDoc so we can ship a release
2 parents 5fc5649 + cab089f commit f2b97a6

File tree

1 file changed

+22
-0
lines changed
  • molecule/molecule-runtime/src/main/java/app/cash/molecule

1 file changed

+22
-0
lines changed

molecule/molecule-runtime/src/main/java/app/cash/molecule/molecule.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package app.cash.molecule
1818
import androidx.compose.runtime.AbstractApplier
1919
import androidx.compose.runtime.Composable
2020
import androidx.compose.runtime.Composition
21+
import androidx.compose.runtime.MonotonicFrameClock
2122
import androidx.compose.runtime.Recomposer
2223
import androidx.compose.runtime.snapshots.Snapshot
2324
import kotlinx.coroutines.CoroutineScope
@@ -30,6 +31,13 @@ import kotlinx.coroutines.flow.channelFlow
3031
import kotlinx.coroutines.job
3132
import kotlinx.coroutines.launch
3233

34+
/**
35+
* Create a [Flow] which will continually recompose `body` to produce a stream of [T] values
36+
* when collected.
37+
*
38+
* The [CoroutineScope] in which the returned [Flow] is collected must contain a
39+
* [MonotonicFrameClock] key which controls when recomposition occurs.
40+
*/
3341
@OptIn(ExperimentalCoroutinesApi::class) // Marked as stable in kotlinx.coroutines 1.6.
3442
fun <T> moleculeFlow(body: @Composable () -> T): Flow<T> {
3543
return channelFlow {
@@ -42,6 +50,13 @@ fun <T> moleculeFlow(body: @Composable () -> T): Flow<T> {
4250
}
4351
}
4452

53+
/**
54+
* Launch a coroutine into this [CoroutineScope] which will continually recompose `body`
55+
* to produce a [StateFlow] stream of [T] values.
56+
*
57+
* The [CoroutineScope] in which this [StateFlow] is created must contain a
58+
* [MonotonicFrameClock] key which controls when recomposition occurs.
59+
*/
4560
fun <T> CoroutineScope.launchMolecule(
4661
body: @Composable () -> T,
4762
): StateFlow<T> {
@@ -62,6 +77,13 @@ fun <T> CoroutineScope.launchMolecule(
6277
return flow!!
6378
}
6479

80+
/**
81+
* Launch a coroutine into this [CoroutineScope] which will continually recompose `body`
82+
* to invoke [emitter] with each returned [T] value.
83+
*
84+
* The [CoroutineScope] in which this [StateFlow] is created must contain a
85+
* [MonotonicFrameClock] key which controls when recomposition occurs.
86+
*/
6587
fun <T> CoroutineScope.launchMolecule(
6688
emitter: (value: T) -> Unit,
6789
body: @Composable () -> T,

0 commit comments

Comments
 (0)