Skip to content

Commit

Permalink
Merge pull request #127 from jinaga/unload-on-logout
Browse files Browse the repository at this point in the history
Provide a way to unload view models on log out
  • Loading branch information
michaellperry authored Jul 14, 2024
2 parents a8ed53e + ff7ba32 commit 9e01487
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Jinaga.Maui/Binding/INavigationLifecycleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public interface INavigationLifecycleManager
/// </summary>
/// <param name="viewModel">The view model to stop managing</param>
void Hidden(ILifecycleManaged viewModel);
/// <summary>
/// Unload all view models that are not visible.
/// Call this method when the user logs out.
/// </summary>
void UnloadInvisible();
}
9 changes: 9 additions & 0 deletions Jinaga.Maui/Binding/NavigationLifecycleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ public void Hidden(ILifecycleManaged viewModel)
}
}

public void UnloadInvisible()
{
foreach (var viewModel in loadedViewModels.Except(visibleViewModels))
{
viewModel.Unload();
loadedViewModels = loadedViewModels.Remove(viewModel);
}
}

// Invariants:
// All visible view models are loaded.
// No descendants of a visible view model are loaded, unless
Expand Down

0 comments on commit 9e01487

Please sign in to comment.