Skip to content

Commit 3540515

Browse files
committed
Fixing the build
1 parent 6caf183 commit 3540515

15 files changed

+48
-111
lines changed

src/Components/Components/src/PersistentComponentState.cs

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public class PersistentComponentState
1717

1818
private readonly List<PersistComponentStateRegistration> _registeredCallbacks;
1919
private readonly List<RestoreComponentStateRegistration> _registeredRestoringCallbacks;
20-
private IPersistentComponentStateScenario? _currentScenario;
21-
private RestoreContext? _currentContext = null;
20+
private RestoreContext? _currentContext;
2221

2322
internal PersistentComponentState(
2423
IDictionary<string, byte[]> currentState,
@@ -33,15 +32,14 @@ internal PersistentComponentState(
3332
internal bool PersistingState { get; set; }
3433

3534
// TODO: Replace IPersistentComponentStateScenario with RestoreContext
36-
internal void InitializeExistingState(IDictionary<string, byte[]> existingState, IPersistentComponentStateScenario? scenario = null)
35+
internal void InitializeExistingState(IDictionary<string, byte[]> existingState, RestoreContext context)
3736
{
3837
if (_existingState != null)
3938
{
4039
throw new InvalidOperationException("PersistentComponentState already initialized.");
4140
}
4241
_existingState = existingState ?? throw new ArgumentNullException(nameof(existingState));
43-
_currentScenario = scenario;
44-
_currentContext = null!;
42+
_currentContext = context;
4543
}
4644

4745
/// <summary>
@@ -76,6 +74,12 @@ public PersistingComponentStateSubscription RegisterOnPersisting(Func<Task> call
7674
return new PersistingComponentStateSubscription(_registeredCallbacks, persistenceCallback);
7775
}
7876

77+
/// <summary>
78+
/// Register a callback to restore the state when the application state is being restored.
79+
/// </summary>
80+
/// <param name="callback"> The callback to invoke when the application state is being restored.</param>
81+
/// <param name="options">Options that control the restoration behavior.</param>
82+
/// <returns>A subscription that can be used to unregister the callback when disposed.</returns>
7983
public RestoringComponentStateSubscription RegisterOnRestoring(Action callback, RestoreOptions options)
8084
{
8185
if (_currentContext!.ShouldRestore(options))
@@ -86,34 +90,12 @@ public RestoringComponentStateSubscription RegisterOnRestoring(Action callback,
8690
if (options.AllowUpdates)
8791
{
8892
// TODO: Remove the filter from registration
89-
var registration = new RestoreComponentStateRegistration(null, callback);
93+
var registration = new RestoreComponentStateRegistration(callback);
9094
_registeredRestoringCallbacks.Add(registration);
9195
return new RestoringComponentStateSubscription(_registeredRestoringCallbacks, registration);
9296
}
93-
}
94-
95-
/// <summary>
96-
/// Register a callback to restore the component state during specific scenarios.
97-
/// The callback will only be invoked if the filter supports the current restoration scenario.
98-
/// </summary>
99-
/// <param name="filter">The filter that determines when this callback should be invoked.</param>
100-
/// <param name="callback">The callback to invoke during state restoration.</param>
101-
/// <returns>A subscription that can be used to unregister the callback when disposed.</returns>
102-
// TODO: Remove this method.
103-
public RestoringComponentStateSubscription RegisterOnRestoring(IPersistentStateFilter? filter, Action callback)
104-
{
105-
ArgumentNullException.ThrowIfNull(callback);
106-
107-
if (_currentScenario == null || filter == null ||
108-
(filter != null && (!filter.SupportsScenario(_currentScenario) ||
109-
filter.ShouldRestore(_currentScenario))))
110-
{
111-
callback();
112-
}
11397

114-
var registration = new RestoreComponentStateRegistration(filter, callback);
115-
_registeredRestoringCallbacks.Add(registration);
116-
return new RestoringComponentStateSubscription(_registeredRestoringCallbacks, registration);
98+
return default;
11799
}
118100

119101
/// <summary>
@@ -263,13 +245,7 @@ private bool TryTake(string key, out byte[]? value)
263245
}
264246
}
265247

266-
/// <summary>
267-
/// Updates the existing state with the given <paramref name="state"/> dictionary.
268-
/// </summary>
269-
/// <param name="state">The new state to apply.</param>
270-
/// <param name="scenario">The scenario for which the state is being updated.</param>
271-
// TODO: Replace scenario with context.
272-
internal void UpdateExistingState(IDictionary<string, byte[]> state, IPersistentComponentStateScenario? scenario)
248+
internal void UpdateExistingState(IDictionary<string, byte[]> state, RestoreContext context)
273249
{
274250
ArgumentNullException.ThrowIfNull(state);
275251

@@ -279,6 +255,6 @@ internal void UpdateExistingState(IDictionary<string, byte[]> state, IPersistent
279255
}
280256

281257
_existingState = state;
282-
_currentScenario = scenario;
258+
_currentContext = context;
283259
}
284260
}

