Skip to content

ParameterState: Add ParameterView to ParameterChangedEventArgs#12269

Merged
ScarletKuro merged 4 commits intoMudBlazor:devfrom
ScarletKuro:parameterstate_handler_paramview
Dec 14, 2025
Merged

ParameterState: Add ParameterView to ParameterChangedEventArgs#12269
ScarletKuro merged 4 commits intoMudBlazor:devfrom
ScarletKuro:parameterstate_handler_paramview

Conversation

@ScarletKuro
Copy link
Member

@ScarletKuro ScarletKuro commented Dec 13, 2025

There is a need to inspect the ParameterView inside the change handler.

In some components, MudBlazor components are a good example, there is a dependency between parameters such as Text and Value. Typically, Value represents a value of type T, while Text is its textual(string) representation.

This creates bidirectional synchronization requirements:

  • When Text changes, Value may need to be updated.
  • When Value changes, Text may need to be updated.

However, both parameters can change at the same time. For example, an end user might use two-way binding for both Text and Value. In such cases, the incoming values may already be consistent (e.g., Value and its correct textual representation), or they may conflict for some reason.

At that point, the component must decide which parameter should take precedence.

Without access to ParameterView, this decision becomes effectively impossible inside the change handler with ParameterState. While it is theoretically possible to introduce boolean flags inside ComponentBase.SetParametersAsync to track changes, this approach is fragile, error-prone, and can easily lead to race conditions.

Checklist:

  • I've read the contribution guidelines
  • My code follows the style of this project
  • I've added or updated relevant unit tests

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the ParameterState framework by adding a ParameterView property to ParameterChangedEventArgs<T>, enabling change handlers to inspect related parameters that were set simultaneously. This addresses scenarios where components need to resolve dependencies between parameters (e.g., Text and Value in input components) and determine which should take precedence when both change at the same time.

  • Added ParameterView property to ParameterChangedEventArgs<T> to provide a snapshot of all parameters set during the change
  • Updated constructor to require ParameterView as the first parameter (breaking change to public API)
  • Added comprehensive test coverage to verify ParameterView is correctly passed and contains expected parameters

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/MudBlazor/State/ParameterChangedEventArgs.cs Added ParameterView property and updated constructor signature to accept ParameterView as first parameter, including XML documentation
src/MudBlazor/State/ParameterStateInternalOfT.cs Updated instantiation of ParameterChangedEventArgs to pass the ParameterView parameter
src/MudBlazor.UnitTests/State/ParameterStateTests.cs Added new test verifying ParameterView contains multiple parameters and updated existing test assertions to include ParameterView
src/MudBlazor.UnitTests/State/ParameterScopeContainerTests.cs Updated test assertions to include ParameterView in expected ParameterChangedEventArgs instances

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ScarletKuro ScarletKuro merged commit 8c4f8f4 into MudBlazor:dev Dec 14, 2025
1 of 2 checks passed
@ScarletKuro ScarletKuro deleted the parameterstate_handler_paramview branch December 14, 2025 01:09
@danielchalmers danielchalmers added the refactor Reorganizes code and has no changes to the API or functionality in the main library label Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Reorganizes code and has no changes to the API or functionality in the main library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants