From 602260b55c649fac7f8ea419c955bb2e02d467e0 Mon Sep 17 00:00:00 2001 From: Daniil Marchenko Date: Tue, 30 Jan 2024 19:25:44 +0200 Subject: [PATCH 1/2] update throttling dependency --- lib/implementations/debounce_lang_tool_service.dart | 6 +++--- lib/implementations/throttling_lang_tool_service.dart | 2 +- pubspec.yaml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/implementations/debounce_lang_tool_service.dart b/lib/implementations/debounce_lang_tool_service.dart index e83c215..eb9fa60 100644 --- a/lib/implementations/debounce_lang_tool_service.dart +++ b/lib/implementations/debounce_lang_tool_service.dart @@ -9,7 +9,7 @@ class DebounceLangToolService extends LanguageCheckService { final LanguageCheckService baseService; /// A debouncing used to debounce the API calls. - final Debouncing debouncing; + final Debouncing>?>> debouncing; /// Creates a new instance of the [DebounceLangToolService] class. DebounceLangToolService( @@ -20,7 +20,7 @@ class DebounceLangToolService extends LanguageCheckService { @override Future>> findMistakes(String text) async { final value = - await debouncing.debounce(() => baseService.findMistakes(text)) + (await debouncing.debounce(() => baseService.findMistakes(text)) ?? []) as Result>; return value; @@ -28,7 +28,7 @@ class DebounceLangToolService extends LanguageCheckService { @override Future dispose() async { - await debouncing.close(); + debouncing.close(); await baseService.dispose(); } } diff --git a/lib/implementations/throttling_lang_tool_service.dart b/lib/implementations/throttling_lang_tool_service.dart index ece37db..f9419fa 100644 --- a/lib/implementations/throttling_lang_tool_service.dart +++ b/lib/implementations/throttling_lang_tool_service.dart @@ -30,7 +30,7 @@ class ThrottlingLangToolService extends LanguageCheckService { @override Future dispose() async { - await throttling.close(); + throttling.close(); await baseService.dispose(); } } diff --git a/pubspec.yaml b/pubspec.yaml index de4706a..ed96e8a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: flutter: sdk: flutter http: ^1.0.0 - throttling: ^1.0.0 + throttling: ^2.0.1 dev_dependencies: flutter_test: From c49dc3b74efadc82e8df22e1fb1494a1765a0506 Mon Sep 17 00:00:00 2001 From: Daniil Marchenko Date: Tue, 30 Jan 2024 20:32:42 +0200 Subject: [PATCH 2/2] rm type casts --- lib/implementations/debounce_lang_tool_service.dart | 9 ++------- .../throttling_lang_tool_service.dart | 12 +++--------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/implementations/debounce_lang_tool_service.dart b/lib/implementations/debounce_lang_tool_service.dart index eb9fa60..ec03d37 100644 --- a/lib/implementations/debounce_lang_tool_service.dart +++ b/lib/implementations/debounce_lang_tool_service.dart @@ -18,13 +18,8 @@ class DebounceLangToolService extends LanguageCheckService { ) : debouncing = Debouncing(duration: debouncingDuration); @override - Future>> findMistakes(String text) async { - final value = - (await debouncing.debounce(() => baseService.findMistakes(text)) ?? []) - as Result>; - - return value; - } + Future>?> findMistakes(String text) async => + await debouncing.debounce(() => baseService.findMistakes(text)); @override Future dispose() async { diff --git a/lib/implementations/throttling_lang_tool_service.dart b/lib/implementations/throttling_lang_tool_service.dart index f9419fa..5b851d0 100644 --- a/lib/implementations/throttling_lang_tool_service.dart +++ b/lib/implementations/throttling_lang_tool_service.dart @@ -10,7 +10,7 @@ class ThrottlingLangToolService extends LanguageCheckService { final LanguageCheckService baseService; /// A throttling used to throttle the API calls. - final Throttling throttling; + final Throttling>?>> throttling; /// Creates a new instance of the [ThrottlingLangToolService] class. ThrottlingLangToolService( @@ -19,14 +19,8 @@ class ThrottlingLangToolService extends LanguageCheckService { ) : throttling = Throttling(duration: throttlingDuration); @override - Future>?> findMistakes(String text) async { - final future = throttling.throttle(() => baseService.findMistakes(text)) - as Future>?>?; - - if (future == null) return null; - - return future.then((res) => res ?? Result.success([].toList())); - } + Future>?> findMistakes(String text) async => + throttling.throttle(() => baseService.findMistakes(text)); @override Future dispose() async {