🏗️ Use actions to decide component rendering
This commit is contained in:
parent
45cb063e52
commit
7d4cf642ff
27 changed files with 125 additions and 304 deletions
|
|
@ -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};
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue