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

View file

@ -4,13 +4,13 @@ use crate::base::action::FnActionWithComponent;
pub struct BeforeRender<C: ComponentTrait> {
f: FnActionWithComponent<C>,
referer_type_id: Option<TypeId>,
referer_type_id: Option<UniqueId>,
referer_id: OptionId,
weight: Weight,
}
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
}
@ -27,7 +27,7 @@ impl<C: ComponentTrait> BeforeRender<C> {
pub fn new(f: FnActionWithComponent<C>) -> Self {
BeforeRender {
f,
referer_type_id: Some(TypeId::of::<C>()),
referer_type_id: Some(UniqueId::of::<C>()),
referer_id: OptionId::default(),
weight: 0,
}
@ -47,15 +47,20 @@ impl<C: ComponentTrait> BeforeRender<C> {
#[allow(clippy::inline_always)]
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
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),
);
if let Some(id) = component.id() {
dispatch_actions(
&ActionKey::new(
TypeId::of::<Self>(),
UniqueId::of::<Self>(),
None,
Some(TypeId::of::<C>()),
Some(UniqueId::of::<C>()),
Some(id),
),
|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> {
f: FnIsRenderable<C>,
referer_type_id: Option<TypeId>,
referer_type_id: Option<UniqueId>,
referer_id: OptionId,
weight: Weight,
}
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
}
@ -27,7 +27,7 @@ impl<C: ComponentTrait> IsRenderable<C> {
pub fn new(f: FnIsRenderable<C>) -> Self {
IsRenderable {
f,
referer_type_id: Some(TypeId::of::<C>()),
referer_type_id: Some(UniqueId::of::<C>()),
referer_id: OptionId::default(),
weight: 0,
}
@ -48,7 +48,12 @@ impl<C: ComponentTrait> IsRenderable<C> {
pub(crate) fn dispatch(component: &C, cx: &mut Context) -> bool {
let mut renderable = true;
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| {
if renderable && !(action.f)(component, cx) {
renderable = false;
@ -59,9 +64,9 @@ impl<C: ComponentTrait> IsRenderable<C> {
if let Some(id) = component.id() {
dispatch_actions(
&ActionKey::new(
TypeId::of::<Self>(),
UniqueId::of::<Self>(),
None,
Some(TypeId::of::<C>()),
Some(UniqueId::of::<C>()),
Some(id),
),
|action: &Self| {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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<RwLock<HashMap<TypeId, ChildrenInRegions>>> =
static LAYOUT_REGIONS: LazyLock<RwLock<HashMap<UniqueId, ChildrenInRegions>>> =
LazyLock::new(|| RwLock::new(HashMap::new()));
static COMMON_REGIONS: LazyLock<RwLock<ChildrenInRegions>> =

View file

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

View file

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