5 changed files
WPE.App.Base | ||
AppComponent.cs | ||
AppJsComponent.cs | ||
JsTypeResolutionExtensions.cs | ||
SubJsComponent.cs | ||
WPE.App.Base.csproj | ||
Add comment 84 else
Add comment 85 AppComponentState = AppComponentState.Valid;
Add comment 86 }
Add comment 87 Plus
Add comment 88 Plus /// <summary>
Add comment 89 Plus /// Create file path for library wwwroot
Add comment 90 Plus /// </summary>
Add comment 91 Plus /// <param name="path">File path in wwwroot</param>
Add comment 92 Plus /// <returns>File path with assembly reference</returns>
Add comment 93 Plus protected string GetFilePath(string path)
Add comment 94 Plus {
Add comment 95 Plus return $"_content/{GetType().Assembly.GetName().Name}/{path}?v={GetType().Assembly.GetName().Version}";
Add comment 96 Plus }
Add comment 87 97 }
Add comment 88 98 }
Add comment 89 99
Add comment 6 /// <summary>
Add comment 7 /// Base class for razor componets with automatic JS module resolution
Add comment 8 /// </summary>
Add comment 9 Minus /// <typeparam name="T">Class implementing this class, needed for JS path and name definitions</typeparam>
Add comment 10 Minus public class AppJsComponent<T> : AppComponent, IAsyncDisposable where T : IJsVersion
Add comment 9 Plus public class AppJsComponent : AppComponent, IAsyncDisposable
Add comment 11 10 {
Add comment 12 11 [Inject]
Add comment 13 12 private IJSRuntime JSRuntime { get; set; }
Add comment 19 18 /// <summary>
Add comment 20 19 /// Defines the lazy task to load the JS module on the first invocation
Add comment 21 20 /// </summary>
Add comment 22 Minus /// <exception cref="NullReferenceException">Thrown, if <typeparamref name="T"/>'s assembly or fullName cannot be extracted</exception>
Add comment 21 Plus /// <exception cref="NullReferenceException">Thrown, if child classes' assembly or fullName cannot be extracted</exception>
Add comment 23 22 public AppJsComponent()
Add comment 24 23 {
Add comment 25 Minus if(!typeof(T).ExtractJsInfo(out var filePath, out var version))
Add comment 24 Plus if(!GetType().ExtractJsInfo(out var filePath, out var version))
Add comment 26 25 throw new NullReferenceException("Could not extract types full name or assembly name");
Add comment 27 26 ModuleTask = new(() => JSRuntime!.InvokeAsync<IJSObjectReference>("import", $"./_content/{filePath}.razor.js?v={version}").AsTask());
Add comment 28 27 }
JsTypeResolutionExtensions.cs
/WPE.App.Base/JsTypeResolutionExtensions.cs-1+1/WPE.App.Base/JsTypeResolutionExtensions.cs
Add comment 6 {
Add comment 7 public static bool ExtractJsInfo(this Type type, [NotNullWhen(true)] out string? filePath, [NotNullWhen(true)] out string? version)
Add comment 8 {
Add comment 9 Minus version = type.GetProperty("JsVersion")?.GetValue(null)?.ToString();
Add comment 9 Plus version = type.Assembly.GetName().Version?.ToString();
Add comment 10 filePath = type.FullName;
Add comment 11 var assembly = type.Assembly.GetName().Name;
Add comment 12 if (filePath is null || assembly is null || version is null) return false;