Skip to content

Commit 968e3b2

Browse files
committed
Updates
1 parent 87a954d commit 968e3b2

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,35 +139,35 @@ public class NotifyingDalek : INotifyPropertyChanged
139139
}
140140
```
141141

142-
The following `CascadingValueServiceCollectionExtensions` creates a <xref:Microsoft.AspNetCore.Components.CascadingValueSource%601> from a type that implements <xref:System.ComponentModel.INotifyPropertyChanged>.
142+
The following `CascadingStateServiceCollectionExtensions` creates a <xref:Microsoft.AspNetCore.Components.CascadingValueSource%601> from a type that implements <xref:System.ComponentModel.INotifyPropertyChanged>.
143143

144-
`CascadingValueServiceCollectionExtensions.cs`:
144+
`CascadingStateServiceCollectionExtensions.cs`:
145145

146146
```csharp
147147
using System.ComponentModel;
148148
using Microsoft.AspNetCore.Components;
149149

150150
namespace Microsoft.Extensions.DependencyInjection;
151151

152-
public static class CascadingApplicationStateServiceCollectionExtensions
152+
public static class CascadingStateServiceCollectionExtensions
153153
{
154-
public static IServiceCollection AddCascadingApplicationState<T>(
154+
public static IServiceCollection AddCascadingStateNotifier<T>(
155155
this IServiceCollection serviceCollection, T value, bool isFixed = false)
156156
where T : INotifyPropertyChanged
157157
{
158158
return serviceCollection.AddCascadingValue<T>(services =>
159159
{
160-
return new ApplicationStateCascadingValueSource<T>(value, isFixed);
160+
return new CascadingStateValueSource<T>(value, isFixed);
161161
});
162162
}
163163

164-
private sealed class ApplicationStateCascadingValueSource<T>
164+
private sealed class CascadingStateValueSource<T>
165165
: CascadingValueSource<T>, IDisposable where T : INotifyPropertyChanged
166166
{
167167
private readonly T value;
168168
private readonly CascadingValueSource<T> source;
169169

170-
public ApplicationStateCascadingValueSource(T value, bool isFixed = false)
170+
public CascadingStateValueSource(T value, bool isFixed = false)
171171
: base(value, isFixed = false)
172172
{
173173
this.value = value;
@@ -193,15 +193,15 @@ The type's <xref:System.ComponentModel.PropertyChangedEventHandler> (`HandleProp
193193
In the `Program` file&dagger;, `NotifyingDalek` is passed to create a <xref:Microsoft.AspNetCore.Components.CascadingValueSource%601> with an initial `Unit` value of 888 units:
194194

195195
```csharp
196-
builder.Services.AddCascadingApplicationState<NotifyingDalek>(
196+
builder.Services.AddCascadingStateNotifier<NotifyingDalek>(
197197
new NotifyingDalek() { Units = 888 });
198198
```
199199

200200
> [!NOTE]
201201
> &dagger;For Blazor Web App solutions consisting of server and client (`.Client`) projects:
202202
>
203-
> * The preceding `NotifyingDalek.cs` and `CascadingValueServiceCollectionExtensions.cs` files are placed in the `.Client` project.
204-
> * The preceding code is placed into the `Program` file of *both* projects.
203+
> * The preceding `NotifyingDalek.cs` and `CascadingStateServiceCollectionExtensions.cs` files are placed in the `.Client` project.
204+
> * The preceding code is placed into each project's `Program` file.
205205
206206
The following component is used to demonstrate how changing the value of `NotifyingDalek.Units` notifies subscribers.
207207

@@ -276,6 +276,8 @@ To demonstrate multiple subscriber notifications, the following `DaleksMain` com
276276

277277
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.
278278

279+
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.
280+
279281
:::moniker-end
280282

281283
## `CascadingValue` component

0 commit comments

Comments
 (0)