more refoctoring work

This commit is contained in:
TheXamlGuy
2024-01-20 21:58:57 +00:00
parent 3a268db79d
commit 45070dc560
42 changed files with 477 additions and 361 deletions
@@ -1,31 +0,0 @@
namespace Hyperbar.Windows.Primary;
public class WidgetComponentViewModelEnumerator(PrimaryWidgetConfiguration configuration,
IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?> factory,
ICache<(Guid ParentId, Guid Id), PrimaryCommandConfiguration> cache) :
IViewModelEnumerator<IWidgetComponentViewModel>
{
public IEnumerable<IWidgetComponentViewModel?> Next()
{
Stack<(Guid, List<PrimaryCommandConfiguration>)> stack = new();
stack.Push((Guid.Empty, configuration.Commands));
while (stack.Count > 0)
{
(Guid currentParentId, List<PrimaryCommandConfiguration> currentConfigurations) = stack.Pop();
foreach (PrimaryCommandConfiguration configuration in currentConfigurations)
{
cache.Add((currentParentId, configuration.Id), configuration);
if (configuration.Commands is not null && configuration.Commands.Count > 0)
{
stack.Push((configuration.Id, configuration.Commands));
}
}
}
foreach (PrimaryCommandConfiguration item in configuration.Commands.OrderBy(x => x.Order))
{
yield return factory.Create(item);
}
}
}