-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug]: AutoRefresh() on a collection of objects triggers listeners before their own internal OAPH listeners? #3922
Comments
This bug can be closed: I missed the part where the documentation states that the OAPH uses a scheduler to update the property:
When using an OAPH to set up a class invariant, one possible workaround is to set |
This bug can be closed: I missed the part where the documentation states that the OAPH uses a scheduler to update the property:
When using an OAPH to set up a class invariant, one possible workaround is to set |
I still wonder whether this should be make clearer through the type system, though. When using objects (as opposed to value types), the documentation recommends the property be implemented as such: public class SomeOwnerClass
{
// ...
private ObservableAsPropertyHelper<SomeClass> _someProperty;
public SomeClass SomeProperty => _someProperty.Value;
// ...
} This means that after the constructor is finished, having set up I guess at the very least, the documentation for OAPH should encourage to declare object properties as nullable types? Does that make sense? |
reopening so can look at the feedback |
Describe the bug 🐞
First off, thanks for all the work on ReactiveUI, it is a very helpful library!
Let's say I have a
ViewModel
object with two properties, one of which is just a different representation of the other one. I'm using OAPHs to derive the second property's from the first property's value. I set this up in the constructor.I then create an
ObservableCollection<ViewModel>
of such objects and want to listen to changes to that collection based on the property. It turns out that that listener gets called before the OAPH's listener, such that I observe an inconsistent state.I'm very confused by this, I would expect that the OAPH's listener, being set up in the constructor and running on the same thread as the property update, would always run before any external listeners, necessarily set up later. This does not seem to be the case.
A few additional notes:
ToObservableChangeSet().AutoRefresh()
I just usevm.WhenAnyValue(x => x.Number)
, I get the expected result, so it seems to be something withToObservableChangeSet().AutoRefresh()
.Step to reproduce
Here's a minimal example, written as a unit test (apologies for the non-standard code style, that's just how my editor is set up):
In this example,
ViewModel
has aNumber
property, which can be set, and anAsString
property which is supposed to give the string representation of this number. When running this example, I get the following two log lines, the first of which can be ignored:As you can see,
Number
andAsString
represent different values, making myViewModel
's state look inconsistent.Reproduction repository
No response
Expected behavior
I would expect the OAPH to run first, given I'm setting it up first and am not specifying that anything runs in the background, and would expect the following log lines (with
Number
andAsString
showing the same thing):Screenshots 🖼️
No response
IDE
Visual Studio 2022
Operating system
Windows
Version
No response
Device
No response
ReactiveUI Version
20.1.63
Additional information ℹ️
No response
The text was updated successfully, but these errors were encountered: