Skip to content
Permalink
Browse files

Fix: StateHasChanged firing before render being available in Blazor (#…

…2334)

* Fix: StateHasChanged firing before render being available in Blazor

* Add also ReactiveComponentBase
  • Loading branch information
glennawatson committed Jan 28, 2020
1 parent 5a0b5df commit c0fc1d3d6d6a2fa130aa5ae30a006ac79e5e28ee
@@ -35,7 +35,7 @@ public class ReactiveComponentBase<T> : ComponentBase, IViewFor<T>, INotifyPrope
/// </summary>
public ReactiveComponentBase()
{
this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged());
this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => InvokeAsync(StateHasChanged));
var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel)
.Where(x => x != null)
.Select(x => Observable.FromEvent<PropertyChangedEventHandler, Unit>(
@@ -49,7 +49,7 @@ public ReactiveComponentBase()
eh => x.PropertyChanged -= eh))
.Switch();

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

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

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

/// <inheritdoc />

0 comments on commit c0fc1d3

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