Skip to content

Commit a83a143

Browse files
committed
Refactor: Make DebounceMs and ThrottleMs required and update Empty instances in debouncers
1 parent 6177ba9 commit a83a143

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

src/CodeOfChaos.Extensions.AspNetCore.Components/EventCallbacks/EventCallbackDebouncer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public sealed class EventCallbackDebouncer : DebouncerBase<EventCallbackDebounce
1717
public override bool IsEmpty => _isEmpty;
1818
public static EventCallbackDebouncer Empty => new() {
1919
Callback = default,
20-
_isEmpty = true
20+
_isEmpty = true,
21+
DebounceMs = -1
2122
};
2223

2324
// -----------------------------------------------------------------------------------------------------------------
@@ -49,7 +50,8 @@ public sealed class EventCallbackDebouncer<T> : DebouncerBase<T>, IDebouncer, ID
4950
public override bool IsEmpty => _isEmpty;
5051
public static EventCallbackDebouncer<T> Empty => new() {
5152
Callback = default,
52-
_isEmpty = true
53+
_isEmpty = true,
54+
DebounceMs = -1
5355
};
5456

5557
// -----------------------------------------------------------------------------------------------------------------

src/CodeOfChaos.Extensions/Debouncers/Regular/Debouncer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public sealed class Debouncer: DebouncerBase<Debouncer.EmptyUnit>, IDebouncer {
1212
public override bool IsEmpty => Callback is null;
1313

1414
public static Debouncer Empty => new() {
15-
Callback = null
15+
Callback = null,
16+
DebounceMs = -1
1617
};
1718

1819
// -----------------------------------------------------------------------------------------------------------------
@@ -73,7 +74,8 @@ public sealed class Debouncer<T> : DebouncerBase<T>, IDebouncer<T> {
7374
public override bool IsEmpty => Callback is null;
7475

7576
public static Debouncer<T> Empty => new() {
76-
Callback = null
77+
Callback = null,
78+
DebounceMs = -1
7779
};
7880

7981
// -----------------------------------------------------------------------------------------------------------------

src/CodeOfChaos.Extensions/Debouncers/Regular/DebouncerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace CodeOfChaos.Extensions.Debouncers;
1010
// ---------------------------------------------------------------------------------------------------------------------
1111
public abstract class DebouncerBase<T> : IAsyncDisposable {
1212
protected const int DefaultDebounceMs = 100;
13-
protected int DebounceMs { get; init; } = DefaultDebounceMs;
13+
public required int DebounceMs { get; init; }
1414

1515
private readonly SemaphoreSlim _semaphore = new(1, 1);
1616
private readonly Lock _stateLock = new();

src/CodeOfChaos.Extensions/Debouncers/Throttled/ThrottledDebouncer.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ public sealed class ThrottledDebouncer: ThrottledDebouncerBase<ThrottledDebounce
1212
public override bool IsEmpty => Callback is null;
1313

1414
public static ThrottledDebouncer Empty => new() {
15-
Callback = null
15+
Callback = null,
16+
DebounceMs = -1,
17+
ThrottleMs = -1
1618
};
1719

1820
// -----------------------------------------------------------------------------------------------------------------
@@ -76,7 +78,9 @@ public sealed class ThrottledDebouncer<T> : ThrottledDebouncerBase<T>, IDebounce
7678
public override bool IsEmpty => Callback is null;
7779

7880
public static ThrottledDebouncer<T> Empty => new() {
79-
Callback = null
81+
Callback = null,
82+
DebounceMs = -1,
83+
ThrottleMs = -1
8084
};
8185

8286
// -----------------------------------------------------------------------------------------------------------------

src/CodeOfChaos.Extensions/Debouncers/Throttled/ThrottledDebouncerBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public abstract class ThrottledDebouncerBase<T> : IAsyncDisposable {
1111
protected const int DefaultDebounceMs = 100;
1212
protected const int DefaultThrottleMs = 100;
1313

14-
protected int DebounceMs { get; init; } = DefaultDebounceMs;
15-
protected int ThrottleMs { get; init; } = DefaultThrottleMs;
14+
public required int DebounceMs { get; init; }
15+
public required int ThrottleMs { get; init; }
1616

1717
private readonly SemaphoreSlim _semaphore = new(1, 1);
1818
private readonly Lock _stateLock = new();

0 commit comments

Comments
 (0)