Skip to content

Commit a780286

Browse files
authored
πŸ› fix: Use DisposeAsyncCore method of base class (#606)
* πŸ› fix: Use DisposeAsyncCore method of base class * πŸ› fix(Slider): do nothing if el was removed
1 parent e9507b4 commit a780286

6 files changed

Lines changed: 18 additions & 37 deletions

File tree

β€Žsrc/Component/BlazorComponent.Web/src/components/slider/index.tsβ€Ž

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ export function registerSliderEvents(
7575
}
7676

7777
export function unregisterSliderEvents(el: HTMLElement, id: number) {
78-
const onSliderMouseDown = sliderHandlesById[id];
79-
el.removeEventListener("mousedown", onSliderMouseDown);
80-
el.removeEventListener("touchstart", onSliderMouseDown);
78+
if (el) {
79+
const onSliderMouseDown = sliderHandlesById[id];
80+
el.removeEventListener("mousedown", onSliderMouseDown);
81+
el.removeEventListener("touchstart", onSliderMouseDown);
8182

82-
delete sliderHandlesById[id];
83+
delete sliderHandlesById[id];
84+
}
8385
}

β€Žsrc/Component/BlazorComponent/Components/OtpInput/BOtpInput.razor.csβ€Ž

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BlazorComponent
44
{
5-
public partial class BOtpInput : BDomComponentBase, IOtpInput, IAsyncDisposable
5+
public partial class BOtpInput : BDomComponentBase, IOtpInput
66
{
77
[CascadingParameter(Name = "IsDark")]
88
public bool CascadingIsDark { get; set; }
@@ -257,17 +257,10 @@ public async Task OnPasteAsync(BOtpInputEventArgs<PasteWithDataEventArgs> events
257257
}
258258
}
259259

260-
async ValueTask IAsyncDisposable.DisposeAsync()
260+
protected override async ValueTask DisposeAsyncCore()
261261
{
262-
try
263-
{
264-
_handle.Dispose();
265-
await JsInvokeAsync(JsInteropConstants.UnregisterOTPInputOnInputEvent, InputRefs);
266-
}
267-
catch (Exception)
268-
{
269-
// ignored
270-
}
262+
_handle.Dispose();
263+
await JsInvokeAsync(JsInteropConstants.UnregisterOTPInputOnInputEvent, InputRefs);
271264
}
272265
}
273266
}

β€Žsrc/Component/BlazorComponent/Components/SlideGroup/BSlideGroup.razor.csβ€Ž

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ο»Ώnamespace BlazorComponent
22
{
3-
public partial class BSlideGroup : BItemGroup, ISlideGroup, IAsyncDisposable
3+
public partial class BSlideGroup : BItemGroup, ISlideGroup
44
{
55
public BSlideGroup() : base(GroupType.SlideGroup)
66
{
@@ -305,16 +305,9 @@ protected async Task OnResize()
305305
await SetWidths();
306306
}
307307

308-
async ValueTask IAsyncDisposable.DisposeAsync()
308+
protected override async ValueTask DisposeAsyncCore()
309309
{
310-
try
311-
{
312-
await ResizeJSModule.UnobserveAsync(Ref);
313-
}
314-
catch (Exception)
315-
{
316-
// ignored
317-
}
310+
await ResizeJSModule.UnobserveAsync(Ref);
318311
}
319312
}
320313
}

β€Žsrc/Component/BlazorComponent/Components/Tabs/BTabs.razor.csβ€Ž

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ο»Ώnamespace BlazorComponent
22
{
3-
public partial class BTabs : BDomComponentBase, ITabs, IAncestorRoutable, IAsyncDisposable
3+
public partial class BTabs : BDomComponentBase, ITabs, IAncestorRoutable
44
{
55
[Inject]
66
protected IResizeJSModule ResizeJSModule { get; set; } = null!;
@@ -168,16 +168,9 @@ private async Task OnResize()
168168
await CallSlider();
169169
}
170170

171-
async ValueTask IAsyncDisposable.DisposeAsync()
171+
protected override async ValueTask DisposeAsyncCore()
172172
{
173-
try
174-
{
175-
await ResizeJSModule.UnobserveAsync(Ref);
176-
}
177-
catch (Exception)
178-
{
179-
// ignored
180-
}
173+
await ResizeJSModule.UnobserveAsync(Ref);
181174
}
182175
}
183176
}

β€Žsrc/Component/BlazorComponent/wwwroot/js/blazor-component.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žsrc/Component/BlazorComponent/wwwroot/js/blazor-component.js.mapβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)