Cascading values+params for state management #34779
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #34236
Thanks @hakenr! 🎷 ... This is probably a bit rough in spots. If you have time to look, I'll address your feedback before pinging a PU engineer. If you're busy, no worries ... I'll get one of them on here early next week to put an 👁️ on this.
Notes
Add a
CascadingValueSource<T>
with notifications (INotifyPropertyChanged
/NotifyChangedAsync
) approach to the Cascading values and parameters article. The basis for the example is code provided by @kzu on CascadingValueSource<T> should automatically invoke NotifyChangedAsync for INotifyPropertyChanged values aspnetcore#53257 (Thanks @kzu! 🎸) . Sanderson said it's supported at CascadingValueSource<T> should automatically invoke NotifyChangedAsync for INotifyPropertyChanged values aspnetcore#53257 (comment), but he also commented elsewhere that "In practice it's extremely rare for people to want to doINotifyPropertyChanged
with Blazor." However, that might be because it isn't documented (until now here 😄).I favor placing this coverage because it's easy to understand/implement and flexible/powerful with a class type. I demo both setting a property value directly and having a method in the class that updates a property. An app can process state quite easily using this approach. I make sure to call out that there's a perf hit and to be careful with this approach.
Add a short section to the State Management article mentioning cascading values and parameters generally. For >=8.0, cross-link the root-level cascading value/
CascadingValueSource<T>
/INotifyPropertyChanged
/NotifyChangedAsync
approach.WRT ...
My initial concern is simply that explaining the features and explaining state management using the features in one spot is problematic because state management is a more advanced use case for the two or three scenarios here where this idea applies. For root-level cascading values with notifications, this approach seems to work well because the use case is a state management approach. I've made a tracking item entry for this idea to look at it again later.
Internal previews