src/Components/Components/src/PersistentState/ComponentStatePersistenceManager.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,26 @@ public ComponentStatePersistenceManager(ILogger<ComponentStatePersistenceManager
5858
/// <returns>A <see cref="Task"/> that will complete when the state has been restored.</returns>
5959
public async Task RestoreStateAsync(IPersistentComponentStateStore store)
6060
{
61-
await RestoreStateAsync(store, scenario: null);
61+
await RestoreStateAsync(store, RestoreContext.InitialValue);
6262
}
6363

6464
/// <summary>
65-
/// Restores the component application state from the given <see cref="IPersistentComponentStateStore"/> using the specified scenario.
65+
/// Restores the application state.
6666
/// </summary>
67-
/// <param name="store">The <see cref="IPersistentComponentStateStore"/> to restore the application state from.</param>
68-
/// <param name="scenario">The restoration scenario that determines which filters should be applied.</param>
67+
/// <param name="store"> The <see cref="IPersistentComponentStateStore"/> to restore the application state from.</param>
68+
/// <param name="context">The <see cref="RestoreContext"/> that provides additional context for the restoration.</param>
6969
/// <returns>A <see cref="Task"/> that will complete when the state has been restored.</returns>
70-
public async Task RestoreStateAsync(IPersistentComponentStateStore store, IPersistentComponentStateScenario? scenario)
70+
public async Task RestoreStateAsync(IPersistentComponentStateStore store, RestoreContext context)
7171
{
7272
var data = await store.GetPersistedStateAsync();
7373

7474
if (_stateIsInitialized)
7575
{
76-
State.UpdateExistingState(data, scenario);
76+
State.UpdateExistingState(data, context);
7777
}
7878
else
7979
{
80-
State.InitializeExistingState(data, scenario);
80+
State.InitializeExistingState(data, context);
8181
_servicesRegistry?.Restore(State);
8282
_stateIsInitialized = true;
8383
}
Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#nullable enable
22
*REMOVED*Microsoft.AspNetCore.Components.ResourceAsset.ResourceAsset(string! url, System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Components.ResourceAssetProperty!>? properties) -> void
3+
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.RestoreStateAsync(Microsoft.AspNetCore.Components.IPersistentComponentStateStore! store, Microsoft.AspNetCore.Components.RestoreContext! context) -> System.Threading.Tasks.Task!
34
Microsoft.AspNetCore.Components.PersistentComponentState.RegisterOnRestoring(System.Action! callback, Microsoft.AspNetCore.Components.RestoreOptions options) -> Microsoft.AspNetCore.Components.RestoringComponentStateSubscription
45
Microsoft.AspNetCore.Components.PersistentStateAttribute.AllowUpdates.get -> bool
56
Microsoft.AspNetCore.Components.PersistentStateAttribute.AllowUpdates.set -> void
@@ -18,6 +19,9 @@ Microsoft.AspNetCore.Components.RestoreOptions.AllowUpdates.init -> void
1819
Microsoft.AspNetCore.Components.RestoreOptions.RestoreBehavior.get -> Microsoft.AspNetCore.Components.RestoreBehavior
1920
Microsoft.AspNetCore.Components.RestoreOptions.RestoreBehavior.init -> void
2021
Microsoft.AspNetCore.Components.RestoreOptions.RestoreOptions() -> void
22+
Microsoft.AspNetCore.Components.RestoringComponentStateSubscription
23+
Microsoft.AspNetCore.Components.RestoringComponentStateSubscription.Dispose() -> void
24+
Microsoft.AspNetCore.Components.RestoringComponentStateSubscription.RestoringComponentStateSubscription() -> void
2125
Microsoft.AspNetCore.Components.Routing.Router.NotFoundPage.get -> System.Type!
2226
Microsoft.AspNetCore.Components.Routing.Router.NotFoundPage.set -> void
2327
Microsoft.AspNetCore.Components.Infrastructure.ComponentsMetricsServiceCollectionExtensions
@@ -37,39 +41,12 @@ Microsoft.AspNetCore.Components.PersistentComponentStateSerializer<T>
3741
Microsoft.AspNetCore.Components.PersistentComponentStateSerializer<T>.PersistentComponentStateSerializer() -> void
3842
abstract Microsoft.AspNetCore.Components.PersistentComponentStateSerializer<T>.Persist(T value, System.Buffers.IBufferWriter<byte>! writer) -> void
3943
abstract Microsoft.AspNetCore.Components.PersistentComponentStateSerializer<T>.Restore(System.Buffers.ReadOnlySequence<byte> data) -> T
40-
Microsoft.AspNetCore.Components.UpdateStateOnEnhancedNavigation
41-
Microsoft.AspNetCore.Components.UpdateStateOnEnhancedNavigation.UpdateStateOnEnhancedNavigation(bool enable = false) -> void
4244
static Microsoft.AspNetCore.Components.Infrastructure.RegisterPersistentComponentStateServiceCollectionExtensions.AddPersistentServiceRegistration<TService>(Microsoft.Extensions.DependencyInjection.IServiceCollection! services, Microsoft.AspNetCore.Components.IComponentRenderMode! componentRenderMode) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
4345
static Microsoft.AspNetCore.Components.Infrastructure.ComponentsMetricsServiceCollectionExtensions.AddComponentsMetrics(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
4446
static Microsoft.AspNetCore.Components.Infrastructure.ComponentsMetricsServiceCollectionExtensions.AddComponentsTracing(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
4547
static Microsoft.AspNetCore.Components.RestoreContext.InitialValue.get -> Microsoft.AspNetCore.Components.RestoreContext!
4648
static Microsoft.AspNetCore.Components.RestoreContext.LastSnapshot.get -> Microsoft.AspNetCore.Components.RestoreContext!
4749
static Microsoft.AspNetCore.Components.RestoreContext.ValueUpdate.get -> Microsoft.AspNetCore.Components.RestoreContext!
48-
static Microsoft.AspNetCore.Components.WebPersistenceFilter.EnhancedNavigation.get -> Microsoft.AspNetCore.Components.WebPersistenceFilter!
49-
static Microsoft.AspNetCore.Components.WebPersistenceScenario.EnhancedNavigation.get -> Microsoft.AspNetCore.Components.WebPersistenceScenario!
5050
virtual Microsoft.AspNetCore.Components.OwningComponentBase.DisposeAsyncCore() -> System.Threading.Tasks.ValueTask
5151
static Microsoft.AspNetCore.Components.Infrastructure.PersistentStateProviderServiceCollectionExtensions.AddSupplyValueFromPersistentComponentStateProvider(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
5252
virtual Microsoft.AspNetCore.Components.Rendering.ComponentState.GetComponentKey() -> object?
53-
Microsoft.AspNetCore.Components.IPersistentComponentStateScenario
54-
Microsoft.AspNetCore.Components.IPersistentComponentStateScenario.IsRecurring.get -> bool
55-
Microsoft.AspNetCore.Components.IPersistentStateFilter
56-
Microsoft.AspNetCore.Components.IPersistentStateFilter.ShouldRestore(Microsoft.AspNetCore.Components.IPersistentComponentStateScenario! scenario) -> bool
57-
Microsoft.AspNetCore.Components.IPersistentStateFilter.SupportsScenario(Microsoft.AspNetCore.Components.IPersistentComponentStateScenario! scenario) -> bool
58-
Microsoft.AspNetCore.Components.PersistentComponentState.RegisterOnRestoring(Microsoft.AspNetCore.Components.IPersistentStateFilter? filter, System.Action! callback) -> Microsoft.AspNetCore.Components.RestoringComponentStateSubscription
59-
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.RestoreStateAsync(Microsoft.AspNetCore.Components.IPersistentComponentStateStore! store, Microsoft.AspNetCore.Components.IPersistentComponentStateScenario? scenario) -> System.Threading.Tasks.Task!
60-
Microsoft.AspNetCore.Components.RestoreStateOnPrerenderingAttribute
61-
Microsoft.AspNetCore.Components.RestoreStateOnPrerenderingAttribute.RestoreStateOnPrerenderingAttribute(bool enable = true) -> void
62-
Microsoft.AspNetCore.Components.RestoreStateOnReconnectionAttribute
63-
Microsoft.AspNetCore.Components.RestoreStateOnReconnectionAttribute.RestoreStateOnReconnectionAttribute(bool enabled = true) -> void
64-
Microsoft.AspNetCore.Components.RestoringComponentStateSubscription
65-
Microsoft.AspNetCore.Components.RestoringComponentStateSubscription.Dispose() -> void
66-
Microsoft.AspNetCore.Components.RestoringComponentStateSubscription.RestoringComponentStateSubscription() -> void
67-
Microsoft.AspNetCore.Components.WebPersistenceFilter
68-
static Microsoft.AspNetCore.Components.WebPersistenceFilter.Prerendering.get -> Microsoft.AspNetCore.Components.WebPersistenceFilter!
69-
static Microsoft.AspNetCore.Components.WebPersistenceFilter.Reconnection.get -> Microsoft.AspNetCore.Components.WebPersistenceFilter!
70-
Microsoft.AspNetCore.Components.WebPersistenceFilter.ShouldRestore(Microsoft.AspNetCore.Components.IPersistentComponentStateScenario! scenario) -> bool
71-
Microsoft.AspNetCore.Components.WebPersistenceFilter.SupportsScenario(Microsoft.AspNetCore.Components.IPersistentComponentStateScenario! scenario) -> bool
72-
Microsoft.AspNetCore.Components.WebPersistenceScenario
73-
Microsoft.AspNetCore.Components.WebPersistenceScenario.IsRecurring.get -> bool
74-
static Microsoft.AspNetCore.Components.WebPersistenceScenario.Prerendering.get -> Microsoft.AspNetCore.Components.WebPersistenceScenario!
75-
static Microsoft.AspNetCore.Components.WebPersistenceScenario.Reconnection.get -> Microsoft.AspNetCore.Components.WebPersistenceScenario!

src/Components/Components/src/RestoreComponentStateRegistration.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33

44
namespace Microsoft.AspNetCore.Components;
55

6-
internal readonly struct RestoreComponentStateRegistration(
7-
IPersistentStateFilter? filter,
8-
Action callback)
6+
internal readonly struct RestoreComponentStateRegistration(Action callback)
97
{
10-
public IPersistentStateFilter? Filter { get; } = filter;
11-
128
public Action Callback { get; } = callback;
139
}

0 commit comments

Comments
 (0)