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
40 changes: 18 additions & 22 deletions src/ReactiveUI.Blazor/ReactiveComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,6 @@ public class ReactiveComponentBase<T> : ComponentBase, IViewFor<T>, INotifyPrope

private bool _disposedValue; // To detect redundant calls

/// <summary>
/// Initializes a new instance of the <see cref="ReactiveComponentBase{T}"/> class.
/// </summary>
public ReactiveComponentBase()
{
var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel)
.Where(x => x != null)
.Select(x => Observable.FromEvent<PropertyChangedEventHandler, Unit>(
eventHandler =>
{
void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default);

return Handler;
},
eh => x.PropertyChanged += eh,
eh => x.PropertyChanged -= eh))
.Switch();

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

/// <inheritdoc />
public event PropertyChangedEventHandler PropertyChanged;

Expand Down Expand Up @@ -105,8 +84,25 @@ protected override void OnAfterRender(bool isFirstRender)
{
if (isFirstRender)
{
this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => InvokeAsync(StateHasChanged));
this.WhenAnyValue(x => x.ViewModel)
.Skip(1)
.Where(x => x != null)
.Subscribe(_ => InvokeAsync(StateHasChanged));
}

this.WhenAnyValue(x => x.ViewModel)
.Where(x => x != null)
.Select(x => Observable.FromEvent<PropertyChangedEventHandler, Unit>(
eventHandler =>
{
void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default);
return Handler;
},
eh => x.PropertyChanged += eh,
eh => x.PropertyChanged -= eh))
.Switch()
.Do(_ => InvokeAsync(StateHasChanged))
.Subscribe();
}

/// <summary>
Expand Down
40 changes: 18 additions & 22 deletions src/ReactiveUI.Blazor/ReactiveLayoutComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,6 @@ public class ReactiveLayoutComponentBase<T> : LayoutComponentBase, IViewFor<T>,

private bool _disposedValue; // To detect redundant calls

/// <summary>
/// Initializes a new instance of the <see cref="ReactiveLayoutComponentBase{T}"/> class.
/// </summary>
public ReactiveLayoutComponentBase()
{
var viewModelsPropertyChanged = this.WhenAnyValue(x => x.ViewModel)
.Where(x => x != null)
.Select(x => Observable.FromEvent<PropertyChangedEventHandler, Unit>(
eventHandler =>
{
void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default);

return Handler;
},
eh => x.PropertyChanged += eh,
eh => x.PropertyChanged -= eh))
.Switch();

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

/// <inheritdoc />
public event PropertyChangedEventHandler PropertyChanged;

Expand Down Expand Up @@ -102,8 +81,25 @@ protected override void OnAfterRender(bool isFirstRender)
{
if (isFirstRender)
{
this.WhenAnyValue(x => x.ViewModel).Where(x => x != null).Subscribe(_ => InvokeAsync(StateHasChanged));
this.WhenAnyValue(x => x.ViewModel)
.Skip(1)
.Where(x => x != null)
.Subscribe(_ => InvokeAsync(StateHasChanged));
}

this.WhenAnyValue(x => x.ViewModel)
.Where(x => x != null)
.Select(x => Observable.FromEvent<PropertyChangedEventHandler, Unit>(
eventHandler =>
{
void Handler(object sender, PropertyChangedEventArgs e) => eventHandler(Unit.Default);
return Handler;
},
eh => x.PropertyChanged += eh,
eh => x.PropertyChanged -= eh))
.Switch()
.Do(_ => InvokeAsync(StateHasChanged))
.Subscribe();
}

/// <summary>
Expand Down
58 changes: 58 additions & 0 deletions src/ReactiveUI.Mac.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.Testing.Tests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.AndroidX", "ReactiveUI.AndroidX\ReactiveUI.AndroidX.csproj", "{294D8C67-0181-41B4-AB28-0114CE3D6390}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.Blazor", "ReactiveUI.Blazor\ReactiveUI.Blazor.csproj", "{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
Expand Down Expand Up @@ -584,6 +586,62 @@ Global
{294D8C67-0181-41B4-AB28-0114CE3D6390}.Release|x64.Build.0 = Release|Any CPU
{294D8C67-0181-41B4-AB28-0114CE3D6390}.Release|x86.ActiveCfg = Release|Any CPU
{294D8C67-0181-41B4-AB28-0114CE3D6390}.Release|x86.Build.0 = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|Mixed Platforms.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|ARM.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|ARM.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|iPhone.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|Mixed Platforms.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|x64.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|x64.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|x86.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.AppStore|x86.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|ARM.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|ARM.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|iPhone.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|x64.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|x64.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|x86.ActiveCfg = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Debug|x86.Build.0 = Debug|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|Any CPU.Build.0 = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|ARM.ActiveCfg = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|ARM.Build.0 = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|iPhone.ActiveCfg = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|iPhone.Build.0 = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|x64.ActiveCfg = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|x64.Build.0 = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|x86.ActiveCfg = Release|Any CPU
{8D4DDE4A-56E2-4FB2-802C-92C8992E5CB1}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down