RapidTravel impr, GoBack/Forward, header navigation

This commit is contained in:
2023-08-03 20:00:55 +02:00
parent 754496625e
commit d6c4f16fc2
22 changed files with 1034 additions and 81 deletions

View File

@@ -3,7 +3,7 @@
public sealed class DebounceProperty<T> : DeclarativePropertyBase<T>
{
private readonly object _lock = new();
private readonly Func<TimeSpan> _interval;
private readonly Func<T?, TimeSpan> _interval;
private DateTime _startTime = DateTime.MinValue;
private T? _nextValue;
private CancellationToken _nextCancellationToken;
@@ -13,7 +13,7 @@ public sealed class DebounceProperty<T> : DeclarativePropertyBase<T>
public DebounceProperty(
IDeclarativeProperty<T> from,
Func<TimeSpan> interval,
Func<T?, TimeSpan> interval,
Action<T?>? setValueHook = null) : base(from.Value, setValueHook)
{
_interval = interval;
@@ -46,7 +46,7 @@ public sealed class DebounceProperty<T> : DeclarativePropertyBase<T>
private async Task StartDebounceTask()
{
while (DateTime.Now - _startTime < _interval())
while (DateTime.Now - _startTime < _interval(_nextValue))
{
await Task.Delay(WaitInterval);
}

View File

@@ -16,6 +16,9 @@ public static class DeclarativePropertyHelpers
Func<T1, T2, T3, Task<TResult>> func,
Action<TResult?>? setValueHook = null)
=> new(prop1, prop2, prop3, func, setValueHook);
public static MergeProperty<T> Merge<T>(params IDeclarativeProperty<T>[] props)
=> new(props);
}
public sealed class DeclarativeProperty<T> : DeclarativePropertyBase<T>

View File

@@ -7,9 +7,9 @@ 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)
public static IDeclarativeProperty<T> Debounce<T>(this IDeclarativeProperty<T> from, Func<T?, TimeSpan> interval, bool resetTimer = false)
=> new DebounceProperty<T>(from, interval) {ResetTimer = resetTimer};
public static IDeclarativeProperty<T> Throttle<T>(this IDeclarativeProperty<T> from, TimeSpan interval)

View File

@@ -0,0 +1,17 @@
namespace DeclarativeProperty;
public class MergeProperty<T> : DeclarativePropertyBase<T>
{
public MergeProperty(params IDeclarativeProperty<T>[] props)
{
ArgumentNullException.ThrowIfNull(props);
foreach (var prop in props)
{
prop.Subscribe(UpdateAsync);
}
}
private async Task UpdateAsync(T? newValue, CancellationToken token)
=> await SetNewValueAsync(newValue, token);
}