Skip to content

Commit 51f91d9

Browse files
committed
+chore: Update dependencies
1 parent d3bb5e3 commit 51f91d9

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

lib/src/debouncer.dart

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
import 'dart:async' show FutureOr, Timer;
1414

15-
import 'package:df_type/df_type.dart' show Sequential;
15+
import 'package:df_safer_dart/df_safer_dart.dart';
16+
17+
typedef _VoidCallback = FutureOr<void> Function();
1618

1719
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
1820

@@ -25,25 +27,35 @@ final class Debouncer {
2527

2628
Timer? _timer;
2729
bool _hasStarted = false;
28-
final _sequential = Sequential();
30+
final _sequencer = SafeSequencer();
2931

3032
/// The function to call once at the very beginning.
31-
final FutureOr<void> Function()? onStart;
33+
final _VoidCallback? _onStart;
34+
_VoidCallback? get onStart => _onStart;
3235

3336
/// The function to call after the [delay] has passed.
34-
final FutureOr<void> Function()? onWaited;
37+
final _VoidCallback? _onWaited;
38+
_VoidCallback? get onWaited => _onWaited;
3539

3640
/// The function to call immediately.
37-
final FutureOr<void> Function()? onCall;
41+
final _VoidCallback? _onCall;
42+
_VoidCallback? get onCall => _onCall;
3843

39-
/// The delay before calling the [onWaited] function.
44+
/// The delay before calling the [_onWaited] function.
4045
final Duration delay;
4146

4247
//
4348
//
4449
//
4550

46-
Debouncer({required this.delay, this.onStart, this.onWaited, this.onCall});
51+
Debouncer({
52+
required this.delay,
53+
FutureOr<void> Function()? onStart,
54+
FutureOr<void> Function()? onWaited,
55+
FutureOr<void> Function()? onCall,
56+
}) : _onCall = onCall,
57+
_onWaited = onWaited,
58+
_onStart = onStart;
4759

4860
//
4961
//
@@ -58,31 +70,31 @@ final class Debouncer {
5870
}) {
5971
cancel();
6072
if (!_hasStarted) {
61-
if (this.onStart != null) {
62-
_sequential.add((_) => this.onStart!());
73+
if (_onStart != null) {
74+
_sequencer.add(_onStart);
6375
}
6476
if (onStart != null) {
65-
_sequential.add((_) => onStart());
77+
_sequencer.add(onStart);
6678
}
6779
_hasStarted = true;
6880
}
69-
if (this.onCall != null) {
70-
_sequential.add((_) => this.onCall!());
81+
if (_onCall != null) {
82+
_sequencer.add(_onCall);
7183
}
7284
if (onCall != null) {
73-
_sequential.add((_) => onCall());
85+
_sequencer.add(onCall);
7486
}
7587
_timer = Timer(delay, () {
76-
if (this.onWaited != null) {
77-
_sequential.add((_) => this.onWaited!());
88+
if (_onWaited != null) {
89+
_sequencer.add(_onWaited);
7890
}
7991
if (onWaited != null) {
80-
_sequential.add((_) => onWaited());
92+
_sequencer.add(onWaited);
8193
}
8294
_hasStarted = false;
8395
});
8496

85-
return _sequential.last;
97+
return _sequencer.last.value;
8698
}
8799

88100
//
@@ -92,13 +104,13 @@ final class Debouncer {
92104
/// Finalizes the debouncer and calls the [onWaited] function.
93105
FutureOr<void> finalize({FutureOr<void> Function()? onWaited}) {
94106
if (cancel()) {
95-
if (this.onWaited != null) {
96-
_sequential.add((_) => this.onWaited!());
107+
if (_onWaited != null) {
108+
_sequencer.add(_onWaited);
97109
}
98110
if (onWaited != null) {
99-
_sequential.add((_) => onWaited());
111+
_sequencer.add(onWaited);
100112
}
101-
return _sequential.last;
113+
return _sequencer.last.value;
102114
}
103115
}
104116

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
name: df_debouncer
1414
description: A package that provides a practical Debouncer for optimizing performance by controlling the frequency of function calls in response to rapid events.
15-
version: 0.4.9
15+
version: 0.4.10
1616
homepage: https://dev-cetera.com/
1717
repository: https://github.com/dev-cetera/df_debouncer
1818
funding:
@@ -32,8 +32,8 @@ environment:
3232
## -----------------------------------------------------------------------------
3333

3434
dependencies:
35-
df_type: ^0.10.4
36-
df_safer_dart: ^0.13.1
35+
df_type: ^0.12.3
36+
df_safer_dart: ^0.13.14
3737

3838
## -----------------------------------------------------------------------------
3939

0 commit comments

Comments
 (0)