From 6c623fcd2dbc1a352f12e9fe7f728c2ca38c2f74 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Fri, 6 Dec 2024 22:45:01 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Renombra=20"TypeId"=20como=20"Un?= =?UTF-8?q?iqueId"=20por=20inter=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/component/after_render_component.rs | 17 +++++++++++------ .../component/before_render_component.rs | 17 +++++++++++------ .../src/base/action/component/is_renderable.rs | 17 +++++++++++------ .../action/layout/after_render_component.rs | 14 +++++++------- .../action/layout/after_render_page_body.rs | 6 +++--- .../action/layout/before_render_component.rs | 14 +++++++------- .../action/layout/before_render_page_body.rs | 6 +++--- .../src/base/action/layout/render_component.rs | 14 +++++++------- .../src/base/action/page/after_render_body.rs | 2 +- .../src/base/action/page/before_render_body.rs | 2 +- pagetop/src/core/action/definition.rs | 18 +++++++++--------- pagetop/src/core/component/children.rs | 6 +++--- pagetop/src/core/layout/regions.rs | 4 ++-- pagetop/src/lib.rs | 8 ++++---- pagetop/src/prelude.rs | 2 +- 15 files changed, 81 insertions(+), 66 deletions(-) diff --git a/pagetop/src/base/action/component/after_render_component.rs b/pagetop/src/base/action/component/after_render_component.rs index 66e13b94..3ee2815f 100644 --- a/pagetop/src/base/action/component/after_render_component.rs +++ b/pagetop/src/base/action/component/after_render_component.rs @@ -4,13 +4,13 @@ use crate::base::action::FnActionWithComponent; pub struct AfterRender { f: FnActionWithComponent, - referer_type_id: Option, + referer_type_id: Option, referer_id: OptionId, weight: Weight, } impl ActionTrait for AfterRender { - fn referer_type_id(&self) -> Option { + fn referer_type_id(&self) -> Option { self.referer_type_id } @@ -27,7 +27,7 @@ impl AfterRender { pub fn new(f: FnActionWithComponent) -> Self { AfterRender { f, - referer_type_id: Some(TypeId::of::()), + referer_type_id: Some(UniqueId::of::()), referer_id: OptionId::default(), weight: 0, } @@ -47,15 +47,20 @@ impl AfterRender { #[allow(clippy::inline_always)] pub(crate) fn dispatch(component: &mut C, cx: &mut Context) { dispatch_actions( - &ActionKey::new(TypeId::of::(), None, Some(TypeId::of::()), None), + &ActionKey::new( + UniqueId::of::(), + None, + Some(UniqueId::of::()), + None, + ), |action: &Self| (action.f)(component, cx), ); if let Some(id) = component.id() { dispatch_actions( &ActionKey::new( - TypeId::of::(), + UniqueId::of::(), None, - Some(TypeId::of::()), + Some(UniqueId::of::()), Some(id), ), |action: &Self| (action.f)(component, cx), diff --git a/pagetop/src/base/action/component/before_render_component.rs b/pagetop/src/base/action/component/before_render_component.rs index 4c7cc48f..808550e5 100644 --- a/pagetop/src/base/action/component/before_render_component.rs +++ b/pagetop/src/base/action/component/before_render_component.rs @@ -4,13 +4,13 @@ use crate::base::action::FnActionWithComponent; pub struct BeforeRender { f: FnActionWithComponent, - referer_type_id: Option, + referer_type_id: Option, referer_id: OptionId, weight: Weight, } impl ActionTrait for BeforeRender { - fn referer_type_id(&self) -> Option { + fn referer_type_id(&self) -> Option { self.referer_type_id } @@ -27,7 +27,7 @@ impl BeforeRender { pub fn new(f: FnActionWithComponent) -> Self { BeforeRender { f, - referer_type_id: Some(TypeId::of::()), + referer_type_id: Some(UniqueId::of::()), referer_id: OptionId::default(), weight: 0, } @@ -47,15 +47,20 @@ impl BeforeRender { #[allow(clippy::inline_always)] pub(crate) fn dispatch(component: &mut C, cx: &mut Context) { dispatch_actions( - &ActionKey::new(TypeId::of::(), None, Some(TypeId::of::()), None), + &ActionKey::new( + UniqueId::of::(), + None, + Some(UniqueId::of::()), + None, + ), |action: &Self| (action.f)(component, cx), ); if let Some(id) = component.id() { dispatch_actions( &ActionKey::new( - TypeId::of::(), + UniqueId::of::(), None, - Some(TypeId::of::()), + Some(UniqueId::of::()), Some(id), ), |action: &Self| (action.f)(component, cx), diff --git a/pagetop/src/base/action/component/is_renderable.rs b/pagetop/src/base/action/component/is_renderable.rs index 4d78a19c..b21fe788 100644 --- a/pagetop/src/base/action/component/is_renderable.rs +++ b/pagetop/src/base/action/component/is_renderable.rs @@ -4,13 +4,13 @@ pub type FnIsRenderable = fn(component: &C, cx: &mut Context) -> bool; pub struct IsRenderable { f: FnIsRenderable, - referer_type_id: Option, + referer_type_id: Option, referer_id: OptionId, weight: Weight, } impl ActionTrait for IsRenderable { - fn referer_type_id(&self) -> Option { + fn referer_type_id(&self) -> Option { self.referer_type_id } @@ -27,7 +27,7 @@ impl IsRenderable { pub fn new(f: FnIsRenderable) -> Self { IsRenderable { f, - referer_type_id: Some(TypeId::of::()), + referer_type_id: Some(UniqueId::of::()), referer_id: OptionId::default(), weight: 0, } @@ -48,7 +48,12 @@ impl IsRenderable { 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), + &ActionKey::new( + UniqueId::of::(), + None, + Some(UniqueId::of::()), + None, + ), |action: &Self| { if renderable && !(action.f)(component, cx) { renderable = false; @@ -59,9 +64,9 @@ impl IsRenderable { if let Some(id) = component.id() { dispatch_actions( &ActionKey::new( - TypeId::of::(), + UniqueId::of::(), None, - Some(TypeId::of::()), + Some(UniqueId::of::()), Some(id), ), |action: &Self| { diff --git a/pagetop/src/base/action/layout/after_render_component.rs b/pagetop/src/base/action/layout/after_render_component.rs index 10090e56..e96c8cef 100644 --- a/pagetop/src/base/action/layout/after_render_component.rs +++ b/pagetop/src/base/action/layout/after_render_component.rs @@ -4,16 +4,16 @@ use crate::base::action::FnActionWithComponent; pub struct AfterRender { f: FnActionWithComponent, - layout_type_id: Option, - referer_type_id: Option, + layout_type_id: Option, + referer_type_id: Option, } impl ActionTrait for AfterRender { - fn layout_type_id(&self) -> Option { + fn layout_type_id(&self) -> Option { self.layout_type_id } - fn referer_type_id(&self) -> Option { + fn referer_type_id(&self) -> Option { self.referer_type_id } } @@ -23,7 +23,7 @@ impl AfterRender { AfterRender { f, layout_type_id: Some(layout.type_id()), - referer_type_id: Some(TypeId::of::()), + referer_type_id: Some(UniqueId::of::()), } } @@ -32,9 +32,9 @@ impl AfterRender { pub(crate) fn dispatch(component: &mut C, cx: &mut Context) { dispatch_actions( &ActionKey::new( - TypeId::of::(), + UniqueId::of::(), Some(cx.layout().type_id()), - Some(TypeId::of::()), + Some(UniqueId::of::()), None, ), |action: &Self| (action.f)(component, cx), diff --git a/pagetop/src/base/action/layout/after_render_page_body.rs b/pagetop/src/base/action/layout/after_render_page_body.rs index 21b6dd6f..905c6807 100644 --- a/pagetop/src/base/action/layout/after_render_page_body.rs +++ b/pagetop/src/base/action/layout/after_render_page_body.rs @@ -4,11 +4,11 @@ use crate::base::action::FnActionWithPage; pub struct AfterRenderBody { f: FnActionWithPage, - layout_type_id: Option, + layout_type_id: Option, } impl ActionTrait for AfterRenderBody { - fn layout_type_id(&self) -> Option { + fn layout_type_id(&self) -> Option { self.layout_type_id } } @@ -26,7 +26,7 @@ impl AfterRenderBody { pub(crate) fn dispatch(page: &mut Page) { dispatch_actions( &ActionKey::new( - TypeId::of::(), + UniqueId::of::(), Some(page.context().layout().type_id()), None, None, diff --git a/pagetop/src/base/action/layout/before_render_component.rs b/pagetop/src/base/action/layout/before_render_component.rs index 5102c1fb..421f4e26 100644 --- a/pagetop/src/base/action/layout/before_render_component.rs +++ b/pagetop/src/base/action/layout/before_render_component.rs @@ -4,16 +4,16 @@ use crate::base::action::FnActionWithComponent; pub struct BeforeRender { f: FnActionWithComponent, - layout_type_id: Option, - referer_type_id: Option, + layout_type_id: Option, + referer_type_id: Option, } impl ActionTrait for BeforeRender { - fn layout_type_id(&self) -> Option { + fn layout_type_id(&self) -> Option { self.layout_type_id } - fn referer_type_id(&self) -> Option { + fn referer_type_id(&self) -> Option { self.referer_type_id } } @@ -23,7 +23,7 @@ impl BeforeRender { BeforeRender { f, layout_type_id: Some(layout.type_id()), - referer_type_id: Some(TypeId::of::()), + referer_type_id: Some(UniqueId::of::()), } } @@ -32,9 +32,9 @@ impl BeforeRender { pub(crate) fn dispatch(component: &mut C, cx: &mut Context) { dispatch_actions( &ActionKey::new( - TypeId::of::(), + UniqueId::of::(), Some(cx.layout().type_id()), - Some(TypeId::of::()), + Some(UniqueId::of::()), None, ), |action: &Self| (action.f)(component, cx), diff --git a/pagetop/src/base/action/layout/before_render_page_body.rs b/pagetop/src/base/action/layout/before_render_page_body.rs index 08a1e1e8..833ae3ce 100644 --- a/pagetop/src/base/action/layout/before_render_page_body.rs +++ b/pagetop/src/base/action/layout/before_render_page_body.rs @@ -4,11 +4,11 @@ use crate::base::action::FnActionWithPage; pub struct BeforeRenderBody { f: FnActionWithPage, - layout_type_id: Option, + layout_type_id: Option, } impl ActionTrait for BeforeRenderBody { - fn layout_type_id(&self) -> Option { + fn layout_type_id(&self) -> Option { self.layout_type_id } } @@ -26,7 +26,7 @@ impl BeforeRenderBody { pub(crate) fn dispatch(page: &mut Page) { dispatch_actions( &ActionKey::new( - TypeId::of::(), + UniqueId::of::(), Some(page.context().layout().type_id()), None, None, diff --git a/pagetop/src/base/action/layout/render_component.rs b/pagetop/src/base/action/layout/render_component.rs index b20f48f1..d21a1fc3 100644 --- a/pagetop/src/base/action/layout/render_component.rs +++ b/pagetop/src/base/action/layout/render_component.rs @@ -4,16 +4,16 @@ pub type FnRenderComponent = fn(component: &C, cx: &mut Context) -> Option { f: FnRenderComponent, - layout_type_id: Option, - referer_type_id: Option, + layout_type_id: Option, + referer_type_id: Option, } impl ActionTrait for RenderComponent { - fn layout_type_id(&self) -> Option { + fn layout_type_id(&self) -> Option { self.layout_type_id } - fn referer_type_id(&self) -> Option { + fn referer_type_id(&self) -> Option { self.referer_type_id } } @@ -23,7 +23,7 @@ impl RenderComponent { RenderComponent { f, layout_type_id: Some(layout.type_id()), - referer_type_id: Some(TypeId::of::()), + referer_type_id: Some(UniqueId::of::()), } } @@ -33,9 +33,9 @@ impl RenderComponent { let mut render_component: Option = None; dispatch_actions( &ActionKey::new( - TypeId::of::(), + UniqueId::of::(), Some(cx.layout().type_id()), - Some(TypeId::of::()), + Some(UniqueId::of::()), None, ), |action: &Self| { diff --git a/pagetop/src/base/action/page/after_render_body.rs b/pagetop/src/base/action/page/after_render_body.rs index f76a8d56..4a317abb 100644 --- a/pagetop/src/base/action/page/after_render_body.rs +++ b/pagetop/src/base/action/page/after_render_body.rs @@ -27,7 +27,7 @@ impl AfterRenderBody { #[allow(clippy::inline_always)] pub(crate) fn dispatch(page: &mut Page) { dispatch_actions( - &ActionKey::new(TypeId::of::(), None, None, None), + &ActionKey::new(UniqueId::of::(), None, None, None), |action: &Self| (action.f)(page), ); } diff --git a/pagetop/src/base/action/page/before_render_body.rs b/pagetop/src/base/action/page/before_render_body.rs index 45842269..acd5a204 100644 --- a/pagetop/src/base/action/page/before_render_body.rs +++ b/pagetop/src/base/action/page/before_render_body.rs @@ -27,7 +27,7 @@ impl BeforeRenderBody { #[allow(clippy::inline_always)] pub(crate) fn dispatch(page: &mut Page) { dispatch_actions( - &ActionKey::new(TypeId::of::(), None, None, None), + &ActionKey::new(UniqueId::of::(), None, None, None), |action: &Self| (action.f)(page), ); } diff --git a/pagetop/src/core/action/definition.rs b/pagetop/src/core/action/definition.rs index 094da455..033cd342 100644 --- a/pagetop/src/core/action/definition.rs +++ b/pagetop/src/core/action/definition.rs @@ -1,21 +1,21 @@ use crate::core::AnyBase; -use crate::{TypeId, Weight}; +use crate::{UniqueId, Weight}; pub type ActionBox = Box; #[derive(Eq, PartialEq, Hash)] pub struct ActionKey { - action_type_id: TypeId, - layout_type_id: Option, - referer_type_id: Option, + action_type_id: UniqueId, + layout_type_id: Option, + referer_type_id: Option, referer_id: Option, } impl ActionKey { pub fn new( - action_type_id: TypeId, - layout_type_id: Option, - referer_type_id: Option, + action_type_id: UniqueId, + layout_type_id: Option, + referer_type_id: Option, referer_id: Option, ) -> Self { ActionKey { @@ -32,11 +32,11 @@ pub trait ActionBase { } pub trait ActionTrait: ActionBase + AnyBase + Send + Sync { - fn layout_type_id(&self) -> Option { + fn layout_type_id(&self) -> Option { None } - fn referer_type_id(&self) -> Option { + fn referer_type_id(&self) -> Option { None } diff --git a/pagetop/src/core/component/children.rs b/pagetop/src/core/component/children.rs index 705a4525..6f90456d 100644 --- a/pagetop/src/core/component/children.rs +++ b/pagetop/src/core/component/children.rs @@ -1,6 +1,6 @@ use crate::core::component::{ComponentTrait, Context}; use crate::html::{html, Markup}; -use crate::{fn_builder, TypeId}; +use crate::{fn_builder, UniqueId}; use std::sync::{Arc, RwLock}; @@ -20,7 +20,7 @@ impl ChildComponent { // ChildComponent HELPERS. - fn type_id(&self) -> TypeId { + fn type_id(&self) -> UniqueId { self.0.read().unwrap().type_id() } @@ -197,7 +197,7 @@ impl Children { self.0.iter().filter(move |&c| c.id() == id) } - pub fn iter_by_type_id(&self, type_id: TypeId) -> impl Iterator { + pub fn iter_by_type_id(&self, type_id: UniqueId) -> impl Iterator { self.0.iter().filter(move |&c| c.type_id() == type_id) } diff --git a/pagetop/src/core/layout/regions.rs b/pagetop/src/core/layout/regions.rs index 8ec5f59f..7e3d8b01 100644 --- a/pagetop/src/core/layout/regions.rs +++ b/pagetop/src/core/layout/regions.rs @@ -1,11 +1,11 @@ use crate::core::component::{ChildComponent, ChildOp, Children}; use crate::core::layout::LayoutRef; -use crate::{fn_builder, AutoDefault, TypeId}; +use crate::{fn_builder, AutoDefault, UniqueId}; use std::collections::HashMap; use std::sync::{LazyLock, RwLock}; -static LAYOUT_REGIONS: LazyLock>> = +static LAYOUT_REGIONS: LazyLock>> = LazyLock::new(|| RwLock::new(HashMap::new())); static COMMON_REGIONS: LazyLock> = diff --git a/pagetop/src/lib.rs b/pagetop/src/lib.rs index c228dcfc..9f1a4aa7 100644 --- a/pagetop/src/lib.rs +++ b/pagetop/src/lib.rs @@ -83,18 +83,18 @@ // RE-EXPORTED ************************************************************************************* +// Concatena una serie de fragmentos de cadena en una cadena propia. pub use concat_string::concat_string; -/// Habilita la concatenación flexible de identificadores en macros, permitiendo crear nuevos -/// elementos con identificadores combinados. +/// Concatenación flexible de identificadores en macros. pub use paste::paste; pub use pagetop_macros::{fn_builder, html, main, test, AutoDefault, ComponentClasses}; pub type StaticResources = std::collections::HashMap<&'static str, static_files::Resource>; -// Un `TypeId` representa un identificador único global para un tipo. -pub use std::any::TypeId; +/// Un `UniqueId` representa un identificador único global para un tipo. +pub type UniqueId = std::any::TypeId; pub type Weight = i8; diff --git a/pagetop/src/prelude.rs b/pagetop/src/prelude.rs index ce132e72..6768849d 100644 --- a/pagetop/src/prelude.rs +++ b/pagetop/src/prelude.rs @@ -4,7 +4,7 @@ pub use crate::{concat_string, fn_builder, html, main, paste, test}; -pub use crate::{AutoDefault, ComponentClasses, StaticResources, TypeId, Weight}; +pub use crate::{AutoDefault, ComponentClasses, StaticResources, UniqueId, Weight}; // MACROS.