< Summary

Information
Class: Nabs.Ui.ExampleJsInterop
Assembly: Nabs.Ui
File(s): /home/runner/work/Nabs/Nabs/src/Nabs.Ui/ExampleJsInterop.cs
Tag: 90_14636759620
Line coverage
0%
Covered lines: 0
Uncovered lines: 10
Coverable lines: 10
Total lines: 37
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Prompt()100%210%
DisposeAsync()0%620%

File(s)

/home/runner/work/Nabs/Nabs/src/Nabs.Ui/ExampleJsInterop.cs

#LineLine coverage
 1using Microsoft.JSInterop;
 2
 3namespace Nabs.Ui
 4{
 5    // This class provides an example of how JavaScript functionality can be wrapped
 6    // in a .NET class for easy consumption. The associated JavaScript module is
 7    // loaded on demand when first needed.
 8    //
 9    // This class can be registered as scoped DI service and then injected into Blazor
 10    // components for use.
 11
 12    public class ExampleJsInterop : IAsyncDisposable
 13    {
 14        private readonly Lazy<Task<IJSObjectReference>> moduleTask;
 15
 16        public ExampleJsInterop(IJSRuntime jsRuntime)
 17        {
 018            moduleTask = new(() => jsRuntime.InvokeAsync<IJSObjectReference>(
 019                "import", "./_content/Nabs.Ui/exampleJsInterop.js").AsTask());
 020        }
 21
 22        public async ValueTask<string> Prompt(string message)
 23        {
 024            var module = await moduleTask.Value;
 025            return await module.InvokeAsync<string>("showPrompt", message);
 026        }
 27
 28        public async ValueTask DisposeAsync()
 29        {
 030            if (moduleTask.IsValueCreated)
 31            {
 032                var module = await moduleTask.Value;
 033                await module.DisposeAsync();
 34            }
 035        }
 36    }
 37}