Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Add ViewModel.StateHasChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyDurov committed Apr 22, 2024
1 parent e95b7ff commit eb2da6c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/BitzArt.Blazor.MVVM/Components/IPersistentComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ namespace BitzArt.Blazor.MVVM;
internal interface IPersistentComponent : IComponent
{
internal PersistentComponentState ComponentState { get; }

internal void StateHasChanged();
}
7 changes: 7 additions & 0 deletions src/BitzArt.Blazor.MVVM/Components/PageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public abstract class PageBase<TViewModel> : ComponentBase, IPersistentComponent
[Inject]
protected TViewModel ViewModel { get; set; } = null!;

PersistentComponentState IPersistentComponent.ComponentState => throw new NotImplementedException();

/// <summary>
/// Method invoked when the component is ready to start, having received its initial
/// parameters from its parent in the render tree. Override this method if you will
Expand All @@ -40,4 +42,9 @@ private async Task PersistStateAsync()
{
await ViewModel.PersistStateAsync();
}

void IPersistentComponent.StateHasChanged()
{
StateHasChanged();
}
}
8 changes: 8 additions & 0 deletions src/BitzArt.Blazor.MVVM/ViewModels/PageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,12 @@ internal override Task PersistStateAsync()

return Task.CompletedTask;
}

/// <summary>
/// Notifies the component that the state has changed.
/// </summary>
protected void StateHasChanged()
{
Component.StateHasChanged();
}
}

0 comments on commit eb2da6c

Please sign in to comment.