From adfed77ffd4f0c99f3c48b4344c06eeff4406dda Mon Sep 17 00:00:00 2001 From: "Steven T. Cramer (aider)" Date: Tue, 23 Jul 2024 10:55:28 +0700 Subject: [PATCH 1/8] Constrained the generic type parameter `T` in the `Add` and `ReRenderSubscribers` methods to ensure it implements the `IState` interface. --- Source/TimeWarp.State/Subscriptions.cs | 310 ++++++++++++------------- 1 file changed, 155 insertions(+), 155 deletions(-) diff --git a/Source/TimeWarp.State/Subscriptions.cs b/Source/TimeWarp.State/Subscriptions.cs index d48d0fdb0..5ed8b2edb 100644 --- a/Source/TimeWarp.State/Subscriptions.cs +++ b/Source/TimeWarp.State/Subscriptions.cs @@ -1,155 +1,155 @@ -namespace TimeWarp.State; - -public class Subscriptions -{ - private readonly ILogger Logger; - - private readonly List TimeWarpStateComponentReferencesList; - - public Subscriptions(ILogger logger) - { - Logger = logger; - Logger.LogDebug(EventIds.Subscriptions_Initializing, "constructing"); - TimeWarpStateComponentReferencesList = new List(); - } - - public Subscriptions Add(ITimeWarpStateComponent timeWarpStateComponent) - { - Type type = typeof(T); - return Add(type, timeWarpStateComponent); - } - - public Subscriptions Add(Type type, ITimeWarpStateComponent timeWarpStateComponent) - { - - // Add only once. - if (!TimeWarpStateComponentReferencesList.Any(subscription => subscription.StateType == type && subscription.ComponentId == timeWarpStateComponent.Id)) - { - Logger.LogDebug - ( - EventIds.Subscriptions_Adding, - "adding subscription for Id:{id} Type.Name:{type_name}", - timeWarpStateComponent.Id, - type.Name - ); - - var subscription = new Subscription( - type, - timeWarpStateComponent.Id, - new WeakReference(timeWarpStateComponent)); - - TimeWarpStateComponentReferencesList.Add(subscription); - } - - return this; - } - - public override bool Equals(object? aObject) => - aObject is Subscriptions subscriptions && - EqualityComparer.Default.Equals(Logger, subscriptions.Logger) && - EqualityComparer>.Default.Equals(TimeWarpStateComponentReferencesList, subscriptions.TimeWarpStateComponentReferencesList); - - public override int GetHashCode() => HashCode.Combine(Logger, TimeWarpStateComponentReferencesList); - - public Subscriptions Remove(ITimeWarpStateComponent timeWarpStateComponent) - { - Logger.LogDebug - ( - EventIds.Subscriptions_RemovingComponentSubscriptions, - "Removing Subscription for {timeWarpStateComponent_Id}", - timeWarpStateComponent.Id - ); - - TimeWarpStateComponentReferencesList.RemoveAll(record => record.ComponentId == timeWarpStateComponent.Id); - - return this; - } - - /// - /// Will iterate over all subscriptions for the given type and call ReRender on each. - /// If the target component no longer exists it will remove its subscription. - /// - /// - public void ReRenderSubscribers() - { - Type type = typeof(T); - - ReRenderSubscribers(type); - } - - /// - /// Will iterate over all subscriptions for the given type and call ReRender on each. - /// If the target component no longer exists it will remove its subscription. - /// - /// - public void ReRenderSubscribers(Type stateType) - { - var subscriptions = TimeWarpStateComponentReferencesList - .Where(record => record.StateType == stateType) - .ToList(); - - foreach (Subscription subscription in subscriptions) - { - if - ( - subscription.TimeWarpStateComponentReference.TryGetTarget(out ITimeWarpStateComponent? target) - && target.ShouldReRender(stateType) - ) - { - LogReRender(subscription); - target.ReRender(); - } - else - { - // If Dispose is called will I ever have items in this list that got Garbage collected? - // Maybe for those that don't inherit from our BaseComponent? - LogRemoveSubscription(subscription); - TimeWarpStateComponentReferencesList.Remove(subscription); - } - } - } - private void LogRemoveSubscription(Subscription subscription) => Logger.LogDebug - ( - EventIds.Subscriptions_RemoveSubscription, - "Removing Subscription for ComponentId:{subscription_ComponentId} StateType.Name:{subscription_StateType_Name}", - subscription.ComponentId, - subscription.StateType.Name - ); - - private void LogReRender(Subscription subscription) => Logger.LogDebug - ( - EventIds.Subscriptions_ReRenderingSubscribers, - "ReRender ComponentId:{subscription_ComponentId} StateType.Name:{subscription_StateType_Name}", - subscription.ComponentId, - subscription.StateType.Name - ); - - private readonly struct Subscription : IEquatable - { - public WeakReference TimeWarpStateComponentReference { get; } - - public string ComponentId { get; } - - public Type StateType { get; } - - public Subscription(Type stateType, string componentId, WeakReference timeWarpStateComponentReference) - { - StateType = stateType; - ComponentId = componentId; - TimeWarpStateComponentReference = timeWarpStateComponentReference; - } - - public static bool operator !=(Subscription leftSubscription, Subscription rightSubscription) => !(leftSubscription == rightSubscription); - - public static bool operator ==(Subscription leftSubscription, Subscription rightSubscription) => leftSubscription.Equals(rightSubscription); - - public bool Equals(Subscription subscription) => - EqualityComparer.Default.Equals(StateType, subscription.StateType) && - ComponentId == subscription.ComponentId && - EqualityComparer>.Default.Equals(TimeWarpStateComponentReference, subscription.TimeWarpStateComponentReference); - - public override bool Equals(object? aObject) => aObject is Subscription subscription && this.Equals(subscription); - - public override int GetHashCode() => ComponentId.GetHashCode(); - } -} +namespace TimeWarp.State; + +public class Subscriptions +{ + private readonly ILogger Logger; + + private readonly List TimeWarpStateComponentReferencesList; + + public Subscriptions(ILogger logger) + { + Logger = logger; + Logger.LogDebug(EventIds.Subscriptions_Initializing, "constructing"); + TimeWarpStateComponentReferencesList = new List(); + } + + public Subscriptions Add(ITimeWarpStateComponent timeWarpStateComponent) where T : IState + { + Type type = typeof(T); + return Add(type, timeWarpStateComponent); + } + + public Subscriptions Add(Type type, ITimeWarpStateComponent timeWarpStateComponent) + { + + // Add only once. + if (!TimeWarpStateComponentReferencesList.Any(subscription => subscription.StateType == type && subscription.ComponentId == timeWarpStateComponent.Id)) + { + Logger.LogDebug + ( + EventIds.Subscriptions_Adding, + "adding subscription for Id:{id} Type.Name:{type_name}", + timeWarpStateComponent.Id, + type.Name + ); + + var subscription = new Subscription( + type, + timeWarpStateComponent.Id, + new WeakReference(timeWarpStateComponent)); + + TimeWarpStateComponentReferencesList.Add(subscription); + } + + return this; + } + + public override bool Equals(object? aObject) => + aObject is Subscriptions subscriptions && + EqualityComparer.Default.Equals(Logger, subscriptions.Logger) && + EqualityComparer>.Default.Equals(TimeWarpStateComponentReferencesList, subscriptions.TimeWarpStateComponentReferencesList); + + public override int GetHashCode() => HashCode.Combine(Logger, TimeWarpStateComponentReferencesList); + + public Subscriptions Remove(ITimeWarpStateComponent timeWarpStateComponent) + { + Logger.LogDebug + ( + EventIds.Subscriptions_RemovingComponentSubscriptions, + "Removing Subscription for {timeWarpStateComponent_Id}", + timeWarpStateComponent.Id + ); + + TimeWarpStateComponentReferencesList.RemoveAll(record => record.ComponentId == timeWarpStateComponent.Id); + + return this; + } + + /// + /// Will iterate over all subscriptions for the given type and call ReRender on each. + /// If the target component no longer exists it will remove its subscription. + /// + /// The type of state, which must implement IState + public void ReRenderSubscribers() where T : IState + { + Type type = typeof(T); + + ReRenderSubscribers(type); + } + + /// + /// Will iterate over all subscriptions for the given type and call ReRender on each. + /// If the target component no longer exists it will remove its subscription. + /// + /// + public void ReRenderSubscribers(Type stateType) + { + var subscriptions = TimeWarpStateComponentReferencesList + .Where(record => record.StateType == stateType) + .ToList(); + + foreach (Subscription subscription in subscriptions) + { + if + ( + subscription.TimeWarpStateComponentReference.TryGetTarget(out ITimeWarpStateComponent? target) + && target.ShouldReRender(stateType) + ) + { + LogReRender(subscription); + target.ReRender(); + } + else + { + // If Dispose is called will I ever have items in this list that got Garbage collected? + // Maybe for those that don't inherit from our BaseComponent? + LogRemoveSubscription(subscription); + TimeWarpStateComponentReferencesList.Remove(subscription); + } + } + } + private void LogRemoveSubscription(Subscription subscription) => Logger.LogDebug + ( + EventIds.Subscriptions_RemoveSubscription, + "Removing Subscription for ComponentId:{subscription_ComponentId} StateType.Name:{subscription_StateType_Name}", + subscription.ComponentId, + subscription.StateType.Name + ); + + private void LogReRender(Subscription subscription) => Logger.LogDebug + ( + EventIds.Subscriptions_ReRenderingSubscribers, + "ReRender ComponentId:{subscription_ComponentId} StateType.Name:{subscription_StateType_Name}", + subscription.ComponentId, + subscription.StateType.Name + ); + + private readonly struct Subscription : IEquatable + { + public WeakReference TimeWarpStateComponentReference { get; } + + public string ComponentId { get; } + + public Type StateType { get; } + + public Subscription(Type stateType, string componentId, WeakReference timeWarpStateComponentReference) + { + StateType = stateType; + ComponentId = componentId; + TimeWarpStateComponentReference = timeWarpStateComponentReference; + } + + public static bool operator !=(Subscription leftSubscription, Subscription rightSubscription) => !(leftSubscription == rightSubscription); + + public static bool operator ==(Subscription leftSubscription, Subscription rightSubscription) => leftSubscription.Equals(rightSubscription); + + public bool Equals(Subscription subscription) => + EqualityComparer.Default.Equals(StateType, subscription.StateType) && + ComponentId == subscription.ComponentId && + EqualityComparer>.Default.Equals(TimeWarpStateComponentReference, subscription.TimeWarpStateComponentReference); + + public override bool Equals(object? aObject) => aObject is Subscription subscription && this.Equals(subscription); + + public override int GetHashCode() => ComponentId.GetHashCode(); + } +} From dfef702ecaf185433b0934702bc67870b0114076 Mon Sep 17 00:00:00 2001 From: "Steven T. Cramer" Date: Tue, 23 Jul 2024 11:39:08 +0700 Subject: [PATCH 2/8] use JSON.stringify instead of ToString and remove no longer useful log --- Source/TimeWarp.State/wwwroot/TypeScript/ReduxDevTools.ts | 7 +++---- Source/TimeWarp.State/wwwroot/js/ReduxDevTools.js | 7 +++---- Source/TimeWarp.State/wwwroot/js/ReduxDevTools.js.map | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Source/TimeWarp.State/wwwroot/TypeScript/ReduxDevTools.ts b/Source/TimeWarp.State/wwwroot/TypeScript/ReduxDevTools.ts index 1b3a93397..94bf955c5 100644 --- a/Source/TimeWarp.State/wwwroot/TypeScript/ReduxDevTools.ts +++ b/Source/TimeWarp.State/wwwroot/TypeScript/ReduxDevTools.ts @@ -19,8 +19,7 @@ export class ReduxDevTools { private IsInitialized: boolean = false; constructor(reduxDevToolsOptions: Config) { - log("ReduxDevTools", "constructor", "info"); - log("ReduxDevTools", reduxDevToolsOptions.toString(), "info"); + log("ReduxDevTools", JSON.stringify(reduxDevToolsOptions, null, 2), "info"); this.TimeWarpState = timeWarpState; this.Config = reduxDevToolsOptions; @@ -61,8 +60,8 @@ export class ReduxDevTools { const dispatchRequests = { 'COMMIT': undefined, 'IMPORT_STATE': undefined, - 'JUMP_TO_ACTION': 'TimeWarp.Features.ReduxDevTools.JumpToStateRequest', - 'JUMP_TO_STATE': 'TimeWarp.Features.ReduxDevTools.JumpToStateRequest', + 'JUMP_TO_ACTION': undefined, // 'TimeWarp.Features.ReduxDevTools.JumpToStateRequest', + 'JUMP_TO_STATE': undefined, // 'TimeWarp.Features.ReduxDevTools.JumpToStateRequest', 'LOCK_CHANGES': undefined, 'PAUSE_RECORDING': undefined, 'PERFORM_ACTION': undefined, diff --git a/Source/TimeWarp.State/wwwroot/js/ReduxDevTools.js b/Source/TimeWarp.State/wwwroot/js/ReduxDevTools.js index 384ca4f79..6b0ca9218 100644 --- a/Source/TimeWarp.State/wwwroot/js/ReduxDevTools.js +++ b/Source/TimeWarp.State/wwwroot/js/ReduxDevTools.js @@ -10,8 +10,7 @@ export class ReduxDevTools { StackTrace; IsInitialized = false; constructor(reduxDevToolsOptions) { - log("ReduxDevTools", "constructor", "info"); - log("ReduxDevTools", reduxDevToolsOptions.toString(), "info"); + log("ReduxDevTools", JSON.stringify(reduxDevToolsOptions, null, 2), "info"); this.TimeWarpState = timeWarpState; this.Config = reduxDevToolsOptions; if (this.Config.trace) { @@ -46,8 +45,8 @@ export class ReduxDevTools { const dispatchRequests = { 'COMMIT': undefined, 'IMPORT_STATE': undefined, - 'JUMP_TO_ACTION': 'TimeWarp.Features.ReduxDevTools.JumpToStateRequest', - 'JUMP_TO_STATE': 'TimeWarp.Features.ReduxDevTools.JumpToStateRequest', + 'JUMP_TO_ACTION': undefined, + 'JUMP_TO_STATE': undefined, 'LOCK_CHANGES': undefined, 'PAUSE_RECORDING': undefined, 'PERFORM_ACTION': undefined, diff --git a/Source/TimeWarp.State/wwwroot/js/ReduxDevTools.js.map b/Source/TimeWarp.State/wwwroot/js/ReduxDevTools.js.map index 47e36091a..b9afeda5d 100644 --- a/Source/TimeWarp.State/wwwroot/js/ReduxDevTools.js.map +++ b/Source/TimeWarp.State/wwwroot/js/ReduxDevTools.js.map @@ -1 +1 @@ -{"version":3,"file":"ReduxDevTools.js","sourceRoot":"","sources":["../TypeScript/ReduxDevTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,a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eAAe,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAC/C,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAE1C,MAAM,WAAW,GAAW,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACzD,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QAClE,CAAC;;YACC,GAAG,CAAC,eAAe,EAAE,oBAAoB,WAAW,8BAA8B,EAAE,SAAS,CAAC,CAAC;IACnG,CAAC,CAAA;IAGD,qBAAqB,CAAC,MAAW,EAAE,KAAc,EAAE,UAAe;QAChE,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;gBACxB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;gBAC1B,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1C,CAAC;YACD,OAAO;QACT,CAAC;QAGD,MAAM,CAAC,iBAAiB,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC;QAClD,OAAQ,MAAM,CAAC,YAAY,CAAqB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACvE,CAAC;IAED,sBAAsB,CAAC,OAAY;QACjC,OAAO,MAAM,CAAC,iBAAiB,CAAC,CAAC,UAAU,IAAI,kCAAkC,CAAC;IACpF,CAAC;CACF"} \ No newline at end of file From afda9834581a00a5228dd6d475631afd0f62cd71 Mon Sep 17 00:00:00 2001 From: "Steven T. Cramer" Date: Tue, 23 Jul 2024 11:59:01 +0700 Subject: [PATCH 3/8] make private prop a field --- .../Features/ReduxDevTools/ReduxDevToolsInterop.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/TimeWarp.State/Features/ReduxDevTools/ReduxDevToolsInterop.cs b/Source/TimeWarp.State/Features/ReduxDevTools/ReduxDevToolsInterop.cs index c23572d1d..0c40b5fe4 100644 --- a/Source/TimeWarp.State/Features/ReduxDevTools/ReduxDevToolsInterop.cs +++ b/Source/TimeWarp.State/Features/ReduxDevTools/ReduxDevToolsInterop.cs @@ -10,9 +10,7 @@ public class ReduxDevToolsInterop private readonly ReduxDevToolsOptions ReduxDevToolsOptions; private bool IsInitialized; - - private bool IsEnabled { get; set; } - + private bool IsEnabled; public ReduxDevToolsInterop ( From 1bfcef94d9a980899527656e599690b84d7079e1 Mon Sep 17 00:00:00 2001 From: "Steven T. Cramer" Date: Tue, 23 Jul 2024 11:59:40 +0700 Subject: [PATCH 4/8] Remove all timeTravel stuff .. I never use time travel and it is a memory hog. --- .../Components/IDevToolsComponent.cs | 10 ----- ...ponent.cs => TimeWarpStateDevComponent.cs} | 18 ++------ .../TimeWarpStateDevToolsInputComponent.cs | 16 ------- .../JumpToState/JumpToStateHandler.cs | 43 ------------------- .../JumpToState/JumpToStateRequest.cs | 16 ------- 5 files changed, 3 insertions(+), 100 deletions(-) delete mode 100644 Source/TimeWarp.State/Features/ReduxDevTools/Components/IDevToolsComponent.cs rename Source/TimeWarp.State/Features/ReduxDevTools/Components/{TimeWarpStateDevToolsComponent.cs => TimeWarpStateDevComponent.cs} (50%) delete mode 100644 Source/TimeWarp.State/Features/ReduxDevTools/Components/TimeWarpStateDevToolsInputComponent.cs delete mode 100644 Source/TimeWarp.State/Features/ReduxDevTools/Requests/JumpToState/JumpToStateHandler.cs delete mode 100644 Source/TimeWarp.State/Features/ReduxDevTools/Requests/JumpToState/JumpToStateRequest.cs diff --git a/Source/TimeWarp.State/Features/ReduxDevTools/Components/IDevToolsComponent.cs b/Source/TimeWarp.State/Features/ReduxDevTools/Components/IDevToolsComponent.cs deleted file mode 100644 index 874818a1a..000000000 --- a/Source/TimeWarp.State/Features/ReduxDevTools/Components/IDevToolsComponent.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace TimeWarp.Features.ReduxDevTools; - -/// -/// Implementation is required to allow DevTools to ReRender components -/// When using Time Travel -/// -public interface IDevToolsComponent -{ - Subscriptions Subscriptions { get; set; } -} diff --git a/Source/TimeWarp.State/Features/ReduxDevTools/Components/TimeWarpStateDevToolsComponent.cs b/Source/TimeWarp.State/Features/ReduxDevTools/Components/TimeWarpStateDevComponent.cs similarity index 50% rename from Source/TimeWarp.State/Features/ReduxDevTools/Components/TimeWarpStateDevToolsComponent.cs rename to Source/TimeWarp.State/Features/ReduxDevTools/Components/TimeWarpStateDevComponent.cs index 65363c0e2..548f9b49a 100644 --- a/Source/TimeWarp.State/Features/ReduxDevTools/Components/TimeWarpStateDevToolsComponent.cs +++ b/Source/TimeWarp.State/Features/ReduxDevTools/Components/TimeWarpStateDevComponent.cs @@ -1,26 +1,14 @@ namespace TimeWarp.Features.ReduxDevTools; /// -/// Base implementation of IDevToolsComponent. Required for TimeTravel in ReduxDevTools +/// Adds a RenderModeDisplay RenderFragment to the TimeWarpStateComponent /// -/// See Peter Morris Issue on Blazor -/// https://github.com/aspnet/Blazor/issues/704 -/// If one implements their own base class with these interfaces -/// They won't be forced to use this one. -/// C# 8 with default implementations of interfaces will be quite tempting to solve this. -/// -public class TimeWarpStateDevToolsComponent : TimeWarpStateComponent, - IDevToolsComponent +public class TimeWarpStateDevComponent : TimeWarpStateComponent { protected readonly RenderFragment RenderModeDisplay; - protected override void OnInitialized() - { - base.OnInitialized(); - Subscriptions.Add(this); - } protected string RenderModeDisplayString => $"CurrentRenderMode: {CurrentRenderMode}\nConfiguredRenderMode: {ConfiguredRenderMode}"; - protected TimeWarpStateDevToolsComponent() + protected TimeWarpStateDevComponent() { RenderModeDisplay = builder => { diff --git a/Source/TimeWarp.State/Features/ReduxDevTools/Components/TimeWarpStateDevToolsInputComponent.cs b/Source/TimeWarp.State/Features/ReduxDevTools/Components/TimeWarpStateDevToolsInputComponent.cs deleted file mode 100644 index fc9e7d5bc..000000000 --- a/Source/TimeWarp.State/Features/ReduxDevTools/Components/TimeWarpStateDevToolsInputComponent.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace TimeWarp.Features.ReduxDevTools; - -/// -/// Base implementation of IDevToolsComponent. Required for TimeTravel in ReduxDevTools -/// -/// See Peter Morris Issue on Blazor -/// https://github.com/aspnet/Blazor/issues/704 -/// If one implements their own base class with these interfaces -/// They won't be forced to use this one. -/// C# 8 with default implementations of interfaces will be quite tempting to solve this. -/// -public abstract class TimeWarpStateDevToolsInputComponent : TimeWarpStateInputComponent, - IDevToolsComponent -{ - protected override void OnInitialized() => Subscriptions.Add(this); -} diff --git a/Source/TimeWarp.State/Features/ReduxDevTools/Requests/JumpToState/JumpToStateHandler.cs b/Source/TimeWarp.State/Features/ReduxDevTools/Requests/JumpToState/JumpToStateHandler.cs deleted file mode 100644 index e598ef039..000000000 --- a/Source/TimeWarp.State/Features/ReduxDevTools/Requests/JumpToState/JumpToStateHandler.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace TimeWarp.Features.ReduxDevTools; - -internal class JumpToStateHandler : IRequestHandler -{ - private readonly ILogger Logger; - private readonly IReduxDevToolsStore Store; - private readonly Subscriptions Subscriptions; - - public JumpToStateHandler - ( - ILogger logger, - IReduxDevToolsStore store, - Subscriptions subscriptions - ) - { - Logger = logger; - Logger.LogDebug(EventIds.JumpToStateHandler_Initializing, "constructor"); - Store = store; - Subscriptions = subscriptions; - } - - public Task Handle(JumpToStateRequest jumpToStateRequest, CancellationToken cancellationToken) - { - Logger.LogDebug - ( - EventIds.JumpToStateHandler_RequestReceived, - "Received Id:{aJumpToStateRequest_Id} State:{aRequest_State}", - jumpToStateRequest.Id, - jumpToStateRequest.State - ); - - Store.LoadStatesFromJson(jumpToStateRequest.State); - Subscriptions.ReRenderSubscribers(); - - Logger.LogDebug - ( - EventIds.JumpToStateHandler_RequestHandled, - "Handled Id:{aJumpToStateRequest_Id}", - jumpToStateRequest.Id - ); - return Task.CompletedTask; - } -} diff --git a/Source/TimeWarp.State/Features/ReduxDevTools/Requests/JumpToState/JumpToStateRequest.cs b/Source/TimeWarp.State/Features/ReduxDevTools/Requests/JumpToState/JumpToStateRequest.cs deleted file mode 100644 index d2f2b31f3..000000000 --- a/Source/TimeWarp.State/Features/ReduxDevTools/Requests/JumpToState/JumpToStateRequest.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace TimeWarp.Features.ReduxDevTools; - -internal class JumpToStateRequest : DispatchRequest, IRequest, IReduxRequest -{ - public JumpToStateRequest(int id, PayloadClass payload, string source, string state, string type) : base(id, payload, source, state, type) {} - - internal class PayloadClass - { - public int ActionId { get; set; } - public string Type { get; set; } - public PayloadClass(string type) - { - Type = type; - } - } -} From fb7cbd2ae55f5a0bce68d8e4f6a3a6e8fa831ac7 Mon Sep 17 00:00:00 2001 From: "Steven T. Cramer" Date: Tue, 23 Jul 2024 12:01:26 +0700 Subject: [PATCH 5/8] clean up logging a little --- .../Features/CloneState/Pipeline/StateTransactionBehavior.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/TimeWarp.State/Features/CloneState/Pipeline/StateTransactionBehavior.cs b/Source/TimeWarp.State/Features/CloneState/Pipeline/StateTransactionBehavior.cs index 72f79054b..6b5b60df3 100644 --- a/Source/TimeWarp.State/Features/CloneState/Pipeline/StateTransactionBehavior.cs +++ b/Source/TimeWarp.State/Features/CloneState/Pipeline/StateTransactionBehavior.cs @@ -60,7 +60,7 @@ CancellationToken cancellationToken ( (ex, path, _, _) => { - Logger.LogDebug("Cloning error: {path} {Message}", path, ex.Message); + Logger.LogWarning("Cloning error: {path} {Message}", path, ex.Message); } ); @@ -75,7 +75,7 @@ CancellationToken cancellationToken Logger.LogDebug ( EventIds.StateTransactionBehavior_Cloning, - "Clone State of type {declaringType} originalState.Guid:{originalState_Guid} newState.Guid:{newState_Guid}", + "Cloned State of type {declaringType} originalState.Guid:{originalState_Guid} newState.Guid:{newState_Guid}", enclosingStateType, originalState.Guid, newState.Guid From e35f3be96ce56169be92ee2176878b4c1112b157 Mon Sep 17 00:00:00 2001 From: "Steven T. Cramer" Date: Tue, 23 Jul 2024 12:02:26 +0700 Subject: [PATCH 6/8] Remove JumpToState stuff used for TimeTravel --- Source/TimeWarp.State/Extensions/ServiceCollectionExtensions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/TimeWarp.State/Extensions/ServiceCollectionExtensions.cs b/Source/TimeWarp.State/Extensions/ServiceCollectionExtensions.cs index b50f795e0..67a2f5fca 100644 --- a/Source/TimeWarp.State/Extensions/ServiceCollectionExtensions.cs +++ b/Source/TimeWarp.State/Extensions/ServiceCollectionExtensions.cs @@ -165,7 +165,6 @@ public static TimeWarpStateOptions UseReduxDevTools serviceCollection.AddScoped(); serviceCollection.AddTransient, CommitHandler>(); - serviceCollection.AddTransient, JumpToStateHandler>(); serviceCollection.AddTransient, StartHandler>(); serviceCollection.AddScoped(serviceProvider => (IReduxDevToolsStore)serviceProvider.GetRequiredService()); From 22a97455291ef36792d09cdf4d675580a7c005ee Mon Sep 17 00:00:00 2001 From: "Steven T. Cramer" Date: Tue, 23 Jul 2024 12:14:56 +0700 Subject: [PATCH 7/8] Bump to 64 --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 15ef804d7..fb0bfa681 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 11.0.0-beta.63+8.0.303 + 11.0.0-beta.64+8.0.303 Steven T. Cramer TimeWarp State $(TimeWarpStateVersion) From 7f807dd9213eec93b2bc8b110ed3985b68928235 Mon Sep 17 00:00:00 2001 From: "Steven T. Cramer" Date: Tue, 23 Jul 2024 16:52:11 +0700 Subject: [PATCH 8/8] TimeWarpStateDevToolsComponent to TimeWarpStateDevComponent --- .../Test.App.Client/Features/Base/Components/BaseComponent.cs | 2 +- .../Features/Base/Components/BaseInputComponent.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Test.App/Test.App.Client/Features/Base/Components/BaseComponent.cs b/Tests/Test.App/Test.App.Client/Features/Base/Components/BaseComponent.cs index d6716bc8c..38c5fd754 100644 --- a/Tests/Test.App/Test.App.Client/Features/Base/Components/BaseComponent.cs +++ b/Tests/Test.App/Test.App.Client/Features/Base/Components/BaseComponent.cs @@ -11,7 +11,7 @@ namespace Test.App.Client.Features.Base.Components; /// But would be required to properly implement the required interfaces. /// one could conditionally inherit from BaseComponent for production build. /// -public abstract class BaseComponent : TimeWarpStateDevToolsComponent +public abstract class BaseComponent : TimeWarpStateDevComponent { protected ApplicationState ApplicationState => GetState(); internal BlueState BlueState => GetState(); diff --git a/Tests/Test.App/Test.App.Client/Features/Base/Components/BaseInputComponent.cs b/Tests/Test.App/Test.App.Client/Features/Base/Components/BaseInputComponent.cs index 0a0a590ec..3a1c11360 100644 --- a/Tests/Test.App/Test.App.Client/Features/Base/Components/BaseInputComponent.cs +++ b/Tests/Test.App/Test.App.Client/Features/Base/Components/BaseInputComponent.cs @@ -10,7 +10,7 @@ namespace Test.App.Client.Features.Base.Components; /// But would be required to properly implement the required interfaces. /// one could conditionally inherit from BaseComponent for production build. /// -public abstract class BaseInputComponent : TimeWarpStateDevToolsInputComponent +public abstract class BaseInputComponent : TimeWarpStateInputComponent { internal ApplicationState ApplicationState => GetState(); internal CounterState CounterState => GetState();