From f5bd69868e0633e83f47749e8fb2050ed913696c Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 9 Sep 2024 17:09:44 +0200 Subject: [PATCH] Added UiService to debounce actions --- .../kotlin/net/codinux/banking/ui/config/DI.kt | 2 ++ .../net/codinux/banking/ui/service/UiService.kt | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/UiService.kt diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/DI.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/DI.kt index d33974b..101b158 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/DI.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/config/DI.kt @@ -31,6 +31,8 @@ object DI { val accountTransactionsFilterService = AccountTransactionsFilterService() + val uiService = UiService() + var bankingRepository: BankingRepository = InMemoryBankingRepository(emptyList()) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/UiService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/UiService.kt new file mode 100644 index 0000000..29193f0 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/UiService.kt @@ -0,0 +1,14 @@ +package net.codinux.banking.ui.service + +import kotlinx.coroutines.* + +class UiService { + + fun debounce(coroutineScope: CoroutineScope, action: () -> Unit): Job { + return coroutineScope.launch { + delay(250) + action() + } + } + +} \ No newline at end of file