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

Suggestion: Should the error state of BindableReactiveProperty be true after initialization? #282

Open
ruxo opened this issue Dec 13, 2024 · 0 comments

Comments

@ruxo
Copy link

ruxo commented Dec 13, 2024

I'm exploring the data validation feature of BindableReactiveProperty, but its initial condition complicates the setup process. Here's an example to illustrate:

var x = new BindableReactiveProperty<string>().EnableValidation(x => {
	return string.IsNullOrEmpty(x)? new InvalidDataException("Invalid X") : null;
});

x.HasErrors.Dump("After initialized");  // (1) False

x.Value = string.Empty;
x.HasErrors.Dump("Assign empty");  // (2) True

x.Value = "xx";
x.HasErrors.Dump("Assign not null");  // (3) False

In this example, after creating the property (1), HasErrors returns false, even though the internal value is default (null for a string). According to the validation logic, this should be considered invalid. Assignments in (2) and (3) correctly trigger the validation logic and update HasErrors accordingly.

Would it make sense for the EnableValidation() method to evaluate the validation logic immediately upon assignment? This change would ensure that the error state is consistent right from initialization.

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

No branches or pull requests

1 participant