Skip to content

Commit da6950c

Browse files
committed
Feedback and cleanups
1 parent 7a29927 commit da6950c

7 files changed

+30
-24
lines changed

src/Components/Components/src/Infrastructure/ComponentStatePersistenceManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Components.Infrastructure;
1111
/// </summary>
1212
public class ComponentStatePersistenceManager
1313
{
14-
private readonly List<RegistrationContext> _registeredCallbacks = new();
14+
private readonly List<PersistComponentStateRegistration> _registeredCallbacks = new();
1515
private readonly ILogger<ComponentStatePersistenceManager> _logger;
1616

1717
private bool _stateIsPersisted;
@@ -106,7 +106,7 @@ private void InferRenderModes(Renderer renderer)
106106
if (registration.Callback.Target is IComponent component)
107107
{
108108
var componentRenderMode = renderer.GetComponentRenderMode(component);
109-
_registeredCallbacks[i] = new RegistrationContext(registration.Callback, componentRenderMode);
109+
_registeredCallbacks[i] = new PersistComponentStateRegistration(registration.Callback, componentRenderMode);
110110
continue;
111111
}
112112

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.AspNetCore.Components;
5+
6+
internal readonly struct PersistComponentStateRegistration(
7+
Func<Task> callback,
8+
IComponentRenderMode? renderMode)
9+
{
10+
public Func<Task> Callback { get; } = callback;
11+
12+
public IComponentRenderMode? RenderMode { get; } = renderMode;
13+
}

src/Components/Components/src/PersistentComponentState.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public class PersistentComponentState
1515
private IDictionary<string, byte[]>? _existingState;
1616
private readonly IDictionary<string, byte[]> _currentState;
1717

18-
private readonly List<RegistrationContext> _registeredCallbacks;
18+
private readonly List<PersistComponentStateRegistration> _registeredCallbacks;
1919

2020
internal PersistentComponentState(
2121
IDictionary<string , byte[]> currentState,
22-
List<RegistrationContext> pauseCallbacks)
22+
List<PersistComponentStateRegistration> pauseCallbacks)
2323
{
2424
_currentState = currentState;
2525
_registeredCallbacks = pauseCallbacks;
@@ -56,7 +56,7 @@ public PersistingComponentStateSubscription RegisterOnPersisting(Func<Task> call
5656
{
5757
ArgumentNullException.ThrowIfNull(callback);
5858

59-
var persistenceCallback = new RegistrationContext(callback, renderMode);
59+
var persistenceCallback = new PersistComponentStateRegistration(callback, renderMode);
6060

6161
_registeredCallbacks.Add(persistenceCallback);
6262

src/Components/Components/src/PersistingComponentStateSubscription.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ namespace Microsoft.AspNetCore.Components;
1111
/// </summary>
1212
public readonly struct PersistingComponentStateSubscription : IDisposable
1313
{
14-
private readonly List<RegistrationContext>? _callbacks;
15-
private readonly RegistrationContext? _callback;
14+
private readonly List<PersistComponentStateRegistration>? _callbacks;
15+
private readonly PersistComponentStateRegistration? _callback;
1616

17-
internal PersistingComponentStateSubscription(List<RegistrationContext> callbacks, RegistrationContext callback)
17+
internal PersistingComponentStateSubscription(List<PersistComponentStateRegistration> callbacks, PersistComponentStateRegistration callback)
1818
{
1919
_callbacks = callbacks;
2020
_callback = callback;

src/Components/Components/src/RegistrationContext.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Components/Components/test/Lifetime/ComponentApplicationLifetimeTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ IEnumerator IEnumerable.GetEnumerator()
310310
}
311311
}
312312

313-
314313
private class TestRenderMode : IComponentRenderMode
315314
{
316315

src/Components/Components/test/Lifetime/ComponentApplicationStateTest.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ComponentApplicationStateTest
1111
public void InitializeExistingState_SetupsState()
1212
{
1313
// Arrange
14-
var applicationState = new PersistentComponentState(new Dictionary<string, byte[]>(), new List<RegistrationContext>());
14+
var applicationState = new PersistentComponentState(new Dictionary<string, byte[]>(), new List<PersistComponentStateRegistration>());
1515
var existingState = new Dictionary<string, byte[]>
1616
{
1717
["MyState"] = JsonSerializer.SerializeToUtf8Bytes(new byte[] { 1, 2, 3, 4 })
@@ -29,7 +29,7 @@ public void InitializeExistingState_SetupsState()
2929
public void InitializeExistingState_ThrowsIfAlreadyInitialized()
3030
{
3131
// Arrange
32-
var applicationState = new PersistentComponentState(new Dictionary<string, byte[]>(), new List<RegistrationContext>());
32+
var applicationState = new PersistentComponentState(new Dictionary<string, byte[]>(), new List<PersistComponentStateRegistration>());
3333
var existingState = new Dictionary<string, byte[]>
3434
{
3535
["MyState"] = new byte[] { 1, 2, 3, 4 }
@@ -45,7 +45,7 @@ public void InitializeExistingState_ThrowsIfAlreadyInitialized()
4545
public void TryRetrieveState_ReturnsStateWhenItExists()
4646
{
4747
// Arrange
48-
var applicationState = new PersistentComponentState(new Dictionary<string, byte[]>(), new List<RegistrationContext>());
48+
var applicationState = new PersistentComponentState(new Dictionary<string, byte[]>(), new List<PersistComponentStateRegistration>());
4949
var existingState = new Dictionary<string, byte[]>
5050
{
5151
["MyState"] = JsonSerializer.SerializeToUtf8Bytes(new byte[] { 1, 2, 3, 4 })
@@ -65,7 +65,7 @@ public void PersistState_SavesDataToTheStoreAsync()
6565
{
6666
// Arrange
6767
var currentState = new Dictionary<string, byte[]>();
68-
var applicationState = new PersistentComponentState(currentState, new List<RegistrationContext>())
68+
var applicationState = new PersistentComponentState(currentState, new List<PersistComponentStateRegistration>())
6969
{
7070
PersistingState = true
7171
};
@@ -84,7 +84,7 @@ public void PersistState_ThrowsForDuplicateKeys()
8484
{
8585
// Arrange
8686
var currentState = new Dictionary<string, byte[]>();
87-
var applicationState = new PersistentComponentState(currentState, new List<RegistrationContext>())
87+
var applicationState = new PersistentComponentState(currentState, new List<PersistComponentStateRegistration>())
8888
{
8989
PersistingState = true
9090
};
@@ -101,7 +101,7 @@ public void PersistAsJson_SerializesTheDataToJsonAsync()
101101
{
102102
// Arrange
103103
var currentState = new Dictionary<string, byte[]>();
104-
var applicationState = new PersistentComponentState(currentState, new List<RegistrationContext>())
104+
var applicationState = new PersistentComponentState(currentState, new List<PersistComponentStateRegistration>())
105105
{
106106
PersistingState = true
107107
};
@@ -120,7 +120,7 @@ public void PersistAsJson_NullValueAsync()
120120
{
121121
// Arrange
122122
var currentState = new Dictionary<string, byte[]>();
123-
var applicationState = new PersistentComponentState(currentState, new List<RegistrationContext>())
123+
var applicationState = new PersistentComponentState(currentState, new List<PersistComponentStateRegistration>())
124124
{
125125
PersistingState = true
126126
};
@@ -140,7 +140,7 @@ public void TryRetrieveFromJson_DeserializesTheDataFromJson()
140140
var myState = new byte[] { 1, 2, 3, 4 };
141141
var serialized = JsonSerializer.SerializeToUtf8Bytes(myState);
142142
var existingState = new Dictionary<string, byte[]>() { ["MyState"] = serialized };
143-
var applicationState = new PersistentComponentState(new Dictionary<string, byte[]>(), new List<RegistrationContext>());
143+
var applicationState = new PersistentComponentState(new Dictionary<string, byte[]>(), new List<PersistComponentStateRegistration>());
144144

145145
applicationState.InitializeExistingState(existingState);
146146

@@ -158,7 +158,7 @@ public void TryRetrieveFromJson_NullValue()
158158
// Arrange
159159
var serialized = JsonSerializer.SerializeToUtf8Bytes<byte[]>(null);
160160
var existingState = new Dictionary<string, byte[]>() { ["MyState"] = serialized };
161-
var applicationState = new PersistentComponentState(new Dictionary<string, byte[]>(), new List<RegistrationContext>());
161+
var applicationState = new PersistentComponentState(new Dictionary<string, byte[]>(), new List<PersistComponentStateRegistration>());
162162

163163
applicationState.InitializeExistingState(existingState);
164164

0 commit comments

Comments
 (0)