Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/ReactiveUI.Blazor/ReactiveComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;

namespace ReactiveUI.Blazor
Expand All @@ -35,7 +36,6 @@ public class ReactiveComponentBase<T> : ComponentBase, IViewFor<T>, INotifyPrope
/// </summary>
public ReactiveComponentBase()
{
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>(
Expand All @@ -56,6 +56,7 @@ public ReactiveComponentBase()
public event PropertyChangedEventHandler PropertyChanged;

/// <inheritdoc />
[Parameter]
public T ViewModel
{
get => _viewModel;
Expand Down Expand Up @@ -99,6 +100,15 @@ protected override void OnInitialized()
base.OnInitialized();
}

/// <inheritdoc />
protected override void OnAfterRender(bool isFirstRender)
{
if (isFirstRender)
{
this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => InvokeAsync(StateHasChanged));
}
}

/// <summary>
/// Invokes the property changed event.
/// </summary>
Expand Down
11 changes: 10 additions & 1 deletion src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;

namespace ReactiveUI.Blazor
Expand All @@ -33,7 +34,6 @@ public class ReactiveLayoutComponentBase<T> : LayoutComponentBase, IViewFor<T>,
/// </summary>
public ReactiveLayoutComponentBase()
{
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>(
Expand Down Expand Up @@ -97,6 +97,15 @@ protected override void OnInitialized()
base.OnInitialized();
}

/// <inheritdoc />
protected override void OnAfterRender(bool isFirstRender)
{
if (isFirstRender)
{
this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => InvokeAsync(StateHasChanged));
}
}

/// <summary>
/// Invokes the property changed event.
/// </summary>
Expand Down