mertceyhan
10/31/2021, 5:12 PMRafal
10/31/2021, 5:23 PMmertceyhan
10/31/2021, 5:31 PMAdam Powell
10/31/2021, 5:52 PMsnapshotFlow {}
to get a flow from snapshot state changesAdam Powell
10/31/2021, 5:52 PMRafal
10/31/2021, 7:42 PMRafal
10/31/2021, 7:43 PMMini
10/31/2021, 9:50 PMsnapshotFlow { viewModel.uiState }.test {
expectItem().shouldBeInstanceOf< UiState.Loading>
expectItem().shouldBeInstanceOf<UiState.Success>
}
Perhaps a different assertion is in order (I dont remember which one you would use with junit)mertceyhan
11/01/2021, 2:19 PMsnapshotFlow
but when I start to collect it, it just prints 0
. What is the missing point? The sample from the doc https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#snapshotFlow(kotlin.Function0)Adam Powell
11/01/2021, 3:48 PMrunBlocking
. Your Snapshot.withMutableSnapshot
block is not running.Adam Powell
11/01/2021, 3:50 PMSnapshot.withMutableSnapshot
block, the observer would see an initial value of 0
followed by 3
as 3
is the value of state
when the snapshot commits. If more changes happened and committed before the collector coroutine could resume, the collector would see only the latest value. State never guarantees that you see every value assigned and committed, only the latest available when the observer runs.mertceyhan
11/01/2021, 4:44 PM