Skip to content

Commit cb2f49d

Browse files
committed
feat: added support for #[make_rx(...)] on unit structs
1 parent 1570e5d commit cb2f49d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/perseus-macro/src/rx_state.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,9 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream {
114114
"tuple structs can't be made reactive with this macro (try using named fields instead)",
115115
)
116116
.to_compile_error(),
117-
syn::Fields::Unit => {
118-
return syn::Error::new_spanned(
119-
new_struct,
120-
"it's pointless to make a unit struct reactive since it has no fields",
121-
)
122-
.to_compile_error()
123-
}
117+
// We may well need a unit struct for templates that use global state but don't have proper state of their own
118+
// We don't need to modify any fields
119+
syn::Fields::Unit => (),
124120
};
125121

126122
// Create a list of fields for the `.make_rx()` method
@@ -147,6 +143,7 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream {
147143
}
148144
}
149145
}
146+
syn::Fields::Unit => quote!(#name),
150147
// We filtered out the other types before
151148
_ => unreachable!(),
152149
};
@@ -174,6 +171,7 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream {
174171
}
175172
}
176173
}
174+
syn::Fields::Unit => quote!(#ident),
177175
// We filtered out the other types before
178176
_ => unreachable!(),
179177
};

0 commit comments

Comments
 (0)