Skip to content

Commit 70eae9b

Browse files
committed
refactor: 使用新的扩展方法减少代码
1 parent b08d53a commit 70eae9b

File tree

12 files changed

+14
-20
lines changed

12 files changed

+14
-20
lines changed

src/BootstrapBlazor/Components/Validate/ValidateBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ public virtual void ToggleMessage(IEnumerable<ValidationResult> results)
485485

486486
private JSModule? ValidateModule { get; set; }
487487

488-
private Task<JSModule> LoadValidateModule() => JSRuntime.LoadModule("./_content/BootstrapBlazor/modules/validate.js");
488+
private Task<JSModule> LoadValidateModule() => JSRuntime.LoadModuleByName("validate");
489489

490490
/// <summary>
491491
/// 增加客户端 Tooltip 方法

src/BootstrapBlazor/Components/WebSpeech/WebSpeechService.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace BootstrapBlazor.Components;
1010
/// <summary>
1111
/// Web Speech 服务
1212
/// </summary>
13-
public class WebSpeechService(IJSRuntime runtime, IComponentIdGenerator ComponentIdGenerator, ILogger<WebSpeechService> logger)
13+
public class WebSpeechService(IJSRuntime runtime, IComponentIdGenerator ComponentIdGenerator)
1414
{
1515
private JSModule? SynthesisModule { get; set; }
1616

@@ -24,9 +24,7 @@ public async Task<WebSpeechSynthesizer> CreateSynthesizerAsync()
2424
{
2525
if (SynthesisModule == null)
2626
{
27-
var moduleName = "./_content/BootstrapBlazor/modules/synthesis.js";
28-
logger.LogInformation("load module {moduleName}", moduleName);
29-
SynthesisModule = await runtime.LoadModule(moduleName);
27+
SynthesisModule = await runtime.LoadModuleByName("synthesis");
3028
}
3129
return new WebSpeechSynthesizer(SynthesisModule, ComponentIdGenerator);
3230
}
@@ -39,9 +37,7 @@ public async Task<WebSpeechRecognition> CreateRecognitionAsync()
3937
{
4038
if (RecognitionModule == null)
4139
{
42-
var moduleName = "./_content/BootstrapBlazor/modules/recognition.js";
43-
logger.LogInformation("load module {moduleName}", moduleName);
44-
RecognitionModule = await runtime.LoadModule(moduleName);
40+
RecognitionModule = await runtime.LoadModuleByName("recognition");
4541
}
4642
return new WebSpeechRecognition(RecognitionModule, ComponentIdGenerator);
4743
}

src/BootstrapBlazor/Services/AjaxService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class AjaxService(IJSRuntime jSRuntime)
1515
[NotNull]
1616
private JSModule? _module = null;
1717

18-
private Task<JSModule> LoadModule() => jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/ajax.js");
18+
private Task<JSModule> LoadModule() => jSRuntime.LoadModuleByName("ajax");
1919

2020
/// <summary>
2121
/// 调用Ajax方法发送请求

src/BootstrapBlazor/Services/Bluetooth/DefaultBluetooth.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public DefaultBluetooth(IJSRuntime jsRuntime)
4444

4545
private async Task<JSModule> LoadModule()
4646
{
47-
var module = await _runtime.LoadModule("./_content/BootstrapBlazor/modules/bt.js");
47+
var module = await _runtime.LoadModuleByName("bt");
4848

4949
IsSupport = await module.InvokeAsync<bool>("init");
5050
return module;

src/BootstrapBlazor/Services/ClipboardService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ClipboardService(IJSRuntime jSRuntime)
1313
[NotNull]
1414
private JSModule? _module = null;
1515

16-
private Task<JSModule> LoadModule() => jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/utility.js");
16+
private Task<JSModule> LoadModule() => jSRuntime.LoadUtility();
1717

1818
/// <summary>
1919
/// 获取剪切板数据方法

src/BootstrapBlazor/Services/DefaultBrowserFingerService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ class DefaultBrowserFingerService(IJSRuntime jSRuntime) : IBrowserFingerService
1313
[NotNull]
1414
private JSModule? _module = null;
1515

16-
private Task<JSModule> LoadModule() => jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/utility.js");
17-
1816
/// <summary>
1917
/// 获取剪切板数据方法
2018
/// </summary>
2119
public async Task<string?> GetFingerCodeAsync(CancellationToken token = default)
2220
{
23-
_module ??= await LoadModule();
21+
_module ??= await jSRuntime.LoadUtility();
2422
return await _module.InvokeAsync<string?>("getFingerCode", token);
2523
}
2624
}

src/BootstrapBlazor/Services/DefaultGeoLocationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public DefaultGeoLocationService(IJSRuntime jsRuntime)
2828
Interop = DotNetObjectReference.Create(this);
2929
}
3030

31-
private Task<JSModule> LoadModule() => JSRuntime.LoadModule("./_content/BootstrapBlazor/modules/geo.js");
31+
private Task<JSModule> LoadModule() => JSRuntime.LoadModuleByName("geo");
3232

3333
/// <summary>
3434
/// get the current position of the device

src/BootstrapBlazor/Services/EyeDropperService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class EyeDropperService(IJSRuntime jSRuntime)
1919
/// <returns></returns>
2020
public async Task<string?> PickAsync(CancellationToken token = default)
2121
{
22-
_module ??= await jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/eye-dropper.js");
22+
_module ??= await jSRuntime.LoadModuleByName("eye-dropper");
2323
return await _module.InvokeAsync<string?>("open", token);
2424
}
2525
}

src/BootstrapBlazor/Services/FullScreenService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class FullScreenService(IJSRuntime jSRuntime)
2121
/// <returns></returns>
2222
public async Task Toggle(FullScreenOption? option = null, CancellationToken token = default)
2323
{
24-
_module ??= await jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/fullscreen.js");
24+
_module ??= await jSRuntime.LoadModuleByName("fullscreen");
2525
await _module.InvokeVoidAsync("toggle", token, option);
2626
}
2727
}

src/BootstrapBlazor/Services/NotificationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public NotificationService(IJSRuntime runtime, ICacheManager cache)
3232
Interop = DotNetObjectReference.Create(this);
3333
}
3434

35-
private Task<JSModule> LoadModule() => JSRuntime.LoadModule("./_content/BootstrapBlazor/modules/noti.js");
35+
private Task<JSModule> LoadModule() => JSRuntime.LoadModuleByName("noti");
3636

3737
/// <summary>
3838
/// 检查浏览器通知权限状态

0 commit comments

Comments
 (0)