🏗️ Use actions to decide component rendering

This commit is contained in:
Manuel Cillero 2024-04-15 02:06:39 +02:00
parent 45cb063e52
commit 7d4cf642ff
27 changed files with 125 additions and 304 deletions

View file

@ -1,3 +1,6 @@
mod is_renderable;
pub use is_renderable::*;
mod before_prepare_component;
pub use before_prepare_component::*;

View file

@ -49,10 +49,6 @@ impl<C: ComponentTrait> AfterPrepare<C> {
ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), 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(

View file

@ -49,10 +49,6 @@ impl<C: ComponentTrait> BeforePrepare<C> {
ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), 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(

View file

@ -0,0 +1,74 @@
use crate::prelude::*;
pub type FnIsRenderable<C> = fn(component: &C, cx: &mut Context) -> bool;
pub struct IsRenderable<C: ComponentTrait> {
f: FnIsRenderable<C>,
referer_type_id: Option<TypeId>,
referer_id: OptionId,
weight: Weight,
}
impl<C: ComponentTrait> ActionTrait for IsRenderable<C> {
fn referer_type_id(&self) -> Option<TypeId> {
self.referer_type_id
}
fn referer_id(&self) -> Option<String> {
self.referer_id.get()
}
fn weight(&self) -> Weight {
self.weight
}
}
impl<C: ComponentTrait> IsRenderable<C> {
pub fn new(f: FnIsRenderable<C>) -> Self {
IsRenderable {
f,
referer_type_id: Some(TypeId::of::<C>()),
referer_id: OptionId::default(),
weight: 0,
}
}
pub fn filter_by_referer_id(mut self, id: impl Into<String>) -> 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::<Self>(), None, Some(TypeId::of::<C>()), None),
|action: &Self| {
if renderable && !(action.f)(component, cx) {
renderable = false;
}
},
);
if renderable && component.id().is_some() {
dispatch_actions(
ActionKey::new(
TypeId::of::<Self>(),
None,
Some(TypeId::of::<C>()),
component.id(),
),
|action: &Self| {
if renderable && !(action.f)(component, cx) {
renderable = false;
}
},
);
}
renderable
}
}

View file

@ -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;

View file

@ -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<Image>,
app_name : String,
slogan : OptionTranslated,
logo : OptionComponent<Image>,
#[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<String>) -> &mut Self {
self.app_name = app_name.into();

View file

@ -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<Icon>,
right_icon : OptionComponent<Icon>,
href : OptionString,
html : OptionTranslated,
target : ButtonTarget,
id : OptionId,
classes : OptionClasses,
style : StyleBase,
font_size : FontSize,
left_icon : OptionComponent<Icon>,
right_icon: OptionComponent<Icon>,
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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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() {

View file

@ -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;

View file

@ -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<String>) -> &mut Self {
self.icon_name.alter_value(name);

View file

@ -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);

View file

@ -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 {

View file

@ -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<Element>) -> &mut Self {
self.elements.alter_typed(op);

View file

@ -24,7 +24,6 @@ pub enum ItemType {
#[rustfmt::skip]
#[derive(AutoDefault)]
pub struct Item {
renderable : Renderable,
item_type : ItemType,
description: OptionTranslated,
left_icon : OptionComponent<Icon>,
@ -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);

View file

@ -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<Group>) -> &mut Self {
self.groups.alter_typed(op);

View file

@ -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::<bool>(PARAM_BASE_INCLUDE_MENU_ASSETS, true);
cx.set_param::<bool>(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<Item>) -> &mut Self {
self.items.alter_typed(op);

View file

@ -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);

View file

@ -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;

View file

@ -13,9 +13,8 @@ pub enum PoweredByLogo {
#[rustfmt::skip]
#[derive(AutoDefault)]
pub struct PoweredBy {
renderable: Renderable,
copyright : Option<String>,
logo : PoweredByLogo,
copyright: Option<String>,
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<impl Into<String>>) -> &mut Self {
self.copyright = copyright.map(|c| c.into());

View file

@ -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};

View file

@ -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<C: ComponentTrait> 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<C: ComponentTrait> 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<C: ComponentTrait> 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 {

View file

@ -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
}