You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
If you first create your view implementing ReactiveComponentBase<SomeViewModel> and then later set the ViewModel property to an instance of SomeViewModel, the page does not update with the contents of the viewmodel. The page will only update when you manually call StateHasChanged().
public T ViewModel
{
get => _viewModel;
set
{
if (EqualityComparer<T>.Default.Equals(_viewModel, value))
{
return;
}
_viewModel = value;
OnPropertyChanged();
}
}
When the ViewModel setter is run, the OnPropertyChanged is triggering both WhenAnyValue observable and the inner event-observable. Somehow, the Switch() statement is being triggered first... and the inner event-observable is being triggered on the old observable for ViewModel, rather than the new observable for the new ViewModel. http://reactivex.io/documentation/operators/switch.html
Apparently, those old events just go nowhere... so they are not triggering the Do() statement.
A fix would be to stick a StateHasChanged() into the ViewModel's setter after the OnPropertyChanged call.
The text was updated successfully, but these errors were encountered:
The solution is almost there. Just needs a WhenAnyValue() also for the ViewModel itself, since at the moment it's only detecting properties changing on the ViewModels. I will implement a fix later today. Thanks for the report.
Describe the bug
If you first create your view implementing
ReactiveComponentBase<SomeViewModel>
and then later set theViewModel
property to an instance ofSomeViewModel
, the page does not update with the contents of the viewmodel. The page will only update when you manually callStateHasChanged()
.Related to the end of #2240
Steps To Reproduce
ReactiveComponentBase<>
view with the ViewModel property set to null.Text=@(ViewModel?.SampleText)
Expected behavior
As soon as the ViewModel is set, the page should update to show the new contents.
Additional context
https://github.com/reactiveui/ReactiveUI/blob/master/src/ReactiveUI.Blazor/ReactiveComponentBase.cs#L40-L52
The problem is here:
and here:
When the
ViewModel
setter is run, theOnPropertyChanged
is triggering bothWhenAnyValue
observable and the inner event-observable. Somehow, the Switch() statement is being triggered first... and the inner event-observable is being triggered on the old observable for ViewModel, rather than the new observable for the new ViewModel.http://reactivex.io/documentation/operators/switch.html
Apparently, those old events just go nowhere... so they are not triggering the Do() statement.
A fix would be to stick a StateHasChanged() into the ViewModel's setter after the
OnPropertyChanged
call.The text was updated successfully, but these errors were encountered: