🚚 Renombra "TypeId" como "UniqueId" por interés

This commit is contained in:
Manuel Cillero 2024-12-06 22:45:01 +01:00
parent 4b9ed163ba
commit 6c623fcd2d
15 changed files with 81 additions and 66 deletions

View file

@ -4,13 +4,13 @@ use crate::base::action::FnActionWithComponent;
pub struct AfterRender<C: ComponentTrait> { pub struct AfterRender<C: ComponentTrait> {
f: FnActionWithComponent<C>, f: FnActionWithComponent<C>,
referer_type_id: Option<TypeId>, referer_type_id: Option<UniqueId>,
referer_id: OptionId, referer_id: OptionId,
weight: Weight, weight: Weight,
} }
impl<C: ComponentTrait> ActionTrait for AfterRender<C> { impl<C: ComponentTrait> ActionTrait for AfterRender<C> {
fn referer_type_id(&self) -> Option<TypeId> { fn referer_type_id(&self) -> Option<UniqueId> {
self.referer_type_id self.referer_type_id
} }
@ -27,7 +27,7 @@ impl<C: ComponentTrait> AfterRender<C> {
pub fn new(f: FnActionWithComponent<C>) -> Self { pub fn new(f: FnActionWithComponent<C>) -> Self {
AfterRender { AfterRender {
f, f,
referer_type_id: Some(TypeId::of::<C>()), referer_type_id: Some(UniqueId::of::<C>()),
referer_id: OptionId::default(), referer_id: OptionId::default(),
weight: 0, weight: 0,
} }
@ -47,15 +47,20 @@ impl<C: ComponentTrait> AfterRender<C> {
#[allow(clippy::inline_always)] #[allow(clippy::inline_always)]
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) { pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
dispatch_actions( dispatch_actions(
&ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None), &ActionKey::new(
UniqueId::of::<Self>(),
None,
Some(UniqueId::of::<C>()),
None,
),
|action: &Self| (action.f)(component, cx), |action: &Self| (action.f)(component, cx),
); );
if let Some(id) = component.id() { if let Some(id) = component.id() {
dispatch_actions( dispatch_actions(
&ActionKey::new( &ActionKey::new(
TypeId::of::<Self>(), UniqueId::of::<Self>(),
None, None,
Some(TypeId::of::<C>()), Some(UniqueId::of::<C>()),
Some(id), Some(id),
), ),
|action: &Self| (action.f)(component, cx), |action: &Self| (action.f)(component, cx),

View file

@ -4,13 +4,13 @@ use crate::base::action::FnActionWithComponent;
pub struct BeforeRender<C: ComponentTrait> { pub struct BeforeRender<C: ComponentTrait> {
f: FnActionWithComponent<C>, f: FnActionWithComponent<C>,
referer_type_id: Option<TypeId>, referer_type_id: Option<UniqueId>,
referer_id: OptionId, referer_id: OptionId,
weight: Weight, weight: Weight,
} }
impl<C: ComponentTrait> ActionTrait for BeforeRender<C> { impl<C: ComponentTrait> ActionTrait for BeforeRender<C> {
fn referer_type_id(&self) -> Option<TypeId> { fn referer_type_id(&self) -> Option<UniqueId> {
self.referer_type_id self.referer_type_id
} }
@ -27,7 +27,7 @@ impl<C: ComponentTrait> BeforeRender<C> {
pub fn new(f: FnActionWithComponent<C>) -> Self { pub fn new(f: FnActionWithComponent<C>) -> Self {
BeforeRender { BeforeRender {
f, f,
referer_type_id: Some(TypeId::of::<C>()), referer_type_id: Some(UniqueId::of::<C>()),
referer_id: OptionId::default(), referer_id: OptionId::default(),
weight: 0, weight: 0,
} }
@ -47,15 +47,20 @@ impl<C: ComponentTrait> BeforeRender<C> {
#[allow(clippy::inline_always)] #[allow(clippy::inline_always)]
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) { pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
dispatch_actions( dispatch_actions(
&ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None), &ActionKey::new(
UniqueId::of::<Self>(),
None,
Some(UniqueId::of::<C>()),
None,
),
|action: &Self| (action.f)(component, cx), |action: &Self| (action.f)(component, cx),
); );
if let Some(id) = component.id() { if let Some(id) = component.id() {
dispatch_actions( dispatch_actions(
&ActionKey::new( &ActionKey::new(
TypeId::of::<Self>(), UniqueId::of::<Self>(),
None, None,
Some(TypeId::of::<C>()), Some(UniqueId::of::<C>()),
Some(id), Some(id),
), ),
|action: &Self| (action.f)(component, cx), |action: &Self| (action.f)(component, cx),

View file

@ -4,13 +4,13 @@ pub type FnIsRenderable<C> = fn(component: &C, cx: &mut Context) -> bool;
pub struct IsRenderable<C: ComponentTrait> { pub struct IsRenderable<C: ComponentTrait> {
f: FnIsRenderable<C>, f: FnIsRenderable<C>,
referer_type_id: Option<TypeId>, referer_type_id: Option<UniqueId>,
referer_id: OptionId, referer_id: OptionId,
weight: Weight, weight: Weight,
} }
impl<C: ComponentTrait> ActionTrait for IsRenderable<C> { impl<C: ComponentTrait> ActionTrait for IsRenderable<C> {
fn referer_type_id(&self) -> Option<TypeId> { fn referer_type_id(&self) -> Option<UniqueId> {
self.referer_type_id self.referer_type_id
} }
@ -27,7 +27,7 @@ impl<C: ComponentTrait> IsRenderable<C> {
pub fn new(f: FnIsRenderable<C>) -> Self { pub fn new(f: FnIsRenderable<C>) -> Self {
IsRenderable { IsRenderable {
f, f,
referer_type_id: Some(TypeId::of::<C>()), referer_type_id: Some(UniqueId::of::<C>()),
referer_id: OptionId::default(), referer_id: OptionId::default(),
weight: 0, weight: 0,
} }
@ -48,7 +48,12 @@ impl<C: ComponentTrait> IsRenderable<C> {
pub(crate) fn dispatch(component: &C, cx: &mut Context) -> bool { pub(crate) fn dispatch(component: &C, cx: &mut Context) -> bool {
let mut renderable = true; let mut renderable = true;
dispatch_actions( dispatch_actions(
&ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None), &ActionKey::new(
UniqueId::of::<Self>(),
None,
Some(UniqueId::of::<C>()),
None,
),
|action: &Self| { |action: &Self| {
if renderable && !(action.f)(component, cx) { if renderable && !(action.f)(component, cx) {
renderable = false; renderable = false;
@ -59,9 +64,9 @@ impl<C: ComponentTrait> IsRenderable<C> {
if let Some(id) = component.id() { if let Some(id) = component.id() {
dispatch_actions( dispatch_actions(
&ActionKey::new( &ActionKey::new(
TypeId::of::<Self>(), UniqueId::of::<Self>(),
None, None,
Some(TypeId::of::<C>()), Some(UniqueId::of::<C>()),
Some(id), Some(id),
), ),
|action: &Self| { |action: &Self| {

View file

@ -4,16 +4,16 @@ use crate::base::action::FnActionWithComponent;
pub struct AfterRender<C: ComponentTrait> { pub struct AfterRender<C: ComponentTrait> {
f: FnActionWithComponent<C>, f: FnActionWithComponent<C>,
layout_type_id: Option<TypeId>, layout_type_id: Option<UniqueId>,
referer_type_id: Option<TypeId>, referer_type_id: Option<UniqueId>,
} }
impl<C: ComponentTrait> ActionTrait for AfterRender<C> { impl<C: ComponentTrait> ActionTrait for AfterRender<C> {
fn layout_type_id(&self) -> Option<TypeId> { fn layout_type_id(&self) -> Option<UniqueId> {
self.layout_type_id self.layout_type_id
} }
fn referer_type_id(&self) -> Option<TypeId> { fn referer_type_id(&self) -> Option<UniqueId> {
self.referer_type_id self.referer_type_id
} }
} }
@ -23,7 +23,7 @@ impl<C: ComponentTrait> AfterRender<C> {
AfterRender { AfterRender {
f, f,
layout_type_id: Some(layout.type_id()), layout_type_id: Some(layout.type_id()),
referer_type_id: Some(TypeId::of::<C>()), referer_type_id: Some(UniqueId::of::<C>()),
} }
} }
@ -32,9 +32,9 @@ impl<C: ComponentTrait> AfterRender<C> {
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) { pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
dispatch_actions( dispatch_actions(
&ActionKey::new( &ActionKey::new(
TypeId::of::<Self>(), UniqueId::of::<Self>(),
Some(cx.layout().type_id()), Some(cx.layout().type_id()),
Some(TypeId::of::<C>()), Some(UniqueId::of::<C>()),
None, None,
), ),
|action: &Self| (action.f)(component, cx), |action: &Self| (action.f)(component, cx),

View file

@ -4,11 +4,11 @@ use crate::base::action::FnActionWithPage;
pub struct AfterRenderBody { pub struct AfterRenderBody {
f: FnActionWithPage, f: FnActionWithPage,
layout_type_id: Option<TypeId>, layout_type_id: Option<UniqueId>,
} }
impl ActionTrait for AfterRenderBody { impl ActionTrait for AfterRenderBody {
fn layout_type_id(&self) -> Option<TypeId> { fn layout_type_id(&self) -> Option<UniqueId> {
self.layout_type_id self.layout_type_id
} }
} }
@ -26,7 +26,7 @@ impl AfterRenderBody {
pub(crate) fn dispatch(page: &mut Page) { pub(crate) fn dispatch(page: &mut Page) {
dispatch_actions( dispatch_actions(
&ActionKey::new( &ActionKey::new(
TypeId::of::<Self>(), UniqueId::of::<Self>(),
Some(page.context().layout().type_id()), Some(page.context().layout().type_id()),
None, None,
None, None,

View file

@ -4,16 +4,16 @@ use crate::base::action::FnActionWithComponent;
pub struct BeforeRender<C: ComponentTrait> { pub struct BeforeRender<C: ComponentTrait> {
f: FnActionWithComponent<C>, f: FnActionWithComponent<C>,
layout_type_id: Option<TypeId>, layout_type_id: Option<UniqueId>,
referer_type_id: Option<TypeId>, referer_type_id: Option<UniqueId>,
} }
impl<C: ComponentTrait> ActionTrait for BeforeRender<C> { impl<C: ComponentTrait> ActionTrait for BeforeRender<C> {
fn layout_type_id(&self) -> Option<TypeId> { fn layout_type_id(&self) -> Option<UniqueId> {
self.layout_type_id self.layout_type_id
} }
fn referer_type_id(&self) -> Option<TypeId> { fn referer_type_id(&self) -> Option<UniqueId> {
self.referer_type_id self.referer_type_id
} }
} }
@ -23,7 +23,7 @@ impl<C: ComponentTrait> BeforeRender<C> {
BeforeRender { BeforeRender {
f, f,
layout_type_id: Some(layout.type_id()), layout_type_id: Some(layout.type_id()),
referer_type_id: Some(TypeId::of::<C>()), referer_type_id: Some(UniqueId::of::<C>()),
} }
} }
@ -32,9 +32,9 @@ impl<C: ComponentTrait> BeforeRender<C> {
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) { pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
dispatch_actions( dispatch_actions(
&ActionKey::new( &ActionKey::new(
TypeId::of::<Self>(), UniqueId::of::<Self>(),
Some(cx.layout().type_id()), Some(cx.layout().type_id()),
Some(TypeId::of::<C>()), Some(UniqueId::of::<C>()),
None, None,
), ),
|action: &Self| (action.f)(component, cx), |action: &Self| (action.f)(component, cx),

View file

@ -4,11 +4,11 @@ use crate::base::action::FnActionWithPage;
pub struct BeforeRenderBody { pub struct BeforeRenderBody {
f: FnActionWithPage, f: FnActionWithPage,
layout_type_id: Option<TypeId>, layout_type_id: Option<UniqueId>,
} }
impl ActionTrait for BeforeRenderBody { impl ActionTrait for BeforeRenderBody {
fn layout_type_id(&self) -> Option<TypeId> { fn layout_type_id(&self) -> Option<UniqueId> {
self.layout_type_id self.layout_type_id
} }
} }
@ -26,7 +26,7 @@ impl BeforeRenderBody {
pub(crate) fn dispatch(page: &mut Page) { pub(crate) fn dispatch(page: &mut Page) {
dispatch_actions( dispatch_actions(
&ActionKey::new( &ActionKey::new(
TypeId::of::<Self>(), UniqueId::of::<Self>(),
Some(page.context().layout().type_id()), Some(page.context().layout().type_id()),
None, None,
None, None,

View file

@ -4,16 +4,16 @@ pub type FnRenderComponent<C> = fn(component: &C, cx: &mut Context) -> Option<Ma
pub struct RenderComponent<C: ComponentTrait> { pub struct RenderComponent<C: ComponentTrait> {
f: FnRenderComponent<C>, f: FnRenderComponent<C>,
layout_type_id: Option<TypeId>, layout_type_id: Option<UniqueId>,
referer_type_id: Option<TypeId>, referer_type_id: Option<UniqueId>,
} }
impl<C: ComponentTrait> ActionTrait for RenderComponent<C> { impl<C: ComponentTrait> ActionTrait for RenderComponent<C> {
fn layout_type_id(&self) -> Option<TypeId> { fn layout_type_id(&self) -> Option<UniqueId> {
self.layout_type_id self.layout_type_id
} }
fn referer_type_id(&self) -> Option<TypeId> { fn referer_type_id(&self) -> Option<UniqueId> {
self.referer_type_id self.referer_type_id
} }
} }
@ -23,7 +23,7 @@ impl<C: ComponentTrait> RenderComponent<C> {
RenderComponent { RenderComponent {
f, f,
layout_type_id: Some(layout.type_id()), layout_type_id: Some(layout.type_id()),
referer_type_id: Some(TypeId::of::<C>()), referer_type_id: Some(UniqueId::of::<C>()),
} }
} }
@ -33,9 +33,9 @@ impl<C: ComponentTrait> RenderComponent<C> {
let mut render_component: Option<Markup> = None; let mut render_component: Option<Markup> = None;
dispatch_actions( dispatch_actions(
&ActionKey::new( &ActionKey::new(
TypeId::of::<Self>(), UniqueId::of::<Self>(),
Some(cx.layout().type_id()), Some(cx.layout().type_id()),
Some(TypeId::of::<C>()), Some(UniqueId::of::<C>()),
None, None,
), ),
|action: &Self| { |action: &Self| {

View file

@ -27,7 +27,7 @@ impl AfterRenderBody {
#[allow(clippy::inline_always)] #[allow(clippy::inline_always)]
pub(crate) fn dispatch(page: &mut Page) { pub(crate) fn dispatch(page: &mut Page) {
dispatch_actions( dispatch_actions(
&ActionKey::new(TypeId::of::<Self>(), None, None, None), &ActionKey::new(UniqueId::of::<Self>(), None, None, None),
|action: &Self| (action.f)(page), |action: &Self| (action.f)(page),
); );
} }

View file

@ -27,7 +27,7 @@ impl BeforeRenderBody {
#[allow(clippy::inline_always)] #[allow(clippy::inline_always)]
pub(crate) fn dispatch(page: &mut Page) { pub(crate) fn dispatch(page: &mut Page) {
dispatch_actions( dispatch_actions(
&ActionKey::new(TypeId::of::<Self>(), None, None, None), &ActionKey::new(UniqueId::of::<Self>(), None, None, None),
|action: &Self| (action.f)(page), |action: &Self| (action.f)(page),
); );
} }

View file

@ -1,21 +1,21 @@
use crate::core::AnyBase; use crate::core::AnyBase;
use crate::{TypeId, Weight}; use crate::{UniqueId, Weight};
pub type ActionBox = Box<dyn ActionTrait>; pub type ActionBox = Box<dyn ActionTrait>;
#[derive(Eq, PartialEq, Hash)] #[derive(Eq, PartialEq, Hash)]
pub struct ActionKey { pub struct ActionKey {
action_type_id: TypeId, action_type_id: UniqueId,
layout_type_id: Option<TypeId>, layout_type_id: Option<UniqueId>,
referer_type_id: Option<TypeId>, referer_type_id: Option<UniqueId>,
referer_id: Option<String>, referer_id: Option<String>,
} }
impl ActionKey { impl ActionKey {
pub fn new( pub fn new(
action_type_id: TypeId, action_type_id: UniqueId,
layout_type_id: Option<TypeId>, layout_type_id: Option<UniqueId>,
referer_type_id: Option<TypeId>, referer_type_id: Option<UniqueId>,
referer_id: Option<String>, referer_id: Option<String>,
) -> Self { ) -> Self {
ActionKey { ActionKey {
@ -32,11 +32,11 @@ pub trait ActionBase {
} }
pub trait ActionTrait: ActionBase + AnyBase + Send + Sync { pub trait ActionTrait: ActionBase + AnyBase + Send + Sync {
fn layout_type_id(&self) -> Option<TypeId> { fn layout_type_id(&self) -> Option<UniqueId> {
None None
} }
fn referer_type_id(&self) -> Option<TypeId> { fn referer_type_id(&self) -> Option<UniqueId> {
None None
} }

View file

@ -1,6 +1,6 @@
use crate::core::component::{ComponentTrait, Context}; use crate::core::component::{ComponentTrait, Context};
use crate::html::{html, Markup}; use crate::html::{html, Markup};
use crate::{fn_builder, TypeId}; use crate::{fn_builder, UniqueId};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
@ -20,7 +20,7 @@ impl ChildComponent {
// ChildComponent HELPERS. // ChildComponent HELPERS.
fn type_id(&self) -> TypeId { fn type_id(&self) -> UniqueId {
self.0.read().unwrap().type_id() self.0.read().unwrap().type_id()
} }
@ -197,7 +197,7 @@ impl Children {
self.0.iter().filter(move |&c| c.id() == id) self.0.iter().filter(move |&c| c.id() == id)
} }
pub fn iter_by_type_id(&self, type_id: TypeId) -> impl Iterator<Item = &ChildComponent> { pub fn iter_by_type_id(&self, type_id: UniqueId) -> impl Iterator<Item = &ChildComponent> {
self.0.iter().filter(move |&c| c.type_id() == type_id) self.0.iter().filter(move |&c| c.type_id() == type_id)
} }

View file

@ -1,11 +1,11 @@
use crate::core::component::{ChildComponent, ChildOp, Children}; use crate::core::component::{ChildComponent, ChildOp, Children};
use crate::core::layout::LayoutRef; use crate::core::layout::LayoutRef;
use crate::{fn_builder, AutoDefault, TypeId}; use crate::{fn_builder, AutoDefault, UniqueId};
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{LazyLock, RwLock}; use std::sync::{LazyLock, RwLock};
static LAYOUT_REGIONS: LazyLock<RwLock<HashMap<TypeId, ChildrenInRegions>>> = static LAYOUT_REGIONS: LazyLock<RwLock<HashMap<UniqueId, ChildrenInRegions>>> =
LazyLock::new(|| RwLock::new(HashMap::new())); LazyLock::new(|| RwLock::new(HashMap::new()));
static COMMON_REGIONS: LazyLock<RwLock<ChildrenInRegions>> = static COMMON_REGIONS: LazyLock<RwLock<ChildrenInRegions>> =

View file

@ -83,18 +83,18 @@
// RE-EXPORTED ************************************************************************************* // RE-EXPORTED *************************************************************************************
// Concatena una serie de fragmentos de cadena en una cadena propia.
pub use concat_string::concat_string; pub use concat_string::concat_string;
/// Habilita la concatenación flexible de identificadores en macros, permitiendo crear nuevos /// Concatenación flexible de identificadores en macros.
/// elementos con identificadores combinados.
pub use paste::paste; pub use paste::paste;
pub use pagetop_macros::{fn_builder, html, main, test, AutoDefault, ComponentClasses}; pub use pagetop_macros::{fn_builder, html, main, test, AutoDefault, ComponentClasses};
pub type StaticResources = std::collections::HashMap<&'static str, static_files::Resource>; pub type StaticResources = std::collections::HashMap<&'static str, static_files::Resource>;
// Un `TypeId` representa un identificador único global para un tipo. /// Un `UniqueId` representa un identificador único global para un tipo.
pub use std::any::TypeId; pub type UniqueId = std::any::TypeId;
pub type Weight = i8; pub type Weight = i8;

View file

@ -4,7 +4,7 @@
pub use crate::{concat_string, fn_builder, html, main, paste, test}; 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. // MACROS.