Skip to content

Commit

Permalink
Merge pull request #460 from TimeWarpEngineering/Cramer/2024-07-25/Next
Browse files Browse the repository at this point in the history
Add TimeWarp.State.Rules and Architecture Tests Add Cancelation Tokens to State and TimeWarpStateComponent.
  • Loading branch information
StevenTCramer authored Aug 3, 2024
2 parents a055018 + 77a518e commit 7f7426c
Show file tree
Hide file tree
Showing 98 changed files with 853 additions and 500 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- Set common properties regarding assembly information and nuget packages -->
<PropertyGroup>
<TimeWarpStateVersion>11.0.0-beta.75+8.0.303</TimeWarpStateVersion>
<TimeWarpStateVersion>11.0.0-beta.76+8.0.303</TimeWarpStateVersion>
<Authors>Steven T. Cramer</Authors>
<Product>TimeWarp State</Product>
<PackageVersion>$(TimeWarpStateVersion)</PackageVersion>
Expand Down
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<PackageVersion Include="Microsoft.TypeScript.MSBuild" Version="5.5.3" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageVersion Include="MSTest.TestFramework" Version="3.5.0" />
<PackageVersion Include="NetArchTest.eNhancedEdition" Version="1.4.3" />
<PackageVersion Include="NUnit" Version="4.1.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.2.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
Expand All @@ -59,4 +60,4 @@
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
<PackageVersion Include="timewarp-heroicons" Version="2.0.19" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ namespace Sample.Client.Features.Counter;

using TimeWarp.State;

internal partial class CounterState
public partial class CounterState
{
public static class IncrementCountActionSet
internal static class IncrementCountActionSet
{
public sealed class Action : IAction
internal sealed class Action : IAction
{
public int Amount { get; }
public Action(int amount)
Expand All @@ -16,7 +16,7 @@ public Action(int amount)
}
}

public sealed class Handler : ActionHandler<Action>
internal sealed class Handler : ActionHandler<Action>
{
public Handler(IStore store) : base(store) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Sample.Client.Features.Counter;

using TimeWarp.State;

internal sealed partial class CounterState : State<CounterState>
public sealed partial class CounterState : State<CounterState>
{
public int Count { get; private set; }
public override void Initialize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal partial class CounterState
{
public static class IncrementCountActionSet
{
public sealed class Action : IAction
internal sealed class Action : IAction
{
public int Amount { get; }
public Action(int amount)
Expand All @@ -16,7 +16,7 @@ public Action(int amount)
}
}

public sealed class Handler : ActionHandler<Action>
internal sealed class Handler : ActionHandler<Action>
{
public Handler(IStore store) : base(store) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TimeWarp.Features.ActionTracking;

Check warning on line 1 in Source/TimeWarp.State.Plus/Features/ActionTracking/ActionTrackingState.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Namespace does not correspond to file location

Namespace does not correspond to file location, must be: 'TimeWarp.State.Plus.Features.ActionTracking'

public partial class ActionTrackingState : State<ActionTrackingState>, ICloneable
public sealed partial class ActionTrackingState : State<ActionTrackingState>, ICloneable
{
private List<IAction> ActiveActionList = [];
public ActionTrackingState(ISender sender) : base(sender) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public partial class ActionTrackingState
{
public static class CompleteProcessingActionSet
{
public class Action : IAction
internal sealed class Action : IAction
{
public IAction TheAction { get; }
public Action(IAction theAction)
Expand All @@ -14,7 +14,7 @@ public Action(IAction theAction)
}

[UsedImplicitly]
internal class Handler : ActionHandler<Action>
internal sealed class Handler : ActionHandler<Action>
{
private readonly ILogger<Handler> Logger;
public Handler(IStore store, ILogger<Handler> logger) : base(store)
Expand Down Expand Up @@ -42,6 +42,16 @@ public override Task Handle(Action action, CancellationToken cancellationToken)
}
}

// public async Task CompleteProcessing(IAction theAction, CancellationToken cancellationToken) =>
// await Sender.Send(new ActionTrackingState.CompleteProcessingActionSet.Action(theAction), cancellationToken);
public async Task CompleteProcessing(IAction theAction, CancellationToken? externalCancellationToken = null)
{
using CancellationTokenSource? linkedCts = externalCancellationToken.HasValue
? CancellationTokenSource.CreateLinkedTokenSource(externalCancellationToken.Value, CancellationToken)
: null;

await Sender.Send
(
new ActionTrackingState.CompleteProcessingActionSet.Action(theAction),
linkedCts?.Token ?? CancellationToken
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public partial class ActionTrackingState
{
public static class StartProcessingActionSet
{
internal class Action : IAction
internal sealed class Action : IAction
{
public Action(IAction theAction)
{
Expand All @@ -13,12 +13,9 @@ public Action(IAction theAction)
public IAction TheAction { get; }
}

[UsedImplicitly]
internal class Handler
(
IStore store
): ActionHandler<Action>(store)
internal sealed class Handler : ActionHandler<Action>
{
public Handler(IStore store) : base(store) {}
private ActionTrackingState ActionTrackingState => Store.GetState<ActionTrackingState>();

public override Task Handle(Action action, CancellationToken cancellationToken)
Expand All @@ -29,6 +26,16 @@ public override Task Handle(Action action, CancellationToken cancellationToken)
}
}

// public async Task StartProcessing(IAction theAction, CancellationToken cancellationToken) =>
// await Sender.Send(new ActionTrackingState.StartProcessingActionSet.Action(theAction), cancellationToken);
public async Task StartProcessing(IAction theAction, CancellationToken? externalCancellationToken = null)
{
using CancellationTokenSource? linkedCts = externalCancellationToken.HasValue
? CancellationTokenSource.CreateLinkedTokenSource(externalCancellationToken.Value, CancellationToken)
: null;

await Sender.Send
(
new ActionTrackingState.StartProcessingActionSet.Action(theAction),
linkedCts?.Token ?? CancellationToken
);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TimeWarp.State.Plus.Features.FeatureFlags.Actions;

public class FeatureFlagState : State<FeatureFlagState>
public sealed class FeatureFlagState : State<FeatureFlagState>
{
public FeatureFlagState(ISender sender) : base(sender) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task Handle(StateInitializedNotification stateInitializedNotificati
string fullName = stateInitializedNotification.StateType.FullName ?? throw new InvalidOperationException();
string assemblyQualifiedName = stateInitializedNotification.StateType.AssemblyQualifiedName ?? throw new InvalidOperationException();

string typeName = assemblyQualifiedName.Replace(fullName, $"{fullName}+Load+Action");
string typeName = assemblyQualifiedName.Replace(fullName, $"{fullName}+LoadActionSet+Action");
Logger.LogDebug(EventIds.StateInitializedNotificationHandler_Handling, "StateInitializedNotificationHandler: {StateTypeName}", stateInitializedNotification.StateType.Name);
var actionType = Type.GetType(typeName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public partial class RouteState
{
public static class ChangeRouteActionSet
{
public class Action : IAction
internal sealed class Action : IAction
{
public Action(string newRoute)
{
Expand All @@ -13,7 +13,7 @@ public Action(string newRoute)
public string NewRoute { get; }
}

internal class Handler : ActionHandler<Action>
internal sealed class Handler : ActionHandler<Action>
{
private readonly ILogger Logger;
private readonly NavigationManager NavigationManager;
Expand Down Expand Up @@ -42,6 +42,16 @@ public override Task Handle(Action action, CancellationToken cancellationToken)
}
}
}
public async Task ChangeRoute(string newRoute, CancellationToken cancellationToken = default) =>
await Sender.Send(new RouteState.ChangeRouteActionSet.Action(newRoute), cancellationToken);
public async Task ChangeRoute(string newRoute, CancellationToken? externalCancellationToken = null)
{
using CancellationTokenSource? linkedCts = externalCancellationToken.HasValue
? CancellationTokenSource.CreateLinkedTokenSource(externalCancellationToken.Value, CancellationToken)
: null;

await Sender.Send
(
new RouteState.ChangeRouteActionSet.Action(newRoute),
linkedCts?.Token ?? CancellationToken
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public partial class RouteState
public static class GoBackActionSet
{
[UsedImplicitly]
public class Action : IAction
internal sealed class Action : IAction
{
public int Amount { get; }
public Action(int amount = 1)
Expand All @@ -14,7 +14,7 @@ public Action(int amount = 1)
}
}

internal class Handler : ActionHandler<Action>
internal sealed class Handler : ActionHandler<Action>
{
private readonly NavigationManager NavigationManager;
public Handler
Expand Down Expand Up @@ -45,6 +45,16 @@ public override Task Handle(Action action, CancellationToken cancellationToken)
}
}

public async Task GoBack(int amount = 1, CancellationToken cancellationToken = default) =>
await Sender.Send(new GoBackActionSet.Action(amount), cancellationToken);
public async Task GoBack(int amount = 1, CancellationToken? externalCancellationToken = null)
{
using CancellationTokenSource? linkedCts = externalCancellationToken.HasValue
? CancellationTokenSource.CreateLinkedTokenSource(externalCancellationToken.Value, CancellationToken)
: null;

await Sender.Send
(
new GoBackActionSet.Action(amount),
linkedCts?.Token ?? CancellationToken
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public partial class RouteState
{
public static class PushRouteInfoActionSet
{
public class Action : IAction;
internal sealed class Action : IAction;

internal class Handler : ActionHandler<Action>
internal sealed class Handler : ActionHandler<Action>
{
private readonly NavigationManager NavigationManager;
private readonly IJSRuntime JsRuntime;
Expand Down Expand Up @@ -44,6 +44,16 @@ public override async Task Handle(Action action, CancellationToken cancellationT
}
}
}
public async Task PushRouteInfo(CancellationToken cancellationToken = default) =>
await Sender.Send(new PushRouteInfoActionSet.Action(), cancellationToken);
public async Task PushRouteInfo(CancellationToken? externalCancellationToken = null)
{
using CancellationTokenSource? linkedCts = externalCancellationToken.HasValue
? CancellationTokenSource.CreateLinkedTokenSource(externalCancellationToken.Value, CancellationToken)
: null;

await Sender.Send
(
new PushRouteInfoActionSet.Action(),
linkedCts?.Token ?? CancellationToken
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TimeWarp.Features.Routing;
/// <summary>
/// Maintain the Route in TimeWarp.State
/// </summary>
public partial class RouteState : State<RouteState>
public sealed partial class RouteState : State<RouteState>
{
private readonly Stack<RouteInfo> RouteStack = new();
public RouteState(ISender sender) : base(sender) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ public partial class ThemeState
{
public static class UpdateActionSet
{
[UsedImplicitly]
public class Action : IAction
internal sealed class Action : IAction
{
public Theme NewTheme { get; init; }
}

[UsedImplicitly]
internal class Handler

internal sealed class Handler
(
IStore store
): ActionHandler<Action>(store)
Expand All @@ -32,6 +30,16 @@ CancellationToken cancellationToken
}
}

public async Task Update(Theme newTheme, CancellationToken cancellationToken = default) =>
await Sender.Send(new UpdateActionSet.Action { NewTheme = newTheme }, cancellationToken);
public async Task Update(Theme newTheme, CancellationToken? externalCancellationToken = null)
{
using CancellationTokenSource? linkedCts = externalCancellationToken.HasValue
? CancellationTokenSource.CreateLinkedTokenSource(externalCancellationToken.Value, CancellationToken)
: null;

await Sender.Send
(
new UpdateActionSet.Action { NewTheme = newTheme },
linkedCts?.Token ?? CancellationToken
);
}
}
2 changes: 1 addition & 1 deletion Source/TimeWarp.State.Plus/Features/Theme/ThemeState.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TimeWarp.Features.Theme;

Check warning on line 1 in Source/TimeWarp.State.Plus/Features/Theme/ThemeState.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Namespace does not correspond to file location

Namespace does not correspond to file location, must be: 'TimeWarp.State.Plus.Features.Theme'

public partial class ThemeState : State<ThemeState>
public sealed partial class ThemeState : State<ThemeState>
{
public Theme CurrentTheme { get; private set; }

Expand Down
Loading

0 comments on commit 7f7426c

Please sign in to comment.