Skip to content

[MVUX] Implement Validation into State.SetAsync and State.UpdateAsync etc. #2991

Open

Description

@DevTKSS

What would you like to be added:

  • State.Validate(AsyncFunc<T,bool> validationOperation) extension should be available for Mvux State and ListState Value Setting / Updating Operations or alternatively a Overload for the existant methods
  • Maybe we could even get a simple overload for ForEachData(
  • would fit greacefully integrate with adding a Uno.Extensions.Validation.Reactive to the existant Uno.Extensions.Validation(.Fluent)

Why is this needed:

Example code that could be used in our Model:

  • await MyIntState.UpdateAsync(oldValue => oldValue -=1, ct)
  • await MyIntState.UpdateAsync(oldValue => oldValue +=1, ct)

There seems no option to implement Validation criteria for this centrally.
e.g. what if MyIntState would have allowed/valid Value Range from 1 - 10? There is literally nothing that would be holding us back from getting beyond this Range.

What we currently need to do:

public async Task MoveLeft([FeedParameter(CurrentLane)]int currentLane, CancellationToken ct = default) // if you are lucky, your method doesn't require the CommandParameter argument, so you can utilize the Mvux Attributes like this
{
     // Or if you wouldn't be able to use FeedParameterAttribute
    // var currentLine = await CurrentLine
    if (0 < currentLine <= 10)
    {
        // Update state immutably
        await CurrentLane.UpdateAsync(lastLane => lastLane -= 1, ct);
    }
    
    var newLane = await CurrentLane

     _logger.LogDebug("Player moving left from lane {currentLane} to new lane {newLane}", currentLane, newLane);

}

And now let's assume, your State might be way more used than this here or imagine, you have a ListState in a Business environment Application!
You could not have a nice centralized Method like if something like that would exist:

public IState<int> CurrentLane => State.Value(this, () => 1).Validate(ValidateCurrentLaneUpdateAsync);

public async ValueTask<bool> ValidateCurrentLaneUpdateAsync(int newValue, CancellationToken ct)
{
    if (newValue > 10)
    {
       // Log problem?
       // send Message to the User who asked for the update, to tell him about this beeing invalid value range
       Messenger.Send(...);
       return false;
    }
    return true;
}

For which Platform:

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renders for Xamarin.Forms
  • Windows
  • Desktop
  • Build tasks

Anything else we need to know?

if you could consider adding Validation to the recognized UnoFeatures, that would be really nice too:

Activity

  1. added
    kind/enhancement
    triage/untriaged
    on Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementtriage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions