use crate::prelude::*; use crate::base::action::FnActionWithComponent; /// Ejecuta [`FnActionWithComponent`] antes de que un tema renderice el componente. pub struct BeforeRender { f: FnActionWithComponent, theme_type_id: Option, referer_type_id: Option, } /// Filtro para despachar [`FnActionWithComponent`] antes de que un tema renderice el componente /// `C`. impl ActionDispatcher for BeforeRender { /// Devuelve el identificador de tipo ([`UniqueId`]) del tema. fn theme_type_id(&self) -> Option { self.theme_type_id } /// Devuelve el identificador de tipo ([`UniqueId`]) del componente `C`. fn referer_type_id(&self) -> Option { self.referer_type_id } } impl BeforeRender { /// Permite [registrar](Extension::actions) una nueva acción [`FnActionWithComponent`] para un /// tema dado. pub fn new(theme: ThemeRef, f: FnActionWithComponent) -> Self { BeforeRender { f, theme_type_id: Some(theme.type_id()), referer_type_id: Some(UniqueId::of::()), } } // Despacha las acciones. #[inline] pub(crate) fn dispatch(component: &mut C, cx: &mut Context) { dispatch_actions( &ActionKey::new( UniqueId::of::(), Some(cx.theme().type_id()), Some(UniqueId::of::()), None, ), |action: &Self| (action.f)(component, cx), ); } }