File tree 8 files changed +59
-11
lines changed
8 files changed +59
-11
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,9 @@ public static class Inertia
38
38
39
39
public static LazyProp < T > Lazy < T > ( Func < T ? > callback ) => _factory . Lazy ( callback ) ;
40
40
public static LazyProp < T > Lazy < T > ( Func < Task < T ? > > callback ) => _factory . Lazy ( callback ) ;
41
+
42
+ public static DeferredProp < T > Defer < T > ( Func < T ? > callback , string ? group = null ) => _factory . Defer ( callback , group ) ;
43
+ public static DeferredProp < T > Defer < T > ( Func < Task < T ? > > callback , string ? group = null ) => _factory . Defer ( callback , group ) ;
41
44
42
45
public static AlwaysProp < T > Always < T > ( Func < T ? > callback ) => _factory . Always ( callback ) ;
43
46
public static AlwaysProp < T > Always < T > ( Func < Task < T ? > > callback ) => _factory . Always ( callback ) ;
Original file line number Diff line number Diff line change 1
1
namespace InertiaNetCore . Models ;
2
2
3
- public readonly record struct InertiaPage ( )
3
+ public readonly record struct InertiaPage
4
4
{
5
- public InertiaProps Props { get ; init ; } = default ! ;
6
- public string Component { get ; init ; } = default ! ;
7
- public string ? Version { get ; init ; } = null ;
8
- public string Url { get ; init ; } = default ! ;
5
+ public required InertiaProps Props { get ; init ; }
6
+ public required Dictionary < string , List < string > > DeferredProps { get ; init ; }
7
+ public required string Component { get ; init ; }
8
+ public required string ? Version { get ; init ; }
9
+ public required string Url { get ; init ; }
9
10
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ internal async Task<InertiaProps> ToProcessedProps(List<string>? partials)
13
13
14
14
foreach ( var ( key , value ) in this )
15
15
{
16
- if ( partials is null && value is ILazyProp )
16
+ if ( partials is null && value is IIgnoreFirstProp )
17
17
continue ;
18
18
19
19
if ( partials is not null && value is not IAlwaysProp && ! partials . Contains ( key , StringComparer . InvariantCultureIgnoreCase ) )
Original file line number Diff line number Diff line change 1
1
using System . Text . Json ;
2
2
using InertiaNetCore . Extensions ;
3
3
using InertiaNetCore . Models ;
4
+ using InertiaNetCore . Utils ;
4
5
using Microsoft . AspNetCore . Http ;
5
6
using Microsoft . AspNetCore . Mvc ;
6
7
using Microsoft . AspNetCore . Mvc . ModelBinding ;
@@ -21,6 +22,7 @@ public async Task ExecuteResultAsync(ActionContext context)
21
22
Version = version ,
22
23
Url = context . HttpContext . RequestedUri ( ) ,
23
24
Props = await GetFinalProps ( context ) ,
25
+ DeferredProps = GetDeferredProps ( context ) ,
24
26
} ;
25
27
26
28
if ( ! context . HttpContext . IsInertiaRequest ( ) )
@@ -70,6 +72,20 @@ private async Task<InertiaProps> GetFinalProps(ActionContext context)
70
72
return finalProps ;
71
73
}
72
74
75
+ private Dictionary < string , List < string > > GetDeferredProps ( ActionContext context )
76
+ {
77
+ if ( context . IsInertiaPartialComponent ( component ) )
78
+ return [ ] ;
79
+
80
+ return props
81
+ . Where ( prop => prop . Value is IDeferredProp )
82
+ . GroupBy ( prop => ( prop . Value as IDeferredProp ) ! . Group )
83
+ . ToDictionary (
84
+ g => g . Key ?? g . Select ( x => x . Key ) . First ( ) ,
85
+ g => g . Select ( x => x . Key ) . ToList ( )
86
+ ) ;
87
+ }
88
+
73
89
private static Dictionary < string , string > GetErrors ( ActionContext context )
74
90
{
75
91
var sessionErrors = context . HttpContext . Session . GetString ( "errors" ) ;
Original file line number Diff line number Diff line change @@ -113,6 +113,8 @@ public void Flash(string key, string? value)
113
113
114
114
public LazyProp < T > Lazy < T > ( Func < T ? > callback ) => new ( callback ) ;
115
115
public LazyProp < T > Lazy < T > ( Func < Task < T ? > > callback ) => new ( callback ) ;
116
+ public DeferredProp < T > Defer < T > ( Func < T ? > callback , string ? group ) => new ( callback , group ) ;
117
+ public DeferredProp < T > Defer < T > ( Func < Task < T ? > > callback , string ? group ) => new ( callback , group ) ;
116
118
public AlwaysProp < T > Always < T > ( Func < T ? > callback ) => new ( callback ) ;
117
119
public AlwaysProp < T > Always < T > ( Func < Task < T ? > > callback ) => new ( callback ) ;
118
120
}
Original file line number Diff line number Diff line change
1
+ namespace InertiaNetCore . Utils ;
2
+
3
+ /// <summary>
4
+ /// Deferred props allow you to defer the loading of certain page data until after the initial page render.
5
+ /// This can be useful for improving the perceived performance of your app by allowing the initial page render to happen as quickly as possible.
6
+ /// </summary>
7
+ public class DeferredProp < T > : InvokableProp < T > , IDeferredProp
8
+ {
9
+ public string ? Group { get ; }
10
+
11
+ public DeferredProp ( Func < T ? > callback , string ? group ) : base ( callback )
12
+ {
13
+ Group = group ;
14
+ }
15
+
16
+ public DeferredProp ( Func < Task < T ? > > callbackAsync , string ? group ) : base ( callbackAsync )
17
+ {
18
+ Group = group ;
19
+ }
20
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace InertiaNetCore . Utils ;
4
4
5
+ public interface IViteBuilder
6
+ {
7
+ HtmlString ReactRefresh ( ) ;
8
+ HtmlString Input ( string path ) ;
9
+ }
10
+
5
11
internal interface IInvokableProp
6
12
{
7
13
internal Task < object ? > InvokeToObject ( ) ;
8
14
}
9
15
10
16
internal interface IAlwaysProp ;
11
17
12
- internal interface ILazyProp ;
18
+ internal interface IIgnoreFirstProp ;
13
19
20
+ internal interface ILazyProp : IIgnoreFirstProp ;
14
21
15
- public interface IViteBuilder
22
+ internal interface IDeferredProp : IIgnoreFirstProp
16
23
{
17
- HtmlString ReactRefresh ( ) ;
18
- HtmlString Input ( string path ) ;
24
+ string ? Group { get ; }
19
25
}
Original file line number Diff line number Diff line change @@ -333,6 +333,6 @@ export default defineConfig({
333
333
334
334
## Work in progress
335
335
336
- - [ ] Deferred props
336
+ - [x ] Deferred props
337
337
- [ ] Merging props
338
338
- [ ] History encryption
You can’t perform that action at this time.
0 commit comments