Skip to content

Commit 7b6ce58

Browse files
committed
Don't debounce by default
1 parent 5aefa29 commit 7b6ce58

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

2 files changed

+11
-6
lines changed

compose/src/commonMain/kotlin/com/powersync/compose/DatabaseState.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import androidx.compose.runtime.collectAsState
66
import com.powersync.sync.SyncStatus
77
import com.powersync.sync.SyncStatusData
88
import kotlinx.coroutines.FlowPreview
9+
import kotlinx.coroutines.flow.Flow
910
import kotlinx.coroutines.flow.debounce
1011
import 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+
}

demos/supabase-todolist/shared/src/commonMain/kotlin/com/powersync/demos/App.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import org.koin.core.module.dsl.bind
3535
import org.koin.core.module.dsl.viewModelOf
3636
import org.koin.core.module.dsl.withOptions
3737
import org.koin.dsl.module
38+
import kotlin.time.Duration.Companion.milliseconds
3839

3940
val 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>()

0 commit comments

Comments
 (0)