I'm using ReactiveUI.Blazor to implement MVVM in a Blazor WASM application.
View models are made available using the built-in DI. They inherit from ReactiveObject and I'm using SourceList for the observable collection, e.g.
public SourceList<int> MyListOfNumbers {get; set;} = new()
The views inherit from ReactiveInjectableComponentBase<TViewModel>.
If any properties are changed in the view model the component will automatically update. However if the SourceList changes, it does not. What is the correct way to watch for SourceList changes and update the component? Currently I do the following inside OnInitialised in the view:
this.WhenActivated(disposable =>
{
ViewModel.MyListOfNumbers.Connect().Subscribe(set =>
{
InvokeAsync(StateHasChanged);
}).DisposeWith(disposable);
}
Is this correct?
(Can someone alse explain what is being done inside OnAfterRender in ReactiveInjectableComponentBase to hook up the properties to StateHasChanged)
I'm using ReactiveUI.Blazor to implement MVVM in a Blazor WASM application.
View models are made available using the built-in DI. They inherit from
ReactiveObjectand I'm usingSourceListfor the observable collection, e.g.public SourceList<int> MyListOfNumbers {get; set;} = new()The views inherit from
ReactiveInjectableComponentBase<TViewModel>.If any properties are changed in the view model the component will automatically update. However if the
SourceListchanges, it does not. What is the correct way to watch forSourceListchanges and update the component? Currently I do the following insideOnInitialisedin the view:Is this correct?
(Can someone alse explain what is being done inside
OnAfterRenderinReactiveInjectableComponentBaseto hook up the properties toStateHasChanged)