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
feature: Add ValidationRule based on an Observable's value #116
Comments
thargy
changed the title
feature: Add ValidationRule based in Observable
feature: Add ValidationRule based on an Observable's value
Oct 12, 2020
2 tasks
Added in #119 and should be available in the |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Currently, I have some code that parses a URL and validates it. Obviously, this can be a slow process so is done asynchronously. A simplified version can be thought of as producing an
IObservable<string>
where the string represents an error if non-null.It would be nice to add overloads to the
ValidationRule
extension method to accept anObservable<T>
and 2 functions:Func<T, bool>
, to determine if the item of typeT
is valid.Func<T, string>
, to return the corresponding error message based on the item.The ensures that there are no race conditions between evaluating the validity of the item, and its message. In our example, these functions would be:
An alternative is to define an interface
IValidationState
(which is implemented byValidationState
), but only definesIsValid
andText
. The ValidationRule can then acceptIObservable<IValidationState>
and doesn't need any extractor functions. This can form the base class of the existing implementations.Example:
I used the following implementation (note the difficulty of implementing such extensions due to
IValidatesProperties<TViewModel>.ContainsProperty<TProp>(Expression<Func<TViewModel, TProp>> propertyExpression, bool exclusively = false)
and the internal nature of theGetPropertyPath()
extension method (I inlined in this implementation). Further, I specify associated properties on creation (rather than using anAddProperty
method)And here is an example of it in use (without the extension method),
parsedAddress
is anObservable<ParsedAddress>
which contain information regarding an entered address that fires sometime after it is entered (there's also a 200msThrottle
involved in its creation).The text was updated successfully, but these errors were encountered: