@@ -150,6 +150,33 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream {
150
150
// We filtered out the other types before
151
151
_ => unreachable ! ( ) ,
152
152
} ;
153
+ let make_unrx_fields = match orig_struct. fields {
154
+ syn:: Fields :: Named ( ref mut fields) => {
155
+ let mut field_assignments = quote ! ( ) ;
156
+ for field in fields. named . iter_mut ( ) {
157
+ // We know it has an identifier because it's a named field
158
+ let field_name = field. ident . as_ref ( ) . unwrap ( ) ;
159
+ // Check if this field was registered as one to use nested reactivity
160
+ if nested_fields_map. contains_key ( field. ident . as_ref ( ) . unwrap ( ) ) {
161
+ field_assignments. extend ( quote ! {
162
+ #field_name: self . #field_name. make_unrx( ) ,
163
+ } )
164
+ } else {
165
+ // We can `.clone()` the field because we implement `Clone` on both the new and the original `struct`s, meaning all fields must also be `Clone`
166
+ field_assignments. extend ( quote ! {
167
+ #field_name: ( * self . #field_name. get_untracked( ) ) . clone( ) ,
168
+ } ) ;
169
+ }
170
+ }
171
+ quote ! {
172
+ #ident {
173
+ #field_assignments
174
+ }
175
+ }
176
+ }
177
+ // We filtered out the other types before
178
+ _ => unreachable ! ( ) ,
179
+ } ;
153
180
154
181
quote ! {
155
182
// We add a Serde derivation because it will always be necessary for Perseus on the original `struct`, and it's really difficult and brittle to filter it out
@@ -166,8 +193,7 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream {
166
193
impl #generics :: perseus:: state:: MakeUnrx for #name#generics {
167
194
type Unrx = #ident#generics;
168
195
fn make_unrx( self ) -> #ident#generics {
169
- todo!( )
170
- // #make_rx_fields
196
+ #make_unrx_fields
171
197
}
172
198
}
173
199
}
0 commit comments