Skip to content
Snippets Groups Projects
Commit 2b2bc436 authored by MrGVSV's avatar MrGVSV
Browse files

Removed unneeded code

parent 289059e2
No related branches found
No related tags found
No related merge requests found
...@@ -63,139 +63,6 @@ pub fn create_function_widget(f: syn::ItemFn, _widget_arguments: WidgetArguments ...@@ -63,139 +63,6 @@ pub fn create_function_widget(f: syn::ItemFn, _widget_arguments: WidgetArguments
let kayak_core = get_core_crate(); let kayak_core = get_core_crate();
// TODO: See if this is still needed. If not, remove it
// let mut input_names: Vec<_> = inputs
// .iter()
// .filter_map(|argument| match argument {
// syn::FnArg::Typed(typed) => {
// let typed_info = typed.ty.to_token_stream().to_string();
// let attr_info = typed.pat.to_token_stream().to_string();
// if (typed_info.contains("KayakContext") && !typed_info.contains("Fn"))
// || (attr_info.contains("styles") && typed_info.contains("Style"))
// {
// None
// } else {
// Some(typed)
// }
// }
// syn::FnArg::Receiver(rec) => {
// emit_error!(rec.span(), "Don't use `self` on widgets");
// None
// }
// })
// .map(|value| {
// let pat = &value.pat;
// quote!(#pat)
// })
// .collect();
//
// let mut input_block_names: Vec<_> = inputs
// .iter()
// .filter(|input| {
// let input = (quote! { #input }).to_string();
// !(input.contains("parent_styles")
// || (input.contains("KayakContext") && !input.contains("Fn")))
// })
// .map(|item| quote! { #item })
// .collect();
// input_block_names.iter_mut().for_each(|input| {
// let input_string = (quote! { #input }).to_string();
// if input_string.contains("children : Children") {
// *input = quote! {
// #[derivative(Debug = "ignore", PartialEq = "ignore")]
// pub children: Children
// };
// } else if input_string.contains("on_event : Option < OnEvent >") {
// *input = quote! {
// #[derivative(Debug = "ignore", PartialEq = "ignore")]
// pub on_event: Option<#kayak_core::OnEvent>
// };
// } else {
// *input = quote! {
// pub #input
// }
// }
// });
// let focusable_default = if widget_arguments.focusable {
// "Some(true)"
// } else {
// "None"
// };
//
// let missing_struct_inputs = vec![
// (
// vec![
// "styles : Option < Style >",
// "styles : Option< kayak_ui :: core :: styles :: Style >",
// ],
// quote! {
// #[derivative(Default(value="None"))]
// pub styles: Option<#kayak_core::styles::Style>
// },
// ),
// (
// vec!["children : Children"],
// quote! {
// #[derivative(Default(value="None"), Debug = "ignore", PartialEq = "ignore")]
// pub children: #kayak_core::Children
// },
// ),
// (
// vec![
// "on_event : Option < OnEvent >",
// "on_event : Option < kayak_ui :: core :: OnEvent >",
// "on_event : Option <\nkayak_ui :: core :: OnEvent >",
// ],
// quote! {
// #[derivative(Default(value="None"), Debug = "ignore", PartialEq = "ignore")]
// pub on_event: Option<#kayak_core::OnEvent>
// },
// ),
// (
// vec!["focusable : Option < bool >"],
// quote! {
// #[derivative(Default(value=#focusable_default))]
// pub focusable: Option<bool>
// },
// ),
// ];
// for (names, token) in missing_struct_inputs {
// if !input_block_names.iter().any(|block_name| {
// names
// .iter()
// .any(|name| block_name.to_string().contains(name))
// }) {
// input_block_names.push(token);
// } else {
// }
// }
// let inputs_block = quote!(
// #(#input_block_names),*
// );
//
// if !input_names
// .iter()
// .any(|item_name| item_name.to_string().contains("children"))
// {
// input_names.push(quote! {
// children
// });
// }
// let inputs_reading_ref = if inputs.len() == 0 {
// quote! {
// let #struct_name { children, styles, .. } = self;
// }
// } else {
// quote!(
// let #struct_name { #(#input_names),*, styles, .. } = self;
// #(let #input_names = #input_names.clone();)*
// )
// };
TokenStream::from(quote! { TokenStream::from(quote! {
#[derive(Default, Debug, PartialEq, Clone)] #[derive(Default, Debug, PartialEq, Clone)]
#vis struct #struct_name #impl_generics { #vis struct #struct_name #impl_generics {
......
use proc_macro2::{Ident, TokenStream}; use proc_macro2::{Ident, TokenStream};
use proc_macro_error::emit_error; use proc_macro_error::emit_error;
use quote::{quote, ToTokens}; use quote::quote;
use std::collections::HashSet; use std::collections::HashSet;
use syn::{ use syn::{
ext::IdentExt, ext::IdentExt,
...@@ -70,64 +70,6 @@ pub struct CustomWidgetAttributes<'a, 'c> { ...@@ -70,64 +70,6 @@ pub struct CustomWidgetAttributes<'a, 'c> {
children: &'c Children, children: &'c Children,
} }
// TODO: This impl may not be needed anymore. If so, it should be removed
impl<'a, 'c> ToTokens for CustomWidgetAttributes<'a, 'c> {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
let mut attrs: Vec<_> = self
.attributes
.iter()
.map(|attribute| {
let ident = attribute.ident();
let value = attribute.value_tokens();
quote! {
#ident: #value
}
})
.collect();
{
let children_tuple = self.children.as_option_of_tuples_tokens();
attrs.push(quote! {
children: #children_tuple
});
}
// let missing = vec![
// ("styles", quote! { styles: None }),
// ("on_event", quote! { on_event: None }),
// ];
//
// for missed in missing {
// if !self.attributes.iter().any(|attribute| {
// attribute
// .ident()
// .to_token_stream()
// .to_string()
// .contains(missed.0)
// }) {
// attrs.push(missed.1);
// }
// }
let quoted = if attrs.len() == 0 {
quote!({ ..Default::default() })
} else {
if !self
.attributes
.iter()
.any(|attribute| attribute.ident().to_token_stream().to_string() == "styles")
{
quote!({ #(#attrs),*, ..Default::default() })
} else {
quote!({ #(#attrs),*, ..Default::default() })
}
};
quoted.to_tokens(tokens);
}
}
impl<'a, 'c> CustomWidgetAttributes<'a, 'c> { impl<'a, 'c> CustomWidgetAttributes<'a, 'c> {
/// Assign this widget's attributes to the given ident /// Assign this widget's attributes to the given ident
/// ///
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment