Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor internal frame tracking & time handling #29

Merged
merged 19 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
introduce ITimer interface
  • Loading branch information
DavidVollmers committed Sep 29, 2023
commit ea63ca3fd52c1d384d6e0d9730bd23e5da420b18
7 changes: 7 additions & 0 deletions packages/Ignis.Components/ITimer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Ignis.Components;

//TODO switch to System.Threading.ITimer when it's available

Check warning on line 3 in packages/Ignis.Components/ITimer.cs

View workflow job for this annotation

GitHub Actions / Test

TODO switch to System.Threading.ITimer when it's available (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 3 in packages/Ignis.Components/ITimer.cs

View workflow job for this annotation

GitHub Actions / Test

TODO switch to System.Threading.ITimer when it's available (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)
// https://learn.microsoft.com/en-us/dotnet/api/system.threading.itimer?view=net-8.0
internal interface ITimer : IDisposable
{
}
2 changes: 1 addition & 1 deletion packages/Ignis.Components/IgnisComponentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static IServiceCollection AddIgnis(this IServiceCollection serviceCollect

serviceCollection.TryAddScoped<IContentRegistry, ContentRegistry>();

serviceCollection.TryAddSingleton<TimeProvider, IgnisTimeProvider>();
serviceCollection.TryAddSingleton<TimeProvider, TimeProviderImplementation>();

return serviceCollection;
}
Expand Down
5 changes: 0 additions & 5 deletions packages/Ignis.Components/IgnisTimeProvider.cs

This file was deleted.

4 changes: 2 additions & 2 deletions packages/Ignis.Components/TimeProvider.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace Ignis.Components;

//TODO switch to System.TimeProvider when it's available

Check warning on line 3 in packages/Ignis.Components/TimeProvider.cs

View workflow job for this annotation

GitHub Actions / Test

Check warning on line 3 in packages/Ignis.Components/TimeProvider.cs

View workflow job for this annotation

GitHub Actions / Test

// https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider?view=net-8.0
internal abstract class TimeProvider
{
public virtual Timer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
public virtual ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
{
return new Timer(callback, state, dueTime, period);
return new TimerImplementation(callback, state, dueTime, period);
}
}
5 changes: 5 additions & 0 deletions packages/Ignis.Components/TimeProviderImplementation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Ignis.Components;

internal class TimeProviderImplementation : TimeProvider
{
}
16 changes: 16 additions & 0 deletions packages/Ignis.Components/TimerImplementation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Ignis.Components;

internal class TimerImplementation : ITimer
{
private readonly Timer _timer;

public TimerImplementation(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
{
_timer = new Timer(callback, state, dueTime, period);
}

public void Dispose()
{
_timer.Dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected virtual void EnterTransition(Action? continueWith = null)

UpdateState(TransitionState.Entering, () =>
{
Timer timer = null!;
ITimer timer = null!;
var (graceDuration, transitionDuration) = ParseDuration(Enter);
timer = TimeProvider.CreateTimer(_ =>
{
Expand All @@ -106,7 +106,7 @@ protected virtual void LeaveTransition(Action? continueWith = null)

UpdateState(TransitionState.Leaving, () =>
{
Timer timer = null!;
ITimer timer = null!;
var (graceDuration, transitionDuration) = ParseDuration(Leave);
timer = TimeProvider.CreateTimer(_ =>
{
Expand Down
5 changes: 3 additions & 2 deletions tests/Ignis.Tests.Common/TestTimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ namespace Ignis.Tests.Common;

internal class TestTimeProvider : TimeProvider
{
public override Timer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
{
return base.CreateTimer(callback, state, TimeSpan.Zero, Timeout.InfiniteTimeSpan);
callback(state);
return new TestTimer();
}
}
14 changes: 14 additions & 0 deletions tests/Ignis.Tests.Common/TestTimer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Ignis.Components;

namespace Ignis.Tests.Common;

internal class TestTimer : ITimer
{
public TestTimer()
{
}

public void Dispose()
{
}
}
19 changes: 6 additions & 13 deletions tests/Ignis.Tests.Components.HeadlessUI/DialogTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,10 @@
var transition = cut.FindComponent<Transition>();
transition.SetParametersAndRender(p => { p.Add(x => x.Show, true); });

await Task.Delay(100);

var transitions = cut.FindAll($"#{transitionId}");
var transitions = cut.WaitForElements($"#{transitionId}");
Assert.Single(transitions);

var dialogs = cut.FindAll($"#{dialogId}");
var dialogs = cut.WaitForElements($"#{dialogId}");
Assert.Single(dialogs);

var dialogDiv = dialogs.Single();
Expand Down Expand Up @@ -183,9 +181,7 @@
var transition = cut.FindComponent<Transition>();
transition.SetParametersAndRender(p => { p.Add(x => x.Show, true); });

await Task.Delay(400);

var transitions = cut.FindAll($"#{transitionId}");
var transitions = cut.WaitForElements($"#{transitionId}");
Assert.Single(transitions);

var dialogs = cut.FindAll($"#{dialogId}");
Expand All @@ -203,14 +199,11 @@

transition.SetParametersAndRender(p => { p.Add(x => x.Show, false); });

await Task.Delay(300);

cut.WaitForState(() => cut.FindAll($"#{dialogId}").Count == 0);
transitions = cut.FindAll($"#{transitionId}");
Assert.Single(transitions);

dialogs = cut.FindAll($"#{dialogId}");
Assert.Empty(dialogs);


transitionDiv = transitions.Single();
outletDiv = cut.Find($"#{outletId}");
var transitionChildDivs = cut.FindAll($"#{transitionChildId}");
Expand Down