🏷️ Simplifica nombres de traits esenciales

Los traits `ExtensionTrait`, `ThemeTrait` y `ComponentTrait` pasan a ser
`Extension`, `Theme`y `Component`, respectivamente,
This commit is contained in:
Manuel Cillero 2025-08-03 13:15:08 +02:00
parent ac0889cb8c
commit bf3ea43b53
23 changed files with 78 additions and 79 deletions

View file

@ -1,4 +1,4 @@
use crate::core::component::ComponentTrait;
use crate::core::component::Component;
use crate::html::{html, Context, Markup};
use crate::{builder_fn, UniqueId};
@ -9,14 +9,14 @@ use std::vec::IntoIter;
/// Representa un componente encapsulado de forma segura y compartida.
///
/// Esta estructura permite manipular y renderizar cualquier tipo que implemente [`ComponentTrait`],
/// Esta estructura permite manipular y renderizar cualquier tipo que implemente [`Component`],
/// garantizando acceso concurrente a través de [`Arc<RwLock<_>>`].
#[derive(Clone)]
pub struct Child(Arc<RwLock<dyn ComponentTrait>>);
pub struct Child(Arc<RwLock<dyn Component>>);
impl Child {
/// Crea un nuevo [`Child`] a partir de un componente.
pub fn with(component: impl ComponentTrait) -> Self {
pub fn with(component: impl Component) -> Self {
Child(Arc::new(RwLock::new(component)))
}
@ -47,15 +47,15 @@ impl Child {
/// Variante tipada de [`Child`] para evitar conversiones durante el uso.
///
/// Facilita el acceso a componentes del mismo tipo sin necesidad de hacer `downcast`.
pub struct Typed<C: ComponentTrait>(Arc<RwLock<C>>);
pub struct Typed<C: Component>(Arc<RwLock<C>>);
impl<C: ComponentTrait> Clone for Typed<C> {
impl<C: Component> Clone for Typed<C> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<C: ComponentTrait> Typed<C> {
impl<C: Component> Typed<C> {
/// Crea un nuevo [`Typed`] a partir de un componente.
pub fn with(component: C) -> Self {
Typed(Arc::new(RwLock::new(component)))
@ -97,7 +97,7 @@ pub enum ChildOp {
}
/// Operaciones con un componente hijo tipado [`Typed<C>`] en una lista [`Children`].
pub enum TypedOp<C: ComponentTrait> {
pub enum TypedOp<C: Component> {
Add(Typed<C>),
InsertAfterId(&'static str, Typed<C>),
InsertBeforeId(&'static str, Typed<C>),
@ -153,7 +153,7 @@ impl Children {
/// Ejecuta una operación con [`TypedOp`] en la lista.
#[builder_fn]
pub fn with_typed<C: ComponentTrait + Default>(mut self, op: TypedOp<C>) -> Self {
pub fn with_typed<C: Component + Default>(mut self, op: TypedOp<C>) -> Self {
match op {
TypedOp::Add(typed) => self.add(typed.into_child()),
TypedOp::InsertAfterId(id, typed) => self.insert_after_id(id, typed.into_child()),

View file

@ -5,7 +5,7 @@ use crate::html::{html, Context, Markup, PrepareMarkup, Render};
/// Define la función de renderizado para todos los componentes.
///
/// Este *trait* se implementa automáticamente en cualquier tipo (componente) que implemente
/// [`ComponentTrait`], por lo que no requiere ninguna codificación manual.
/// [`Component`], por lo que no requiere ninguna codificación manual.
pub trait ComponentRender {
/// Renderiza el componente usando el contexto proporcionado.
fn render(&mut self, cx: &mut Context) -> Markup;
@ -86,7 +86,7 @@ pub trait ComponentTrait: AnyInfo + ComponentRender + Send + Sync {
/// 7. Despacha [`action::component::AfterRender<C>`](crate::base::action::component::AfterRender)
/// para que otras extensiones puedan hacer sus últimos ajustes.
/// 8. Finalmente devuelve un [`Markup`] del renderizado preparado en el paso 5.
impl<C: ComponentTrait> ComponentRender for C {
impl<C: Component> ComponentRender for C {
fn render(&mut self, cx: &mut Context) -> Markup {
// Si no es renderizable, devuelve un bloque HTML vacío.
if !action::component::IsRenderable::dispatch(self, cx) {