-
-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Describe the bug 🐞
[Reactive]
public double MaxValue { get; set; }
[Reactive]
public double MinValue { get; set; }
If I were to have the above code (code weaved to be a notify property at build time) and I were to write:
var minMaxObs = this.WhenAnyValue(v => v.MinValue, v => v.MaxValue,
(min, max) => min < max)
this.ValidationRule(v => v.MaxValue, minMaxObs,
"Value must be less than max value.");
this.WhenAnyPropertyChanged("MaxValue").Subscribe(_ => {
// save to database here
});
Then when inside my subscribe callback HasErrors
is false when a validation error has occurred. It seems like the state of HasErrors
is behind one, because if the property is updated again and still invalid, HasErrors
will be true.
I've tried re-ordering my observables so that validation rules were last, that didn't work.
EDIT:
This seems to be caused by WhenAnyPropertyChanged
being called before WhenAnyValue
, even though the order that subscribers are set up are right. This may be an upstream issue. A workaround I found is dispatching on the UI thread the subscription of the 'WhenAnyPropertyChanged' callback. I'm using WhenAnyPropertyChanged
because I have a framework I created where properties marked with a specified attribute automatically save changes to the database, without requiring me to make observables for all of them.
Step to reproduce
Create a notifiable property and subscribe to changes via ReactiveUI WhenAnyPropertyChanged
extension. Notice that validation status is wrong within subscription callback.
Reproduction repository
https://github.com/reactiveui/ReactiveUI
Expected behavior
HasErrors
should correctly reflect validation status.
Screenshots 🖼️
No response
IDE
No response
Operating system
Windows
Version
11
Device
PC
ReactiveUI Version
3.1.7
Additional information ℹ️
No response