From 97010069a2f2c3475b2b434b1c9dfaa17aaee899 Mon Sep 17 00:00:00 2001 From: Rich Bryant Date: Fri, 17 Jan 2020 22:17:53 +0000 Subject: [PATCH] Fix to stop blazor crash (#2318) * Update ReactiveComponentBase.cs * Added @limefrogyank's fix, reverted variable name * Changes to enable testing * reverted proj file now tested * Changed back to indented in both files * Reverted ordering and variable name --- src/ReactiveUI.Blazor/ReactiveComponentBase.cs | 4 +--- src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs | 2 +- src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs index f8ef575029..b6e609879f 100644 --- a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs @@ -7,12 +7,10 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Reactive; using System.Reactive.Linq; using System.Reactive.Subjects; using System.Runtime.CompilerServices; -using System.Threading.Tasks; using Microsoft.AspNetCore.Components; namespace ReactiveUI.Blazor @@ -37,7 +35,7 @@ public class ReactiveComponentBase : ComponentBase, IViewFor, INotifyPrope /// public ReactiveComponentBase() { - this.WhenAnyValue(x => x.ViewModel).Subscribe(_ => StateHasChanged()); + this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged()); var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel) .Where(x => x != null) .Select(x => Observable.FromEvent( diff --git a/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs index b73b443993..e7ada4551e 100644 --- a/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs @@ -33,7 +33,7 @@ public class ReactiveLayoutComponentBase : LayoutComponentBase, IViewFor, /// public ReactiveLayoutComponentBase() { - this.WhenAnyValue(x => x.ViewModel).Subscribe(_ => StateHasChanged()); + this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged()); var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel) .Where(x => x != null) .Select(x => Observable.FromEvent( diff --git a/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj b/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj index 2461bd56db..0687178296 100644 --- a/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj +++ b/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj @@ -7,7 +7,7 @@ - +