@@ -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}
0 commit comments