Skip to content
Permalink
Browse files

fix: Blazor StateHasChanged not firing on ViewModel change (#2303)

  • Loading branch information
glennawatson committed Jan 6, 2020
1 parent 908579d commit 8d7f45d6d2e1d29fc274879b8e7c3c07893e1740
@@ -37,7 +37,8 @@ public class ReactiveComponentBase<T> : ComponentBase, IViewFor<T>, INotifyPrope
/// </summary>
public ReactiveComponentBase()
{
var propertyChangedObservable = this.WhenAnyValue(x => x.ViewModel)
this.WhenAnyValue(x => x.ViewModel).Subscribe(_ => StateHasChanged());
var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel)
.Select(x => Observable.FromEvent<PropertyChangedEventHandler, Unit>(

This comment has been minimized.

Copy link
@richbryant

richbryant Jan 17, 2020

Contributor

Pretty sure this is what introduced #2308

eventHandler =>
{
@@ -49,7 +50,7 @@ public ReactiveComponentBase()
eh => x.PropertyChanged -= eh))
.Switch();

propertyChangedObservable.Do(_ => StateHasChanged()).Subscribe();
viewModelsPropertyChanged.Do(_ => StateHasChanged()).Subscribe();
}

/// <inheritdoc />
@@ -33,7 +33,8 @@ public class ReactiveLayoutComponentBase<T> : LayoutComponentBase, IViewFor<T>,
/// </summary>
public ReactiveLayoutComponentBase()
{
var propertyChangedObservable = this.WhenAnyValue(x => x.ViewModel)
this.WhenAnyValue(x => x.ViewModel).Subscribe(_ => StateHasChanged());
var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel)
.Select(x => Observable.FromEvent<PropertyChangedEventHandler, Unit>(
eventHandler =>
{
@@ -45,7 +46,7 @@ public ReactiveLayoutComponentBase()
eh => x.PropertyChanged -= eh))
.Switch();

propertyChangedObservable.Do(_ => StateHasChanged()).Subscribe();
viewModelsPropertyChanged.Do(_ => StateHasChanged()).Subscribe();
}

/// <inheritdoc />

0 comments on commit 8d7f45d

Please sign in to comment.
You can’t perform that action at this time.