Skip to content

Commit ca8189a

Browse files
committed
Minor changes
1 parent 1383df1 commit ca8189a

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

InertiaCore/Extensions/Configure.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static IApplicationBuilder UseInertia(this IApplicationBuilder app)
2121
if (viteBuilder != null)
2222
{
2323
Vite.UseBuilder(viteBuilder);
24-
Inertia.Version(() => Vite.GetManifestHash());
24+
Inertia.Version(Vite.GetManifestHash);
2525
}
2626

2727
app.Use(async (context, next) =>

InertiaCore/Inertia.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public static class Inertia
1919

2020
public static Task<IHtmlContent> Html(dynamic model) => _factory.Html(model);
2121

22-
public static void Version(object? version) => _factory.Version(version);
22+
public static void Version(string? version) => _factory.Version(version);
23+
24+
public static void Version(Func<string?> version) => _factory.Version(version);
2325

2426
public static string? GetVersion() => _factory.GetVersion();
2527

@@ -29,9 +31,9 @@ public static class Inertia
2931

3032
public static void Share(IDictionary<string, object?> data) => _factory.Share(data);
3133

32-
public static AlwaysProp Always(object? value) => _factory.Always(value);
34+
public static AlwaysProp Always(string value) => _factory.Always(value);
3335

34-
public static AlwaysProp Always(Func<object?> callback) => _factory.Always(callback);
36+
public static AlwaysProp Always(Func<string> callback) => _factory.Always(callback);
3537

3638
public static AlwaysProp Always(Func<Task<object?>> callback) => _factory.Always(callback);
3739

InertiaCore/ResponseFactory.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ internal interface IResponseFactory
1616
public Response Render(string component, object? props = null);
1717
public Task<IHtmlContent> Head(dynamic model);
1818
public Task<IHtmlContent> Html(dynamic model);
19-
public void Version(object? version);
19+
public void Version(string? version);
20+
public void Version(Func<string?> version);
2021
public string? GetVersion();
2122
public LocationResult Location(string url);
2223
public void Share(string key, object? value);
@@ -95,7 +96,9 @@ public async Task<IHtmlContent> Html(dynamic model)
9596
return new HtmlString($"<div id=\"app\" data-page=\"{encoded}\"></div>");
9697
}
9798

98-
public void Version(object? version) => _version = version;
99+
public void Version(string? version) => _version = version;
100+
101+
public void Version(Func<string?> version) => _version = version;
99102

100103
public string? GetVersion() => _version switch
101104
{

InertiaCore/Utils/Vite.cs

+4-8
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,11 @@ public HtmlString Input(string path)
6767
throw new Exception("Vite Manifest is invalid. Run `npm run build` and try again.");
6868
}
6969

70-
if (!manifestJson.ContainsKey(path))
70+
if (!manifestJson.TryGetValue(path, out var obj))
7171
{
7272
throw new Exception("Asset not found in manifest: " + path);
7373
}
7474

75-
var obj = manifestJson[path];
7675
var filePath = obj.GetProperty("file");
7776

7877
if (IsCssPath(filePath.ToString()))
@@ -210,12 +209,9 @@ private static string GetString(IHtmlContent content)
210209

211210
public string? GetManifest()
212211
{
213-
if (_fileSystem.File.Exists(GetPublicPathForFile(_options.Value.ManifestFilename)))
214-
{
215-
return _fileSystem.File.ReadAllText(GetPublicPathForFile(_options.Value.ManifestFilename));
216-
}
217-
218-
return null;
212+
return _fileSystem.File.Exists(GetPublicPathForFile(_options.Value.ManifestFilename))
213+
? _fileSystem.File.ReadAllText(GetPublicPathForFile(_options.Value.ManifestFilename))
214+
: null;
219215
}
220216
}
221217

InertiaCoreTests/UnitTestVite.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
using InertiaCore.Models;
44
using InertiaCore.Utils;
55
using Microsoft.AspNetCore.Builder;
6-
using Microsoft.Extensions.Options;
76
using Microsoft.AspNetCore.Http;
87
using Microsoft.AspNetCore.Mvc;
8+
using Microsoft.Extensions.Options;
99
using Moq;
10-
using Microsoft.Extensions.DependencyInjection;
1110

1211
namespace InertiaCoreTests;
1312

@@ -73,7 +72,8 @@ public void TestNotHot()
7372
}
7473

7574
[Test]
76-
[Description("Test if the Vite Helper handles generating HTML tags for both JS and CSS from HMR and the manifest properly.")]
75+
[Description(
76+
"Test if the Vite Helper handles generating HTML tags for both JS and CSS from HMR and the manifest properly.")]
7777
public void TestViteInput()
7878
{
7979
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
@@ -226,7 +226,7 @@ public async Task TestViteVersion()
226226
fileSystem.AddFile(@"/wwwroot/build/manifest.json",
227227
new MockFileData("{\"app.tsx\": {\"file\": \"assets/main-19038c6a.js\"}}"));
228228

229-
_factory.Version(() => Vite.GetManifestHash());
229+
_factory.Version(Vite.GetManifestHash);
230230

231231
var response = _factory.Render("Test/Page", new
232232
{
@@ -247,7 +247,7 @@ public async Task TestViteVersion()
247247

248248
Assert.Multiple(() =>
249249
{
250-
Assert.That(result, Is.InstanceOf(typeof(JsonResult)));
250+
Assert.That(result, Is.InstanceOf<JsonResult>());
251251

252252
var json = (result as JsonResult)?.Value;
253253
Assert.That((json as Page)?.Version, Is.EqualTo("bba1afd1066309f4a69430e0c446ba8d"));

0 commit comments

Comments
 (0)