Skip to content

Commit

Permalink
Change how DiagramCanvas is disposed
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonamAnjos committed Aug 16, 2024
1 parent 1d5a782 commit 5ac3162
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Threading.Tasks;
using Blazor.Diagrams.Core.Behaviors;
using Blazor.Diagrams.Core.Behaviors;
using Blazor.Diagrams.Core.Geometry;
using Blazor.Diagrams.Extensions;
using Microsoft.AspNetCore.Components;
Expand Down Expand Up @@ -40,6 +38,9 @@ public async ValueTask DisposeAsync()
await JSRuntime.UnobserveResizes(elementReference);

_reference.Dispose();
_reference = null!;

GC.SuppressFinalize(this); // CA1816
}

private string GetLayerStyle(int order)
Expand Down
13 changes: 9 additions & 4 deletions src/Blazor.Diagrams/Extensions/JSRuntimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Threading.Tasks;
using Blazor.Diagrams.Core.Geometry;
using Blazor.Diagrams.Core.Geometry;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;

Expand Down Expand Up @@ -28,7 +26,14 @@ public static async Task ObserveResizes<T>(this IJSRuntime jsRuntime, ElementRef

public static async Task UnobserveResizes(this IJSRuntime jsRuntime, ElementReference element)
{
await jsRuntime.InvokeVoidAsync("ZBlazorDiagrams.unobserve", element, element.Id);
try
{
await jsRuntime.InvokeVoidAsync("ZBlazorDiagrams.unobserve", element, element.Id);
}
catch (ObjectDisposedException)
{
// Ignore, DotNetObjectReference was likely disposed
}
}

public static async Task AddDefaultPreventingForWheelHandler(this IJSRuntime jsRuntime, ElementReference element)
Expand Down

0 comments on commit 5ac3162

Please sign in to comment.