Admin mode WIP
This commit is contained in:
@@ -10,7 +10,7 @@ public sealed class DebounceProperty<T> : TimingPropertyBase<T>
|
||||
|
||||
public DebounceProperty(
|
||||
IDeclarativeProperty<T> from,
|
||||
TimeSpan interval,
|
||||
Func<TimeSpan> interval,
|
||||
Action<T?>? setValueHook = null) : base(from, interval, setValueHook)
|
||||
{
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public sealed class DebounceProperty<T> : TimingPropertyBase<T>
|
||||
{
|
||||
try
|
||||
{
|
||||
while (DateTime.Now - _startTime < Interval)
|
||||
while (DateTime.Now - _startTime < Interval())
|
||||
{
|
||||
await Task.Delay(WaitInterval, newToken);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,10 @@ namespace DeclarativeProperty;
|
||||
public static class DeclarativePropertyExtensions
|
||||
{
|
||||
public static IDeclarativeProperty<T> Debounce<T>(this IDeclarativeProperty<T> from, TimeSpan interval, bool resetTimer = false)
|
||||
=> new DebounceProperty<T>(from, interval){ResetTimer = resetTimer};
|
||||
=> new DebounceProperty<T>(from, () => interval) {ResetTimer = resetTimer};
|
||||
|
||||
public static IDeclarativeProperty<T> Debounce<T>(this IDeclarativeProperty<T> from, Func<TimeSpan> interval, bool resetTimer = false)
|
||||
=> new DebounceProperty<T>(from, interval) {ResetTimer = resetTimer};
|
||||
|
||||
public static IDeclarativeProperty<T> DistinctUntilChanged<T>(this IDeclarativeProperty<T> from)
|
||||
=> new DistinctUntilChangedProperty<T>(from);
|
||||
|
||||
@@ -7,7 +7,7 @@ public class ThrottleProperty<T> : TimingPropertyBase<T>
|
||||
|
||||
public ThrottleProperty(
|
||||
IDeclarativeProperty<T> from,
|
||||
TimeSpan interval,
|
||||
Func<TimeSpan> interval,
|
||||
Action<T?>? setValueHook = null) : base(from, interval, setValueHook)
|
||||
{
|
||||
}
|
||||
@@ -15,7 +15,8 @@ public class ThrottleProperty<T> : TimingPropertyBase<T>
|
||||
protected override Task SetValue(T? next, CancellationToken cancellationToken = default)
|
||||
{
|
||||
_debounceCts?.Cancel();
|
||||
if (DateTime.Now - _lastFired > Interval)
|
||||
var interval = Interval();
|
||||
if (DateTime.Now - _lastFired > interval)
|
||||
{
|
||||
_lastFired = DateTime.Now;
|
||||
// Note: Recursive chains can happen. Awaiting this can cause a deadlock.
|
||||
@@ -28,7 +29,7 @@ public class ThrottleProperty<T> : TimingPropertyBase<T>
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(Interval, _debounceCts.Token);
|
||||
await Task.Delay(interval, _debounceCts.Token);
|
||||
await FireIfNeededAsync(
|
||||
next,
|
||||
() => { _lastFired = DateTime.Now; },
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
public abstract class TimingPropertyBase<T> : DeclarativePropertyBase<T>
|
||||
{
|
||||
private readonly SemaphoreSlim _semaphore = new(1, 1);
|
||||
protected TimeSpan Interval { get; }
|
||||
protected Func<TimeSpan> Interval { get; }
|
||||
|
||||
protected TimingPropertyBase(
|
||||
IDeclarativeProperty<T> from,
|
||||
TimeSpan interval,
|
||||
Func<TimeSpan> interval,
|
||||
Action<T?>? setValueHook = null) : base(from.Value, setValueHook)
|
||||
{
|
||||
Interval = interval;
|
||||
@@ -65,7 +65,7 @@ public abstract class TimingPropertyBase<T> : DeclarativePropertyBase<T>
|
||||
CancellationToken timingCancellationToken = default,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
await Task.Delay(Interval, timingCancellationToken);
|
||||
await Task.Delay(Interval(), timingCancellationToken);
|
||||
var shouldFire = WithLock(() =>
|
||||
{
|
||||
if (timingCancellationToken.IsCancellationRequested)
|
||||
|
||||
Reference in New Issue
Block a user