From ee32844de22ed420a2d14be754be7e01e5d8149e Mon Sep 17 00:00:00 2001 From: Rich Bryant Date: Fri, 17 Jan 2020 18:50:00 +0000 Subject: [PATCH 1/6] Update ReactiveComponentBase.cs --- .../ReactiveComponentBase.cs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs index f8ef575029..ba0e832005 100644 --- a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs @@ -37,21 +37,22 @@ public class ReactiveComponentBase : ComponentBase, IViewFor, INotifyPrope /// public ReactiveComponentBase() { - this.WhenAnyValue(x => x.ViewModel).Subscribe(_ => StateHasChanged()); - var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel) - .Where(x => x != null) - .Select(x => Observable.FromEvent( - eventHandler => - { - void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default); - - return Handler; - }, - eh => x.PropertyChanged += eh, - eh => x.PropertyChanged -= eh)) - .Switch(); - - viewModelsPropertyChanged.Do(_ => StateHasChanged()).Subscribe(); + var propertyChangedObservable = this.WhenAnyValue(x => x.ViewModel) + .WhereNotNull() + .Select(x => Observable.FromEvent( + eventHandler => + { + void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default); + + return Handler; + }, + eh => x.PropertyChanged += eh, + eh => x.PropertyChanged -= eh)) + .Switch(); + + propertyChangedObservable.Do(_ => StateHasChanged()).Subscribe(); + + this.WhenAnyValue(x => x.ViewModel).WhereNotNull().Subscribe(_ => StateHasChanged()); } /// From 51271b7ab39dd96cd60ae05530a741a187156fc9 Mon Sep 17 00:00:00 2001 From: Rich Bryant Date: Fri, 17 Jan 2020 18:52:36 +0000 Subject: [PATCH 2/6] Added @limefrogyank's fix, reverted variable name --- src/ReactiveUI.Blazor/ReactiveComponentBase.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs index ba0e832005..b31de0b025 100644 --- a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs @@ -37,7 +37,7 @@ public class ReactiveComponentBase : ComponentBase, IViewFor, INotifyPrope /// public ReactiveComponentBase() { - var propertyChangedObservable = this.WhenAnyValue(x => x.ViewModel) + var viewModelsChangedObservable = this.WhenAnyValue(x => x.ViewModel) .WhereNotNull() .Select(x => Observable.FromEvent( eventHandler => @@ -50,8 +50,7 @@ public ReactiveComponentBase() eh => x.PropertyChanged -= eh)) .Switch(); - propertyChangedObservable.Do(_ => StateHasChanged()).Subscribe(); - + viewModelsChangedObservable.Do(_ => StateHasChanged()).Subscribe(); this.WhenAnyValue(x => x.ViewModel).WhereNotNull().Subscribe(_ => StateHasChanged()); } From 7f5dd006a0f45e5ed0f34fca77ec1b936057847e Mon Sep 17 00:00:00 2001 From: Rich Bryant Date: Fri, 17 Jan 2020 19:18:44 +0000 Subject: [PATCH 3/6] Changes to enable testing --- .../ReactiveComponentBase.cs | 6 ++-- .../ReactiveLayoutComponentBase.cs | 30 +++++++++---------- .../ReactiveUI.Blazor.csproj | 7 +++-- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs index b31de0b025..8715a99818 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 @@ -38,7 +36,7 @@ public class ReactiveComponentBase : ComponentBase, IViewFor, INotifyPrope public ReactiveComponentBase() { var viewModelsChangedObservable = this.WhenAnyValue(x => x.ViewModel) - .WhereNotNull() + .Where(x => x != null) .Select(x => Observable.FromEvent( eventHandler => { @@ -51,7 +49,7 @@ public ReactiveComponentBase() .Switch(); viewModelsChangedObservable.Do(_ => StateHasChanged()).Subscribe(); - this.WhenAnyValue(x => x.ViewModel).WhereNotNull().Subscribe(_ => StateHasChanged()); + this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged()); } /// diff --git a/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs index b73b443993..af9620f971 100644 --- a/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs @@ -33,21 +33,21 @@ public class ReactiveLayoutComponentBase : LayoutComponentBase, IViewFor, /// public ReactiveLayoutComponentBase() { - this.WhenAnyValue(x => x.ViewModel).Subscribe(_ => StateHasChanged()); - var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel) - .Where(x => x != null) - .Select(x => Observable.FromEvent( - eventHandler => - { - void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default); - - return Handler; - }, - eh => x.PropertyChanged += eh, - eh => x.PropertyChanged -= eh)) - .Switch(); - - viewModelsPropertyChanged.Do(_ => StateHasChanged()).Subscribe(); + var viewModelsChangedObservable = this.WhenAnyValue(x => x.ViewModel) + .Where(x => x != null) + .Select(x => Observable.FromEvent( + eventHandler => + { + void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default); + + return Handler; + }, + eh => x.PropertyChanged += eh, + eh => x.PropertyChanged -= eh)) + .Switch(); + + viewModelsChangedObservable.Do(_ => StateHasChanged()).Subscribe(); + this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged()); } /// diff --git a/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj b/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj index 2461bd56db..6325261366 100644 --- a/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj +++ b/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj @@ -7,10 +7,11 @@ - + - - + + + From f27bae533c4787cabbd8600d280350a76c46388f Mon Sep 17 00:00:00 2001 From: Rich Bryant Date: Fri, 17 Jan 2020 19:40:46 +0000 Subject: [PATCH 4/6] reverted proj file now tested --- src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj b/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj index 6325261366..0687178296 100644 --- a/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj +++ b/src/ReactiveUI.Blazor/ReactiveUI.Blazor.csproj @@ -10,8 +10,7 @@ - - - + + From 9ea8d857f4a4a38ba23266f6f025e953d8f7f0c8 Mon Sep 17 00:00:00 2001 From: Rich Bryant Date: Fri, 17 Jan 2020 22:00:04 +0000 Subject: [PATCH 5/6] Changed back to indented in both files --- .../ReactiveComponentBase.cs | 22 +++++++++---------- .../ReactiveLayoutComponentBase.cs | 22 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs index 8715a99818..6c43664c8d 100644 --- a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs @@ -36,17 +36,17 @@ public class ReactiveComponentBase : ComponentBase, IViewFor, INotifyPrope public ReactiveComponentBase() { var viewModelsChangedObservable = this.WhenAnyValue(x => x.ViewModel) - .Where(x => x != null) - .Select(x => Observable.FromEvent( - eventHandler => - { - void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default); - - return Handler; - }, - eh => x.PropertyChanged += eh, - eh => x.PropertyChanged -= eh)) - .Switch(); + .Where(x => x != null) + .Select(x => Observable.FromEvent( + eventHandler => + { + void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default); + + return Handler; + }, + eh => x.PropertyChanged += eh, + eh => x.PropertyChanged -= eh)) + .Switch(); viewModelsChangedObservable.Do(_ => StateHasChanged()).Subscribe(); this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged()); diff --git a/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs index af9620f971..3fdfef4d88 100644 --- a/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs @@ -34,17 +34,17 @@ public class ReactiveLayoutComponentBase : LayoutComponentBase, IViewFor, public ReactiveLayoutComponentBase() { var viewModelsChangedObservable = this.WhenAnyValue(x => x.ViewModel) - .Where(x => x != null) - .Select(x => Observable.FromEvent( - eventHandler => - { - void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default); - - return Handler; - }, - eh => x.PropertyChanged += eh, - eh => x.PropertyChanged -= eh)) - .Switch(); + .Where(x => x != null) + .Select(x => Observable.FromEvent( + eventHandler => + { + void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default); + + return Handler; + }, + eh => x.PropertyChanged += eh, + eh => x.PropertyChanged -= eh)) + .Switch(); viewModelsChangedObservable.Do(_ => StateHasChanged()).Subscribe(); this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged()); From 2f9b3e41a52fae9b5f402bcc56c37f1f8f662090 Mon Sep 17 00:00:00 2001 From: Rich Bryant Date: Fri, 17 Jan 2020 22:16:02 +0000 Subject: [PATCH 6/6] Reverted ordering and variable name --- src/ReactiveUI.Blazor/ReactiveComponentBase.cs | 6 +++--- src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs index 6c43664c8d..b6e609879f 100644 --- a/src/ReactiveUI.Blazor/ReactiveComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveComponentBase.cs @@ -35,7 +35,8 @@ public class ReactiveComponentBase : ComponentBase, IViewFor, INotifyPrope /// public ReactiveComponentBase() { - var viewModelsChangedObservable = this.WhenAnyValue(x => x.ViewModel) + 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( eventHandler => @@ -48,8 +49,7 @@ public ReactiveComponentBase() eh => x.PropertyChanged -= eh)) .Switch(); - viewModelsChangedObservable.Do(_ => StateHasChanged()).Subscribe(); - this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged()); + viewModelsPropertyChanged.Do(_ => StateHasChanged()).Subscribe(); } /// diff --git a/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs b/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs index 3fdfef4d88..e7ada4551e 100644 --- a/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs +++ b/src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs @@ -33,7 +33,8 @@ public class ReactiveLayoutComponentBase : LayoutComponentBase, IViewFor, /// public ReactiveLayoutComponentBase() { - var viewModelsChangedObservable = this.WhenAnyValue(x => x.ViewModel) + 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( eventHandler => @@ -46,8 +47,7 @@ public ReactiveLayoutComponentBase() eh => x.PropertyChanged -= eh)) .Switch(); - viewModelsChangedObservable.Do(_ => StateHasChanged()).Subscribe(); - this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => StateHasChanged()); + viewModelsPropertyChanged.Do(_ => StateHasChanged()).Subscribe(); } ///