File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed
compose/src/commonMain/kotlin/com/powersync/compose
demos/supabase-todolist/shared/src/commonMain/kotlin/com/powersync/demos Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -6,13 +6,17 @@ import androidx.compose.runtime.collectAsState
66import com.powersync.sync.SyncStatus
77import com.powersync.sync.SyncStatusData
88import kotlinx.coroutines.FlowPreview
9+ import kotlinx.coroutines.flow.Flow
910import kotlinx.coroutines.flow.debounce
1011import kotlin.time.Duration
11- import kotlin.time.Duration.Companion.milliseconds
1212
1313@OptIn(FlowPreview ::class )
1414@Composable
15- public fun SyncStatus.composeState (debounce : Duration =200.0.milliseconds): State <SyncStatusData > = asFlow()
16- // Debouncing the status flow prevents flicker
17- .debounce(debounce)
18- .collectAsState(initial = this )
15+ public fun SyncStatus.composeState (debounce : Duration =Duration .ZERO ): State <SyncStatusData > {
16+ var flow: Flow <SyncStatusData > = asFlow()
17+ if (debounce.isPositive()) {
18+ flow = flow.debounce(debounce)
19+ }
20+
21+ return flow.collectAsState(initial = this )
22+ }
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import org.koin.core.module.dsl.bind
3535import org.koin.core.module.dsl.viewModelOf
3636import org.koin.core.module.dsl.withOptions
3737import org.koin.dsl.module
38+ import kotlin.time.Duration.Companion.milliseconds
3839
3940val sharedAppModule = module {
4041 // This is overridden by the androidBackgroundSync example
@@ -71,7 +72,7 @@ fun AppContent(
7172 db : PowerSyncDatabase = koinInject(),
7273 modifier : Modifier = Modifier ,
7374) {
74- val status by db.currentStatus.composeState()
75+ val status by db.currentStatus.composeState(debounce = 200.0 .milliseconds )
7576
7677 val authViewModel = koinViewModel<AuthViewModel >()
7778 val navController = koinInject<NavController >()
You can’t perform that action at this time.
0 commit comments