Skip to content

Commit fdc6a78

Browse files
authored
Apply suggestions from code review
1 parent 99c0e3d commit fdc6a78

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

aspnetcore/blazor/components/cascading-values-and-parameters.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ The following `Daleks` component displays the cascaded values.
7575

7676
:::moniker range=">= aspnetcore-8.0"
7777

78-
In the following example, `Dalek` is registered as a cascading value using [`CascadingValueSource<T>`](xref:Microsoft.AspNetCore.Components.CascadingValueSource%601), where `<T>` is the type. The `isFixed` flag indicates whether the value is fixed. If false, all recipients are subscribed for update notifications. Subscriptions create overhead and reduce performance, so set `isFixed` to `true` if the value doesn't change.
78+
In the following example, `Dalek` is registered as a cascading value using [`CascadingValueSource<T>`](xref:Microsoft.AspNetCore.Components.CascadingValueSource%601), where `<T>` is the type. The `isFixed` flag indicates whether the value is fixed. If `false`, all recipients are subscribed for update notifications. Subscriptions create overhead and reduce performance, so set `isFixed` to `true` if the value doesn't change.
7979

8080
```csharp
8181
builder.Services.AddCascadingValue(sp =>
@@ -131,7 +131,7 @@ public class NotifyingDalek : INotifyPropertyChanged
131131
[CallerMemberName] string? propertyName = default)
132132
=> PropertyChanged?.Invoke(this, new(propertyName));
133133

134-
public async Task SetUnitsToOneThousand()
134+
public async Task SetUnitsToOneThousandAsync()
135135
{
136136
// Simulate a three second delay in processing
137137
await Task.Delay(3000);
@@ -154,10 +154,10 @@ namespace Microsoft.Extensions.DependencyInjection;
154154
public static class CascadingStateServiceCollectionExtensions
155155
{
156156
public static IServiceCollection AddCascadingStateNotifier<T>(
157-
this IServiceCollection serviceCollection, T value, bool isFixed = false)
157+
this IServiceCollection services, T state, bool isFixed = false)
158158
where T : INotifyPropertyChanged
159159
{
160-
return serviceCollection.AddCascadingValue<T>(services =>
160+
return serviceCollection.AddCascadingValue<T>(sp =>
161161
{
162162
return new CascadingStateValueSource<T>(value, isFixed);
163163
});
@@ -166,15 +166,15 @@ public static class CascadingStateServiceCollectionExtensions
166166
private sealed class CascadingStateValueSource<T>
167167
: CascadingValueSource<T>, IDisposable where T : INotifyPropertyChanged
168168
{
169-
private readonly T value;
169+
private readonly T state;
170170
private readonly CascadingValueSource<T> source;
171171

172-
public CascadingStateValueSource(T value, bool isFixed = false)
173-
: base(value, isFixed = false)
172+
public CascadingStateValueSource(T state, bool isFixed = false)
173+
: base(state, isFixed = false)
174174
{
175-
this.value = value;
176-
source = new CascadingValueSource<T>(value, isFixed);
177-
this.value.PropertyChanged += HandlePropertyChanged;
175+
this.state= state;
176+
source = new CascadingValueSource<T>(state, isFixed);
177+
this.state.PropertyChanged += HandlePropertyChanged;
178178
}
179179

180180
private void HandlePropertyChanged(object? sender, PropertyChangedEventArgs e)
@@ -184,7 +184,7 @@ public static class CascadingStateServiceCollectionExtensions
184184

185185
public void Dispose()
186186
{
187-
value.PropertyChanged -= HandlePropertyChanged;
187+
state.PropertyChanged -= HandlePropertyChanged;
188188
}
189189
}
190190
}
@@ -252,7 +252,7 @@ The following component is used to demonstrate how changing the value of `Notify
252252
{
253253
if (Dalek is not null)
254254
{
255-
await Dalek.SetUnitsToOneThousand();
255+
await Dalek.SetUnitsToOneThousandAsync();
256256
}
257257
}
258258
}
@@ -278,7 +278,7 @@ To demonstrate multiple subscriber notifications, the following `DaleksMain` com
278278

279279
Because the <xref:Microsoft.AspNetCore.Components.CascadingValueSource%601>'s type in this example (`NotifyingDalek`) is a class type, you can meet virtually any state management feature specification requirement. However, subscriptions create overhead and reduce performance, so benchmark the performance of this approach in your app and compare it to other [state management approaches](xref:blazor/state-management) before adopting it in a production app with constrained processing and memory resources.
280280

281-
Any change in state (any property value change of the class) causes all subscribed components to rerender, regardless of which part of the state that they use. **Avoid creating a single large class representing the entire global application state.** Instead, create granular classes and cascade them separately with specific subscriptions to cascading parameters, ensuring that only components subscribed to a specific portion of the application state are affected by changes.
281+
Any change in state (any property value change of the class) causes all subscribed components to rerender, regardless of which part of the state they use. **Avoid creating a single large class representing the entire global application state.** Instead, create granular classes and cascade them separately with specific subscriptions to cascading parameters, ensuring that only components subscribed to a specific portion of the application state are affected by changes.
282282

283283
:::moniker-end
284284

0 commit comments

Comments
 (0)