🚧 Handles siempre requeridos en la implementación

This commit is contained in:
Manuel Cillero 2023-06-09 11:11:50 +02:00
parent 0af85c4d77
commit a48c575198
7 changed files with 16 additions and 24 deletions

View file

@ -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<Markup, FatalError> {
Page::new(request)
.with_in("content", L10n::html(html! {h1 { "Hello World!"}}))
.with_in("content", L10n::html(html! { h1 { "Hello World!" } }))
.render()
}

View file

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

View file

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

View file

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

View file

@ -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::<Self>().to_owned()

View file

@ -1,4 +1,4 @@
mod definition;
pub use definition::{BaseModule, ModuleStaticRef, ModuleTrait, MODULE_UNNAMED};
pub use definition::{BaseModule, ModuleStaticRef, ModuleTrait};
pub(crate) mod all;

View file

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