Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cascading values+params for state management #34779

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

guardrex
Copy link
Collaborator

@guardrex guardrex commented Feb 21, 2025

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 do INotifyPropertyChanged 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 ...

    the entire State Management page could simply be a list of approaches with links to other pages that explain each feature in detail

    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

📄 File 🔗 Preview link
aspnetcore/blazor/components/cascading-values-and-parameters.md aspnetcore/blazor/components/cascading-values-and-parameters
aspnetcore/blazor/state-management.md aspnetcore/blazor/state-management

@guardrex guardrex self-assigned this Feb 21, 2025
@guardrex guardrex mentioned this pull request Feb 20, 2025
73 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a section on cascading values/parameters for state management with multiple subscribers
1 participant