mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
This commit is contained in:
parent
cc32a3e863
commit
d44b90c16d
2 changed files with 31 additions and 3 deletions
|
@ -28,7 +28,7 @@ pub fn TestComponent(
|
|||
/// # use example::TestComponent;
|
||||
/// <TestComponent key="hello"/>
|
||||
#[prop(optional)]
|
||||
another:usize,
|
||||
another: usize,
|
||||
/// rust unclosed
|
||||
/// ```view
|
||||
/// use example::TestComponent;
|
||||
|
@ -38,3 +38,22 @@ pub fn TestComponent(
|
|||
_ = (key, another, and_another);
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn TestMutCallback<'a, F>(
|
||||
cx: Scope,
|
||||
mut callback: F,
|
||||
value: &'a str,
|
||||
) -> impl IntoView
|
||||
where
|
||||
F: FnMut(u32) + 'static,
|
||||
{
|
||||
let value = value.to_owned();
|
||||
view! { cx,
|
||||
<button on:click=move |_| {
|
||||
callback(5);
|
||||
}>
|
||||
{value}
|
||||
</button>
|
||||
<TestComponent key="test"/>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,6 +284,8 @@ impl ToTokens for Model {
|
|||
) #ret #(+ #lifetimes)*
|
||||
#where_clause
|
||||
{
|
||||
// allowed for lifetimes that are needed for props struct
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
#body
|
||||
|
||||
#destructure_props
|
||||
|
@ -589,12 +591,14 @@ fn prop_builder_fields(vis: &Visibility, props: &[Prop]) -> TokenStream {
|
|||
quote!()
|
||||
};
|
||||
|
||||
let PatIdent { ident, by_ref, .. } = &name;
|
||||
|
||||
quote! {
|
||||
#docs
|
||||
#builder_docs
|
||||
#builder_attrs
|
||||
#allow_missing_docs
|
||||
#vis #name: #ty,
|
||||
#vis #by_ref #ident: #ty,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
|
@ -604,7 +608,12 @@ fn prop_names(props: &[Prop]) -> TokenStream {
|
|||
props
|
||||
.iter()
|
||||
.filter(|Prop { ty, .. }| !is_valid_scope_type(ty))
|
||||
.map(|Prop { name, .. }| quote! { #name, })
|
||||
.map(|Prop { name, .. }| {
|
||||
// fields like mutability are removed because unneeded
|
||||
// in the contexts in which this is used
|
||||
let ident = &name.ident;
|
||||
quote! { #ident, }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue