-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/microsoft/fluentui-blazor in…
…to dev
- Loading branch information
Showing
14 changed files
with
928 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ------------------------------------------------------------------------ | ||
// MIT License - Copyright (c) Microsoft Corporation. All rights reserved. | ||
// ------------------------------------------------------------------------ | ||
|
||
namespace Microsoft.FluentUI.AspNetCore.Components.Utilities; | ||
|
||
/// <summary> | ||
/// The DebounceTask dispatcher delays the invocation of an action until a predetermined interval has elapsed since the last call. | ||
/// This ensures that the action is only invoked once after the calls have stopped for the specified duration. | ||
/// </summary> | ||
public sealed class Debounce : InternalDebounce.DebounceTask | ||
{ | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// ------------------------------------------------------------------------ | ||
// MIT License - Copyright (c) Microsoft Corporation. All rights reserved. | ||
// ------------------------------------------------------------------------ | ||
|
||
namespace Microsoft.FluentUI.AspNetCore.Components.Utilities.InternalDebounce; | ||
|
||
/// <summary> | ||
/// The DebounceTask dispatcher delays the invocation of an action until a predetermined interval has elapsed since the last call. | ||
/// This ensures that the action is only invoked once after the calls have stopped for the specified duration. | ||
/// </summary> | ||
[Obsolete("Use Debounce, which inherits from DebounceTask.")] | ||
internal class DebounceAction : IDisposable | ||
{ | ||
private bool _disposed; | ||
private readonly System.Timers.Timer _timer = new(); | ||
private TaskCompletionSource? _taskCompletionSource; | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether the DebounceTask dispatcher is busy. | ||
/// </summary> | ||
public bool Busy => _taskCompletionSource?.Task.Status == TaskStatus.Running && !_disposed; | ||
|
||
/// <summary> | ||
/// Gets the current task. | ||
/// </summary> | ||
public Task CurrentTask => _taskCompletionSource?.Task ?? Task.CompletedTask; | ||
|
||
/// <summary> | ||
/// Delays the invocation of an action until a predetermined interval has elapsed since the last call. | ||
/// </summary> | ||
/// <param name="milliseconds"></param> | ||
/// <param name="action"></param> | ||
/// <exception cref="ArgumentOutOfRangeException"></exception> | ||
public void Run(int milliseconds, Func<Task> action) | ||
{ | ||
// Check arguments | ||
if (milliseconds <= 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(milliseconds), milliseconds, "The milliseconds must be greater than to zero."); | ||
} | ||
|
||
ArgumentNullException.ThrowIfNull(action); | ||
|
||
// DebounceTask | ||
if (!_disposed) | ||
{ | ||
_taskCompletionSource = _timer.Debounce(action, milliseconds); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Delays the invocation of an action until a predetermined interval has elapsed since the last call. | ||
/// </summary> | ||
/// <param name="milliseconds"></param> | ||
/// <param name="action"></param> | ||
/// <exception cref="ArgumentOutOfRangeException"></exception> | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD003:Avoid awaiting foreign Tasks", Justification = "Required to return the current Task.")] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MA0042:Do not use blocking calls in an async method", Justification = "Special case using CurrentTask")] | ||
public Task RunAsync(int milliseconds, Func<Task> action) | ||
{ | ||
Run(milliseconds, action); | ||
return CurrentTask; | ||
} | ||
|
||
/// <summary> | ||
/// Releases all resources used by the DebounceTask dispatcher. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
_taskCompletionSource = null; | ||
_timer.Dispose(); | ||
_disposed = true; | ||
GC.SuppressFinalize(this); | ||
} | ||
} |
Oops, something went wrong.