diff --git a/src/base/action/component.rs b/src/base/action/component.rs index 22c56e0a..03eedf26 100644 --- a/src/base/action/component.rs +++ b/src/base/action/component.rs @@ -1,3 +1,6 @@ +mod is_renderable; +pub use is_renderable::*; + mod before_prepare_component; pub use before_prepare_component::*; diff --git a/src/base/action/component/after_prepare_component.rs b/src/base/action/component/after_prepare_component.rs index 033ec8ff..150669b1 100644 --- a/src/base/action/component/after_prepare_component.rs +++ b/src/base/action/component/after_prepare_component.rs @@ -49,10 +49,6 @@ impl AfterPrepare { ActionKey::new(TypeId::of::(), None, Some(TypeId::of::()), None), |action: &Self| (action.f)(component, cx), ); - } - - #[inline(always)] - pub(crate) fn dispatch_by_id(component: &mut C, cx: &mut Context) { if component.id().is_some() { dispatch_actions( ActionKey::new( diff --git a/src/base/action/component/before_prepare_component.rs b/src/base/action/component/before_prepare_component.rs index 3d1a164d..75421129 100644 --- a/src/base/action/component/before_prepare_component.rs +++ b/src/base/action/component/before_prepare_component.rs @@ -49,10 +49,6 @@ impl BeforePrepare { ActionKey::new(TypeId::of::(), None, Some(TypeId::of::()), None), |action: &Self| (action.f)(component, cx), ); - } - - #[inline(always)] - pub(crate) fn dispatch_by_id(component: &mut C, cx: &mut Context) { if component.id().is_some() { dispatch_actions( ActionKey::new( diff --git a/src/base/action/component/is_renderable.rs b/src/base/action/component/is_renderable.rs new file mode 100644 index 00000000..998421fd --- /dev/null +++ b/src/base/action/component/is_renderable.rs @@ -0,0 +1,74 @@ +use crate::prelude::*; + +pub type FnIsRenderable = fn(component: &C, cx: &mut Context) -> bool; + +pub struct IsRenderable { + f: FnIsRenderable, + referer_type_id: Option, + referer_id: OptionId, + weight: Weight, +} + +impl ActionTrait for IsRenderable { + fn referer_type_id(&self) -> Option { + self.referer_type_id + } + + fn referer_id(&self) -> Option { + self.referer_id.get() + } + + fn weight(&self) -> Weight { + self.weight + } +} + +impl IsRenderable { + pub fn new(f: FnIsRenderable) -> Self { + IsRenderable { + f, + referer_type_id: Some(TypeId::of::()), + referer_id: OptionId::default(), + weight: 0, + } + } + + pub fn filter_by_referer_id(mut self, id: impl Into) -> Self { + self.referer_id.alter_value(id); + self + } + + pub fn with_weight(mut self, value: Weight) -> Self { + self.weight = value; + self + } + + #[inline(always)] + pub(crate) fn dispatch(component: &C, cx: &mut Context) -> bool { + let mut renderable = true; + dispatch_actions( + ActionKey::new(TypeId::of::(), None, Some(TypeId::of::()), None), + |action: &Self| { + if renderable && !(action.f)(component, cx) { + renderable = false; + } + }, + ); + if renderable && component.id().is_some() { + dispatch_actions( + ActionKey::new( + TypeId::of::(), + None, + Some(TypeId::of::()), + component.id(), + ), + |action: &Self| { + if renderable && !(action.f)(component, cx) { + renderable = false; + } + }, + ); + } + renderable + } +} diff --git a/src/base/component/block.rs b/src/base/component/block.rs index f10ee3b7..dbd76eb8 100644 --- a/src/base/component/block.rs +++ b/src/base/component/block.rs @@ -3,12 +3,11 @@ use crate::prelude::*; #[rustfmt::skip] #[derive(AutoDefault, ComponentClasses)] pub struct Block { - id : OptionId, - renderable: Renderable, - classes : OptionClasses, - style : StyleBase, - title : OptionTranslated, - mixed : MixedComponents, + id : OptionId, + classes: OptionClasses, + style : StyleBase, + title : OptionTranslated, + mixed : MixedComponents, } impl ComponentTrait for Block { @@ -20,10 +19,6 @@ impl ComponentTrait for Block { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn setup_before_prepare(&mut self, _cx: &mut Context) { self.alter_classes( ClassesOp::Prepend, @@ -60,12 +55,6 @@ impl Block { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_style(&mut self, style: StyleBase) -> &mut Self { self.style = style; diff --git a/src/base/component/branding.rs b/src/base/component/branding.rs index b2768234..84a563ad 100644 --- a/src/base/component/branding.rs +++ b/src/base/component/branding.rs @@ -3,14 +3,13 @@ use crate::prelude::*; #[rustfmt::skip] #[derive(AutoDefault)] pub struct Branding { - id : OptionId, - renderable: Renderable, + id : OptionId, #[default(_code = "config::SETTINGS.app.name.to_owned()")] - app_name : String, - slogan : OptionTranslated, - logo : OptionComponent, + app_name : String, + slogan : OptionTranslated, + logo : OptionComponent, #[default(_code = "|_| \"/\"")] - frontpage : FnContextualPath, + frontpage: FnContextualPath, } impl ComponentTrait for Branding { @@ -22,10 +21,6 @@ impl ComponentTrait for Branding { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { let logo = self.logo().render(cx); let home = self.frontpage()(cx); @@ -63,12 +58,6 @@ impl Branding { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_app_name(&mut self, app_name: impl Into) -> &mut Self { self.app_name = app_name.into(); diff --git a/src/base/component/button.rs b/src/base/component/button.rs index 50107635..865a583f 100644 --- a/src/base/component/button.rs +++ b/src/base/component/button.rs @@ -13,16 +13,15 @@ pub enum ButtonTarget { #[rustfmt::skip] #[derive(AutoDefault, ComponentClasses)] pub struct Button { - id : OptionId, - renderable : Renderable, - classes : OptionClasses, - style : StyleBase, - font_size : FontSize, - left_icon : OptionComponent, - right_icon : OptionComponent, - href : OptionString, - html : OptionTranslated, - target : ButtonTarget, + id : OptionId, + classes : OptionClasses, + style : StyleBase, + font_size : FontSize, + left_icon : OptionComponent, + right_icon: OptionComponent, + href : OptionString, + html : OptionTranslated, + target : ButtonTarget, } impl ComponentTrait for Button { @@ -34,10 +33,6 @@ impl ComponentTrait for Button { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn setup_before_prepare(&mut self, _cx: &mut Context) { self.alter_classes( ClassesOp::Prepend, @@ -87,12 +82,6 @@ impl Button { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_style(&mut self, style: StyleBase) -> &mut Self { self.style = style; diff --git a/src/base/component/flex/container.rs b/src/base/component/flex/container.rs index cfb5be3a..46a0b696 100644 --- a/src/base/component/flex/container.rs +++ b/src/base/component/flex/container.rs @@ -15,7 +15,6 @@ pub enum ContainerType { #[derive(AutoDefault, ComponentClasses)] pub struct Container { id : OptionId, - renderable : Renderable, classes : OptionClasses, container_type: ContainerType, direction : flex::Direction, @@ -35,10 +34,6 @@ impl ComponentTrait for Container { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn setup_before_prepare(&mut self, cx: &mut Context) { self.alter_classes( ClassesOp::Prepend, @@ -144,12 +139,6 @@ impl Container { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_direction(&mut self, direction: flex::Direction) -> &mut Self { self.direction = direction; diff --git a/src/base/component/flex/item.rs b/src/base/component/flex/item.rs index 03fe1219..680ab2e8 100644 --- a/src/base/component/flex/item.rs +++ b/src/base/component/flex/item.rs @@ -13,7 +13,6 @@ pub enum ItemType { #[derive(AutoDefault, ComponentClasses)] pub struct Item { id : OptionId, - renderable : Renderable, classes : OptionClasses, item_type : ItemType, flex_grow : flex::Grow, @@ -33,10 +32,6 @@ impl ComponentTrait for Item { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn setup_before_prepare(&mut self, _cx: &mut Context) { self.alter_classes( ClassesOp::Prepend, @@ -129,12 +124,6 @@ impl Item { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_grow(&mut self, grow: flex::Grow) -> &mut Self { self.flex_grow = grow; diff --git a/src/base/component/form/action_button.rs b/src/base/component/form/action_button.rs index 66259653..72a75554 100644 --- a/src/base/component/form/action_button.rs +++ b/src/base/component/form/action_button.rs @@ -20,7 +20,6 @@ impl ToString for ActionButtonType { #[rustfmt::skip] #[derive(AutoDefault, ComponentClasses)] pub struct ActionButton { - renderable : Renderable, classes : OptionClasses, button_type: ActionButtonType, style : StyleBase, @@ -38,10 +37,6 @@ impl ComponentTrait for ActionButton { ActionButton::submit() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn setup_before_prepare(&mut self, _cx: &mut Context) { self.alter_classes( ClassesOp::Prepend, @@ -95,12 +90,6 @@ impl ActionButton { // Button BUILDER. - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_style(&mut self, style: StyleBase) -> &mut Self { self.style = style; diff --git a/src/base/component/form/date.rs b/src/base/component/form/date.rs index cad18284..21377824 100644 --- a/src/base/component/form/date.rs +++ b/src/base/component/form/date.rs @@ -3,7 +3,6 @@ use crate::prelude::*; #[rustfmt::skip] #[derive(AutoDefault, ComponentClasses)] pub struct Date { - renderable : Renderable, classes : OptionClasses, name : OptionString, value : OptionString, @@ -22,10 +21,6 @@ impl ComponentTrait for Date { Date::default().with_classes(ClassesOp::Add, "form-item form-type-date") } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup { let id = self.name().get().map(|name| concat_string!("edit-", name)); PrepareMarkup::With(html! { @@ -63,12 +58,6 @@ impl ComponentTrait for Date { impl Date { // Date BUILDER. - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_name(&mut self, name: &str) -> &mut Self { self.name.alter_value(name); diff --git a/src/base/component/form/form_main.rs b/src/base/component/form/form_main.rs index 9c68cd8e..39577060 100644 --- a/src/base/component/form/form_main.rs +++ b/src/base/component/form/form_main.rs @@ -10,13 +10,12 @@ pub enum FormMethod { #[rustfmt::skip] #[derive(AutoDefault, ComponentClasses)] pub struct Form { - id : OptionId, - renderable: Renderable, - classes : OptionClasses, - action : OptionString, - charset : OptionString, - method : FormMethod, - mixed : MixedComponents, + id : OptionId, + classes: OptionClasses, + action : OptionString, + charset: OptionString, + method : FormMethod, + mixed : MixedComponents, } impl ComponentTrait for Form { @@ -30,10 +29,6 @@ impl ComponentTrait for Form { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { let method = match self.method() { FormMethod::Post => Some("post".to_owned()), @@ -62,12 +57,6 @@ impl Form { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_action(&mut self, action: &str) -> &mut Self { self.action.alter_value(action); diff --git a/src/base/component/form/input.rs b/src/base/component/form/input.rs index 2bef941c..4673f70a 100644 --- a/src/base/component/form/input.rs +++ b/src/base/component/form/input.rs @@ -14,7 +14,6 @@ pub enum InputType { #[rustfmt::skip] #[derive(AutoDefault, ComponentClasses)] pub struct Input { - renderable : Renderable, classes : OptionClasses, input_type : InputType, name : OptionName, @@ -40,10 +39,6 @@ impl ComponentTrait for Input { .with_maxlength(Some(128)) } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - #[rustfmt::skip] fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { let type_input = match self.input_type() { @@ -142,12 +137,6 @@ impl Input { // Input BUILDER. - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_name(&mut self, name: &str) -> &mut Self { if let Some(previous) = self.name.get() { diff --git a/src/base/component/heading.rs b/src/base/component/heading.rs index db5307c1..d620f8e9 100644 --- a/src/base/component/heading.rs +++ b/src/base/component/heading.rs @@ -42,7 +42,6 @@ impl ToString for HeadingSize { #[derive(AutoDefault, ComponentClasses)] pub struct Heading { id : OptionId, - renderable : Renderable, classes : OptionClasses, heading_type: HeadingType, size : HeadingSize, @@ -58,10 +57,6 @@ impl ComponentTrait for Heading { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn setup_before_prepare(&mut self, _cx: &mut Context) { self.alter_classes(ClassesOp::Add, self.size().to_string()); } @@ -126,12 +121,6 @@ impl Heading { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_heading_type(&mut self, heading_type: HeadingType) -> &mut Self { self.heading_type = heading_type; diff --git a/src/base/component/icon.rs b/src/base/component/icon.rs index e4d16050..a8c62ce2 100644 --- a/src/base/component/icon.rs +++ b/src/base/component/icon.rs @@ -3,10 +3,9 @@ use crate::prelude::*; #[rustfmt::skip] #[derive(AutoDefault, ComponentClasses)] pub struct Icon { - renderable: Renderable, - classes : OptionClasses, - icon_name : OptionString, - font_size : FontSize, + classes : OptionClasses, + icon_name: OptionString, + font_size: FontSize, } impl ComponentTrait for Icon { @@ -14,10 +13,6 @@ impl ComponentTrait for Icon { Icon::default() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - #[rustfmt::skip] fn setup_before_prepare(&mut self, cx: &mut Context) { if let Some(icon_name) = self.icon_name().get() { @@ -43,12 +38,6 @@ impl Icon { // Icon BUILDER. - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_icon_name(&mut self, name: impl Into) -> &mut Self { self.icon_name.alter_value(name); diff --git a/src/base/component/image.rs b/src/base/component/image.rs index bf4c0dfd..0a412ea1 100644 --- a/src/base/component/image.rs +++ b/src/base/component/image.rs @@ -16,11 +16,10 @@ pub enum ImageSize { #[rustfmt::skip] #[derive(AutoDefault, ComponentClasses)] pub struct Image { - id : OptionId, - renderable: Renderable, - classes : OptionClasses, - source : OptionString, - size : ImageSize, + id : OptionId, + classes: OptionClasses, + source : OptionString, + size : ImageSize, } impl ComponentTrait for Image { @@ -32,10 +31,6 @@ impl ComponentTrait for Image { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup { let (width, height) = match self.size() { ImageSize::Auto => (None, None), @@ -83,12 +78,6 @@ impl Image { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_source(&mut self, source: &str) -> &mut Self { self.source.alter_value(source); diff --git a/src/base/component/menu/element.rs b/src/base/component/menu/element.rs index adc1450b..5c39f7ea 100644 --- a/src/base/component/menu/element.rs +++ b/src/base/component/menu/element.rs @@ -18,7 +18,6 @@ pub enum ElementType { #[rustfmt::skip] #[derive(AutoDefault)] pub struct Element { - renderable : Renderable, element_type: ElementType, } @@ -27,10 +26,6 @@ impl ComponentTrait for Element { Element::default() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { match self.element_type() { ElementType::Void => PrepareMarkup::None, @@ -48,25 +43,15 @@ impl Element { pub fn html(content: Html) -> Self { Element { element_type: ElementType::Html(Content::with(content)), - ..Default::default() } } pub fn submenu(submenu: Submenu) -> Self { Element { element_type: ElementType::Submenu(SubmenuItems::with(submenu)), - ..Default::default() } } - // Element BUILDER. - - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - // Element GETTERS. pub fn element_type(&self) -> &ElementType { diff --git a/src/base/component/menu/group.rs b/src/base/component/menu/group.rs index fc1d53c6..fecb76da 100644 --- a/src/base/component/menu/group.rs +++ b/src/base/component/menu/group.rs @@ -5,9 +5,8 @@ use super::Element; #[rustfmt::skip] #[derive(AutoDefault)] pub struct Group { - id : OptionId, - renderable: Renderable, - elements : MixedComponents, + id : OptionId, + elements: MixedComponents, } impl ComponentTrait for Group { @@ -19,10 +18,6 @@ impl ComponentTrait for Group { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { PrepareMarkup::With(html! { div id=[self.id()] class="menu-group" { @@ -41,12 +36,6 @@ impl Group { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_elements(&mut self, op: TypedOp) -> &mut Self { self.elements.alter_typed(op); diff --git a/src/base/component/menu/item.rs b/src/base/component/menu/item.rs index 75280cae..fd77f728 100644 --- a/src/base/component/menu/item.rs +++ b/src/base/component/menu/item.rs @@ -24,7 +24,6 @@ pub enum ItemType { #[rustfmt::skip] #[derive(AutoDefault)] pub struct Item { - renderable : Renderable, item_type : ItemType, description: OptionTranslated, left_icon : OptionComponent, @@ -36,10 +35,6 @@ impl ComponentTrait for Item { Item::default() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { let description = self.description.using(cx.langid()); @@ -151,12 +146,6 @@ impl Item { // Item BUILDER. - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_description(&mut self, text: L10n) -> &mut Self { self.description.alter_value(text); diff --git a/src/base/component/menu/megamenu.rs b/src/base/component/menu/megamenu.rs index 0f7cacec..91b8e1be 100644 --- a/src/base/component/menu/megamenu.rs +++ b/src/base/component/menu/megamenu.rs @@ -5,9 +5,8 @@ use super::Group; #[rustfmt::skip] #[derive(AutoDefault)] pub struct Megamenu { - id : OptionId, - renderable: Renderable, - groups : MixedComponents, + id : OptionId, + groups: MixedComponents, } impl ComponentTrait for Megamenu { @@ -19,10 +18,6 @@ impl ComponentTrait for Megamenu { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { PrepareMarkup::With(html! { div id=[self.id()] class="menu__groups" { @@ -41,12 +36,6 @@ impl Megamenu { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_groups(&mut self, op: TypedOp) -> &mut Self { self.groups.alter_typed(op); diff --git a/src/base/component/menu/menu_main.rs b/src/base/component/menu/menu_main.rs index 47caa503..db5babb4 100644 --- a/src/base/component/menu/menu_main.rs +++ b/src/base/component/menu/menu_main.rs @@ -5,9 +5,8 @@ use super::Item; #[rustfmt::skip] #[derive(AutoDefault)] pub struct Menu { - id : OptionId, - renderable: Renderable, - items : MixedComponents, + id : OptionId, + items: MixedComponents, } impl ComponentTrait for Menu { @@ -19,10 +18,6 @@ impl ComponentTrait for Menu { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { cx.set_param::(PARAM_BASE_INCLUDE_MENU_ASSETS, true); cx.set_param::(PARAM_BASE_INCLUDE_ICONS, true); @@ -69,12 +64,6 @@ impl Menu { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_items(&mut self, op: TypedOp) -> &mut Self { self.items.alter_typed(op); diff --git a/src/base/component/menu/submenu.rs b/src/base/component/menu/submenu.rs index 48feaff3..38b5aa08 100644 --- a/src/base/component/menu/submenu.rs +++ b/src/base/component/menu/submenu.rs @@ -5,10 +5,9 @@ use super::Item; #[rustfmt::skip] #[derive(AutoDefault)] pub struct Submenu { - id : OptionId, - renderable: Renderable, - title : OptionTranslated, - items : MixedComponents, + id : OptionId, + title: OptionTranslated, + items: MixedComponents, } impl ComponentTrait for Submenu { @@ -20,10 +19,6 @@ impl ComponentTrait for Submenu { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { PrepareMarkup::With(html! { div id=[self.id()] class="menu__items" { @@ -47,12 +42,6 @@ impl Submenu { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_title(&mut self, title: L10n) -> &mut Self { self.title.alter_value(title); diff --git a/src/base/component/paragraph.rs b/src/base/component/paragraph.rs index c6d70eba..269383d9 100644 --- a/src/base/component/paragraph.rs +++ b/src/base/component/paragraph.rs @@ -3,11 +3,10 @@ use crate::prelude::*; #[rustfmt::skip] #[derive(AutoDefault, ComponentClasses)] pub struct Paragraph { - id : OptionId, - renderable: Renderable, - classes : OptionClasses, - font_size : FontSize, - mixed : MixedComponents, + id : OptionId, + classes : OptionClasses, + font_size: FontSize, + mixed : MixedComponents, } impl ComponentTrait for Paragraph { @@ -19,10 +18,6 @@ impl ComponentTrait for Paragraph { self.id.get() } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn setup_before_prepare(&mut self, _cx: &mut Context) { self.alter_classes(ClassesOp::Prepend, self.font_size().to_string()); } @@ -56,12 +51,6 @@ impl Paragraph { self } - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_font_size(&mut self, font_size: FontSize) -> &mut Self { self.font_size = font_size; diff --git a/src/base/component/powered_by.rs b/src/base/component/powered_by.rs index 8fccb29d..47449191 100644 --- a/src/base/component/powered_by.rs +++ b/src/base/component/powered_by.rs @@ -13,9 +13,8 @@ pub enum PoweredByLogo { #[rustfmt::skip] #[derive(AutoDefault)] pub struct PoweredBy { - renderable: Renderable, - copyright : Option, - logo : PoweredByLogo, + copyright: Option, + logo : PoweredByLogo, } impl ComponentTrait for PoweredBy { @@ -28,10 +27,6 @@ impl ComponentTrait for PoweredBy { } } - fn is_renderable(&self, cx: &Context) -> bool { - (self.renderable.check)(cx) - } - fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { let poweredby_pagetop = L10n::l("poweredby_pagetop") .with_arg( @@ -62,12 +57,6 @@ impl ComponentTrait for PoweredBy { impl PoweredBy { // PoweredBy BUILDER. - #[fn_builder] - pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self { - self.renderable.check = check; - self - } - #[fn_builder] pub fn alter_copyright(&mut self, copyright: Option>) -> &mut Self { self.copyright = copyright.map(|c| c.into()); diff --git a/src/core/component.rs b/src/core/component.rs index b17770fb..b6650981 100644 --- a/src/core/component.rs +++ b/src/core/component.rs @@ -2,9 +2,6 @@ mod context; pub use context::{AssetsOp, Context}; pub type FnContextualPath = fn(cx: &Context) -> &str; -mod renderable; -pub use renderable::{FnIsRenderable, Renderable}; - mod definition; pub use definition::{ComponentBase, ComponentTrait}; diff --git a/src/core/component/definition.rs b/src/core/component/definition.rs index 2270b80f..80a40a09 100644 --- a/src/core/component/definition.rs +++ b/src/core/component/definition.rs @@ -25,11 +25,6 @@ pub trait ComponentTrait: AnyBase + ComponentBase + Send + Sync { None } - #[allow(unused_variables)] - fn is_renderable(&self, cx: &Context) -> bool { - true - } - #[allow(unused_variables)] fn setup_before_prepare(&mut self, cx: &mut Context) {} @@ -41,7 +36,7 @@ pub trait ComponentTrait: AnyBase + ComponentBase + Send + Sync { impl ComponentBase for C { fn render(&mut self, cx: &mut Context) -> Markup { - if self.is_renderable(cx) { + if action::component::IsRenderable::dispatch(self, cx) { // Comprueba el componente antes de prepararlo. self.setup_before_prepare(cx); @@ -50,7 +45,6 @@ impl ComponentBase for C { // Acciones de los módulos antes de preparar el componente. action::component::BeforePrepare::dispatch(self, cx); - action::component::BeforePrepare::dispatch_by_id(self, cx); // Renderiza el componente. let markup = match action::theme::RenderComponent::dispatch(self, cx) { @@ -67,7 +61,6 @@ impl ComponentBase for C { // Acciones de los módulos después de preparar el componente. action::component::AfterPrepare::dispatch(self, cx); - action::component::AfterPrepare::dispatch_by_id(self, cx); markup } else { diff --git a/src/core/component/renderable.rs b/src/core/component/renderable.rs deleted file mode 100644 index 2f0055ce..00000000 --- a/src/core/component/renderable.rs +++ /dev/null @@ -1,14 +0,0 @@ -use crate::core::component::Context; -use crate::AutoDefault; - -pub type FnIsRenderable = fn(cx: &Context) -> bool; - -#[derive(AutoDefault)] -pub struct Renderable { - #[default(_code = "render_always")] - pub check: FnIsRenderable, -} - -fn render_always(_cx: &Context) -> bool { - true -}