Skip to content

Commit

Permalink
Ensure updating subscriptions loading state is atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
mr3y-the-programmer committed Aug 17, 2024
1 parent 62f1bea commit 5a0b25d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.runtime.snapshots.Snapshot
import app.cash.molecule.RecompositionMode
import app.cash.molecule.launchMolecule
import com.mr3y.podcaster.core.data.PodcastsRepository
Expand Down Expand Up @@ -68,8 +69,10 @@ internal fun SubscriptionsPresenter(

if (podcasts.isEmpty() || episodes.isEmpty()) {
delay(1000)
isSubscriptionsLoading = false
isEpisodesLoading = false
Snapshot.withMutableSnapshot {
isSubscriptionsLoading = false
isEpisodesLoading = false
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ class SubscriptionsPresenterTest : BasePresenterTest<SubscriptionsUIEvent>() {
assertThat(currentState.episodes).isEmpty()
currentState = awaitItem()
assertThat(currentState.subscriptions).isEqualTo(listOf(Podcasts[0]))
// each episode addition triggers separate state update, and we added 2 episodes
assertThat(currentState.episodes).hasSize(1)
currentState = awaitItem()
assertThat(currentState.episodes).hasSize(2)

expectNoEvents()
Expand Down

0 comments on commit 5a0b25d

Please sign in to comment.