Skip to content

Commit

Permalink
Merge pull request #104 from neuroglia-io/fix-dagre-child-added-bubbling
Browse files Browse the repository at this point in the history
Bubbling "child added" event so parents can update their own nodes/clusters in Blazor.Dagre
  • Loading branch information
JBBianchi authored Aug 14, 2024
2 parents 2003539 + 1f62b4f commit 2cb5789
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Neuroglia.Blazor.Dagre/Models/ClusterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public ClusterViewModel(
child.Changed += OnChildChanged;
if (child is IClusterViewModel cluster)
{
cluster.ChildAdded += this.OnChildAdded;
this._allClusters.Add(cluster.Id, cluster);
this.Flatten(cluster);
}
Expand Down Expand Up @@ -106,6 +107,7 @@ public virtual void AddChild(INodeViewModel node)
this.ChildAdded?.Invoke(this, node);
if (node is IClusterViewModel cluster)
{
cluster.ChildAdded += this.OnChildAdded;
this._allClusters.Add(cluster.Id, cluster);
this.Flatten(cluster);
return;
Expand All @@ -114,6 +116,22 @@ public virtual void AddChild(INodeViewModel node)
this.OnChange();
}

/// <inheritdoc/>
public virtual void OnChildAdded(object? sender, INodeViewModel child)
{
if (child is IClusterViewModel cluster)
{
this._allClusters.Add(cluster.Id, cluster);
this.Flatten(cluster);
}
else if (child is INodeViewModel node)
{
this._allNodes.Add(node.Id, node);
}
this.OnChange();
this.ChildAdded?.Invoke(this, child);
}

/// <summary>
/// Adds nested nodes/clusters to allNodes/Clusters
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion src/Neuroglia.Blazor.Dagre/Models/GraphViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ public virtual async Task OnWheelAsync(ElementReference sender, WheelEventArgs e
if (this.Wheel != null) await this.Wheel.Invoke(new(e, sender, element));
}

/// <inheritdoc/>
public virtual void OnChildAdded(object? sender, INodeViewModel child)
{
if (child is IClusterViewModel cluster)
Expand Down

0 comments on commit 2cb5789

Please sign in to comment.