mirror of
https://github.com/AlexMacocian/TrailBlazr.git
synced 2026-07-15 15:20:00 +00:00
Expose ParametersSet API
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>0.2.7</Version>
|
||||
<Version>0.2.8</Version>
|
||||
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
||||
@@ -15,7 +15,7 @@ public abstract class ViewModelBase<TViewModel, TView> : INotifyPropertyChanged
|
||||
private set
|
||||
{
|
||||
field = value;
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.View)));
|
||||
this.NotifyPropertyChanged(nameof(this.View));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,5 +29,12 @@ public abstract class ViewModelBase<TViewModel, TView> : INotifyPropertyChanged
|
||||
this.View?.RefreshView();
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public virtual ValueTask Initialize(CancellationToken cancellationToken) => ValueTask.CompletedTask;
|
||||
|
||||
public virtual ValueTask ParametersSet(TView view, CancellationToken cancellationToken) => ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,18 @@ public abstract class ViewBase<TView, TViewModel> : ComponentBase
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
await base.OnParametersSetAsync();
|
||||
if (this is not TView view)
|
||||
{
|
||||
throw new InvalidOperationException($"View is not of type {typeof(TView).Name}. Actual type: {this.GetType().Name}");
|
||||
}
|
||||
|
||||
using var initializationCts = new CancellationTokenSource(InitializationTimeout);
|
||||
await this.ViewModel.ParametersSet(view, initializationCts.Token);
|
||||
}
|
||||
|
||||
internal void RefreshView()
|
||||
{
|
||||
this.StateHasChanged();
|
||||
|
||||
Reference in New Issue
Block a user