@@ -37,29 +37,10 @@ protected internal void ProcessResponse()
3737 {
3838 Component = _component ,
3939 Version = _version ,
40- Url = _context ! . RequestedUri ( )
40+ Url = _context ! . RequestedUri ( ) ,
41+ Props = ResolveProperties ( _props . GetType ( ) . GetProperties ( ) . ToDictionary ( o => o . Name . ToCamelCase ( ) , o => o . GetValue ( _props ) ) )
4142 } ;
4243
43- var partial = _context ! . GetPartialData ( ) ;
44- if ( partial . Any ( ) && _context ! . IsInertiaPartialComponent ( _component ) )
45- {
46- var only = _props . Only ( partial ) ;
47- var partialProps = only . ToDictionary ( o => o . ToCamelCase ( ) , o =>
48- _props . GetType ( ) . GetProperty ( o ) ? . GetValue ( _props ) ) ;
49-
50- page . Props = partialProps ;
51- }
52- else
53- {
54- var props = _props . GetType ( ) . GetProperties ( )
55- . Where ( o => o . PropertyType != typeof ( LazyProp ) )
56- . ToDictionary ( o => o . Name . ToCamelCase ( ) , o => o . GetValue ( _props ) ) ;
57-
58- page . Props = props ;
59- }
60-
61- page . Props = PrepareProps ( page . Props ) ;
62-
6344 var shared = _context ! . HttpContext . Features . Get < InertiaSharedData > ( ) ;
6445 if ( shared != null )
6546 page . Props = shared . GetMerged ( page . Props ) ;
@@ -75,13 +56,14 @@ protected internal void ProcessResponse()
7556 {
7657 Func < object ? > f => f . Invoke ( ) ,
7758 LazyProp l => l . Invoke ( ) ,
59+ AlwaysProp l => l . Invoke ( ) ,
7860 _ => pair . Value
7961 } ) ;
8062 }
8163
8264 protected internal JsonResult GetJson ( )
8365 {
84- _context ! . HttpContext . Response . Headers . Override ( "X- Inertia" , "true" ) ;
66+ _context ! . HttpContext . Response . Headers . Override ( InertiaHeader . Inertia , "true" ) ;
8567 _context ! . HttpContext . Response . Headers . Override ( "Vary" , "Accept" ) ;
8668 _context ! . HttpContext . Response . StatusCode = 200 ;
8769
@@ -127,4 +109,56 @@ public Response WithViewData(IDictionary<string, object> viewData)
127109 _viewData = viewData ;
128110 return this ;
129111 }
112+
113+ private Dictionary < string , object ? > ResolveProperties ( Dictionary < string , object ? > props )
114+ {
115+ var isPartial = _context ! . IsInertiaPartialComponent ( _component ) ;
116+
117+ if ( ! isPartial )
118+ {
119+ props = props
120+ . Where ( kv => kv . Value is not LazyProp )
121+ . ToDictionary ( kv => kv . Key , kv => kv . Value ) ;
122+ }
123+ else
124+ {
125+ props = props . ToDictionary ( kv => kv . Key , kv => kv . Value ) ;
126+
127+ if ( _context ! . HttpContext . Request . Headers . ContainsKey ( InertiaHeader . PartialOnly ) )
128+ {
129+ props = ResolveOnly ( props ) ;
130+ }
131+
132+ if ( _context ! . HttpContext . Request . Headers . ContainsKey ( InertiaHeader . PartialExcept ) )
133+ {
134+ props = ResolveExcept ( props ) ;
135+ }
136+ }
137+
138+ props = ResolveAlways ( props ) ;
139+ props = PrepareProps ( props ) ;
140+
141+ return props ;
142+ }
143+
144+ private Dictionary < string , object ? > ResolveOnly ( Dictionary < string , object ? > props )
145+ {
146+ return _context ! . OnlyProps ( props ) ;
147+ }
148+
149+ private Dictionary < string , object ? > ResolveExcept ( Dictionary < string , object ? > props )
150+ {
151+ return _context ! . ExceptProps ( props ) ;
152+ }
153+
154+ private Dictionary < string , object ? > ResolveAlways ( Dictionary < string , object ? > props )
155+ {
156+ var alwaysProps = _props . GetType ( ) . GetProperties ( )
157+ . Where ( o => o . PropertyType == typeof ( AlwaysProp ) )
158+ . ToDictionary ( o => o . Name . ToCamelCase ( ) , o => o . GetValue ( _props ) ) ; ;
159+
160+ return props
161+ . Where ( kv => kv . Value is not AlwaysProp )
162+ . Concat ( alwaysProps ) . ToDictionary ( kv => kv . Key , kv => kv . Value ) ;
163+ }
130164}
0 commit comments