Add system for creating component attributes + new #[component] attribute (#1448)
* Add `#[component]` attribute + system for creating component attributes + other stuff * Delete inlineprops.rs * Update inline_props.rs * Cargo fmt * Fix clippy warnings and paths in props/mods.rs * Include where clause in `#[inline_props]` output * Allow Clippy type complexity in `LinkProps` * Allow the type complexity lint for the entire link.rs file * Remove snake_case -> PascalCase converter, but rather enforce PascalCase Also: - Put the second function inside the main one instead of besides it. - Simplify * Simplify type check lints so they don't return false positives They will not always work, but they won't return any false positives, like for aliases. This is likely going to be replaced by a more polished Clippy-backed linting system. * Fix #583 * Cargo fmt * Add docs for `deserialize()` and remove useless comment * Add `#[component]` to prelude * Merge branch 'master' of https://github.com/tigerros/dioxus * #[inline_props] is no more. Except in the docs folder, but that's going to be removed * Remove docs folder * Remove docs from workspace * Resolve `DeserializerOutput` conversation
This commit is contained in:
1 parent
b68a1f57e0
commit
c866ae602b
281 files changed
+1122
-12818
No files matched your search
@@ -2,9 +2,9 @@
|
||||
//!
|
||||
//! However, it has been adopted to fit the Dioxus Props builder pattern.
|
||||
//!
|
||||
//! For dioxus, we make a few changes:
|
||||
//! - [ ] automatically implement Into<Option> on the setters (IE the strip setter option)
|
||||
//! - [ ] automatically implement a default of none for optional fields (those explicitly wrapped with Option<T>)
|
||||
//! For Dioxus, we make a few changes:
|
||||
//! - [ ] Automatically implement Into<Option> on the setters (IE the strip setter option)
|
||||
//! - [ ] Automatically implement a default of none for optional fields (those explicitly wrapped with Option<T>)
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
|
||||
@@ -194,8 +194,9 @@ mod field_info {
|
||||
|
||||
// children field is automatically defaulted to None
|
||||
if name == "children" {
|
||||
builder_attr.default =
|
||||
Some(syn::parse(quote!(Default::default()).into()).unwrap());
|
||||
builder_attr.default = Some(
|
||||
syn::parse(quote!(::core::default::Default::default()).into()).unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
// auto detect optional
|
||||
@@ -204,8 +205,9 @@ mod field_info {
|
||||
&& type_from_inside_option(&field.ty, true).is_some();
|
||||
if !builder_attr.strip_option && strip_option_auto {
|
||||
builder_attr.strip_option = true;
|
||||
builder_attr.default =
|
||||
Some(syn::parse(quote!(Default::default()).into()).unwrap());
|
||||
builder_attr.default = Some(
|
||||
syn::parse(quote!(::core::default::Default::default()).into()).unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(FieldInfo {
|
||||
@@ -213,7 +215,7 @@ mod field_info {
|
||||
name,
|
||||
generic_ident: syn::Ident::new(
|
||||
&format!("__{}", strip_raw_ident_prefix(name.to_string())),
|
||||
proc_macro2::Span::call_site(),
|
||||
name.span(),
|
||||
),
|
||||
ty: &field.ty,
|
||||
builder_attr,
|
||||
@@ -345,14 +347,18 @@ mod field_info {
|
||||
.ok_or_else(|| Error::new_spanned(&path, "Expected identifier"))?;
|
||||
match name.as_str() {
|
||||
"default" => {
|
||||
self.default =
|
||||
Some(syn::parse(quote!(Default::default()).into()).unwrap());
|
||||
self.default = Some(
|
||||
syn::parse(quote!(::core::default::Default::default()).into())
|
||||
.unwrap(),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
"optional" => {
|
||||
self.default =
|
||||
Some(syn::parse(quote!(Default::default()).into()).unwrap());
|
||||
self.default = Some(
|
||||
syn::parse(quote!(::core::default::Default::default()).into())
|
||||
.unwrap(),
|
||||
);
|
||||
self.strip_option = true;
|
||||
Ok(())
|
||||
}
|
||||
@@ -505,15 +511,12 @@ mod struct_info {
|
||||
.map(|(i, f)| FieldInfo::new(i, f, builder_attr.field_defaults.clone()))
|
||||
.collect::<Result<_, _>>()?,
|
||||
builder_attr,
|
||||
builder_name: syn::Ident::new(&builder_name, proc_macro2::Span::call_site()),
|
||||
builder_name: syn::Ident::new(&builder_name, ast.ident.span()),
|
||||
conversion_helper_trait_name: syn::Ident::new(
|
||||
&format!("{builder_name}_Optional"),
|
||||
proc_macro2::Span::call_site(),
|
||||
),
|
||||
core: syn::Ident::new(
|
||||
&format!("{builder_name}_core"),
|
||||
proc_macro2::Span::call_site(),
|
||||
ast.ident.span(),
|
||||
),
|
||||
core: syn::Ident::new(&format!("{builder_name}_core"), ast.ident.span()),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -551,11 +554,11 @@ mod struct_info {
|
||||
let phantom_generics = self.generics.params.iter().map(|param| match param {
|
||||
syn::GenericParam::Lifetime(lifetime) => {
|
||||
let lifetime = &lifetime.lifetime;
|
||||
quote!(core::marker::PhantomData<&#lifetime ()>)
|
||||
quote!(::core::marker::PhantomData<&#lifetime ()>)
|
||||
}
|
||||
syn::GenericParam::Type(ty) => {
|
||||
let ty = &ty.ident;
|
||||
quote!(core::marker::PhantomData<#ty>)
|
||||
quote!(::core::marker::PhantomData<#ty>)
|
||||
}
|
||||
syn::GenericParam::Const(_cnst) => {
|
||||
quote!()
|
||||
@@ -634,7 +637,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
||||
#vis fn builder() -> #builder_name #generics_with_empty {
|
||||
#builder_name {
|
||||
fields: #empties_tuple,
|
||||
_phantom: core::default::Default::default(),
|
||||
_phantom: ::core::default::Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -651,12 +654,12 @@ Finally, call `.build()` to create the instance of `{name}`.
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
fields: self.fields.clone(),
|
||||
_phantom: Default::default(),
|
||||
_phantom: ::core::default::Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl #impl_generics dioxus::prelude::Properties for #name #ty_generics
|
||||
impl #impl_generics ::dioxus::prelude::Properties for #name #ty_generics
|
||||
#b_generics_where_extras_predicates
|
||||
{
|
||||
type Builder = #builder_name #generics_with_empty;
|
||||
@@ -793,7 +796,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
||||
};
|
||||
let (arg_type, arg_expr) = if field.builder_attr.auto_into {
|
||||
(
|
||||
quote!(impl core::convert::Into<#arg_type>),
|
||||
quote!(impl ::core::convert::Into<#arg_type>),
|
||||
quote!(#field_name.into()),
|
||||
)
|
||||
} else {
|
||||
@@ -811,7 +814,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
||||
builder_name,
|
||||
strip_raw_ident_prefix(field_name.to_string())
|
||||
),
|
||||
proc_macro2::Span::call_site(),
|
||||
builder_name.span(),
|
||||
);
|
||||
let repeated_fields_error_message = format!("Repeated field {field_name}");
|
||||
|
||||
@@ -930,7 +933,7 @@ Finally, call `.build()` to create the instance of `{name}`.
|
||||
builder_name,
|
||||
strip_raw_ident_prefix(field_name.to_string())
|
||||
),
|
||||
proc_macro2::Span::call_site(),
|
||||
builder_name.span(),
|
||||
);
|
||||
let early_build_error_message = format!("Missing required field {field_name}");
|
||||
|
||||
|
||||
Reference in new issue
Block a user