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

Commit

Permalink
Subscribe ComponentStateContainer to ComponentStateHasChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyDurov committed May 23, 2024
1 parent eee849a commit a03a75b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/BitzArt.Blazor.MVVM/Factory/ViewModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public ViewModel Create(IServiceProvider serviceProvider, Type viewModelType, Co
var viewModel = (ViewModel)serviceProvider.GetRequiredKeyedService(typeof(ViewModel), viewModelMap.RegistrationKey);
viewModel.Signature = signature;

viewModel.OnComponentStateChanged += (sender) =>
{
viewModel.ComponentStateContainer?.NotifyStateChanged();
return Task.CompletedTask;
};

foreach (var injection in viewModelMap.Injections)
{
if (injection.IsServiceInjection)
Expand All @@ -60,8 +66,10 @@ public ViewModel Create(IServiceProvider serviceProvider, Type viewModelType, Co
var injectedViewModel = Create(serviceProvider, injection.DependencyType, nestedSignature, parent: viewModel, affectedViewModels: affectedViewModels);
injection.Property.SetValue(viewModel, injectedViewModel);

viewModel.OnComponentStateContainerWasSet += (container)
=> injectedViewModel.ComponentStateContainer = container;
viewModel.OnComponentStateContainerWasSet += (container) =>
{
injectedViewModel.ComponentStateContainer = container;
};
}

else if (injection.IsParentViewModelInjection)
Expand Down

0 comments on commit a03a75b

Please sign in to comment.