From a48c57519860c52531a77340b5dc7f38e7106e7a Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Fri, 9 Jun 2023 11:11:50 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Handles=20siempre=20requeridos?= =?UTF-8?q?=20en=20la=20implementaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/hello-world/src/main.rs | 8 +++++++- pagetop/src/core/action.rs | 2 +- pagetop/src/core/action/definition.rs | 8 ++------ pagetop/src/core/component.rs | 4 +--- pagetop/src/core/component/definition.rs | 8 ++------ pagetop/src/core/module.rs | 2 +- pagetop/src/core/module/definition.rs | 8 ++------ 7 files changed, 16 insertions(+), 24 deletions(-) diff --git a/examples/hello-world/src/main.rs b/examples/hello-world/src/main.rs index 502153f8..36c70336 100644 --- a/examples/hello-world/src/main.rs +++ b/examples/hello-world/src/main.rs @@ -1,8 +1,14 @@ use pagetop::prelude::*; +define_handle!(APP_HELLO_WORLD); + struct HelloWorld; impl ModuleTrait for HelloWorld { + fn handle(&self) -> Handle { + APP_HELLO_WORLD + } + fn configure_service(&self, cfg: &mut server::web::ServiceConfig) { cfg.route("/", server::web::get().to(hello_world)); } @@ -10,7 +16,7 @@ impl ModuleTrait for HelloWorld { async fn hello_world(request: server::HttpRequest) -> ResultPage { Page::new(request) - .with_in("content", L10n::html(html! {h1 { "Hello World!"}})) + .with_in("content", L10n::html(html! { h1 { "Hello World!" } })) .render() } diff --git a/pagetop/src/core/action.rs b/pagetop/src/core/action.rs index f526b79f..455e2176 100644 --- a/pagetop/src/core/action.rs +++ b/pagetop/src/core/action.rs @@ -1,5 +1,5 @@ mod definition; -pub use definition::{action_ref, ActionTrait, AnyAction, ACTION_UNNAMED}; +pub use definition::{action_ref, ActionTrait, AnyAction}; mod bundle; pub use bundle::Action; diff --git a/pagetop/src/core/action/definition.rs b/pagetop/src/core/action/definition.rs index e9a13ed3..96f5b5bf 100644 --- a/pagetop/src/core/action/definition.rs +++ b/pagetop/src/core/action/definition.rs @@ -1,17 +1,13 @@ -use crate::{define_handle, Handle}; +use crate::Handle; pub use std::any::Any as AnyAction; -define_handle!(ACTION_UNNAMED); - pub trait ActionTrait: AnyAction + Send + Sync { fn new() -> Self where Self: Sized; - fn handle(&self) -> Handle { - ACTION_UNNAMED - } + fn handle(&self) -> Handle; fn weight(&self) -> isize { 0 diff --git a/pagetop/src/core/component.rs b/pagetop/src/core/component.rs index cadd3340..ee186937 100644 --- a/pagetop/src/core/component.rs +++ b/pagetop/src/core/component.rs @@ -2,9 +2,7 @@ mod context; pub use context::{ContextOp, RenderContext}; mod definition; -pub use definition::{ - component_mut, component_ref, AnyComponent, BaseComponent, ComponentTrait, COMPONENT_UNNAMED, -}; +pub use definition::{component_mut, component_ref, AnyComponent, BaseComponent, ComponentTrait}; mod one; pub use one::OneComponent; diff --git a/pagetop/src/core/component/definition.rs b/pagetop/src/core/component/definition.rs index d81f30b9..fc7851e0 100644 --- a/pagetop/src/core/component/definition.rs +++ b/pagetop/src/core/component/definition.rs @@ -1,11 +1,9 @@ use crate::core::component::RenderContext; use crate::html::{html, Markup}; -use crate::{define_handle, util, Handle}; +use crate::{util, Handle}; pub use std::any::Any as AnyComponent; -define_handle!(COMPONENT_UNNAMED); - pub trait BaseComponent { fn render(&mut self, rcx: &mut RenderContext) -> Markup; } @@ -15,9 +13,7 @@ pub trait ComponentTrait: AnyComponent + BaseComponent + Send + Sync { where Self: Sized; - fn handle(&self) -> Handle { - COMPONENT_UNNAMED - } + fn handle(&self) -> Handle; fn name(&self) -> String { util::single_type_name::().to_owned() diff --git a/pagetop/src/core/module.rs b/pagetop/src/core/module.rs index 31e857e6..0ecfbc65 100644 --- a/pagetop/src/core/module.rs +++ b/pagetop/src/core/module.rs @@ -1,4 +1,4 @@ mod definition; -pub use definition::{BaseModule, ModuleStaticRef, ModuleTrait, MODULE_UNNAMED}; +pub use definition::{BaseModule, ModuleStaticRef, ModuleTrait}; pub(crate) mod all; diff --git a/pagetop/src/core/module/definition.rs b/pagetop/src/core/module/definition.rs index b6df322c..60ddfdf7 100644 --- a/pagetop/src/core/module/definition.rs +++ b/pagetop/src/core/module/definition.rs @@ -1,24 +1,20 @@ use crate::base::component::L10n; use crate::core::action::Action; use crate::core::theme::ThemeStaticRef; -use crate::{define_handle, server, util, Handle}; +use crate::{server, util, Handle}; #[cfg(feature = "database")] use crate::db::MigrationItem; pub type ModuleStaticRef = &'static dyn ModuleTrait; -define_handle!(MODULE_UNNAMED); - pub trait BaseModule { fn single_name(&self) -> &'static str; } /// Los módulos deben implementar este *trait*. pub trait ModuleTrait: BaseModule + Send + Sync { - fn handle(&self) -> Handle { - MODULE_UNNAMED - } + fn handle(&self) -> Handle; fn name(&self) -> L10n { L10n::text(self.single_name())