use crate::prelude::*;
use super::FnActionTransformMarkup;
pub struct TransformMarkup<C: Component> {
f: FnActionTransformMarkup<C>,
referer_type_id: Option<UniqueId>,
referer_id: AttrId,
weight: Weight,
}
impl<C: Component> ActionDispatcher for TransformMarkup<C> {
fn referer_type_id(&self) -> Option<UniqueId> {
self.referer_type_id
}
fn referer_id(&self) -> Option<String> {
self.referer_id.get()
}
fn weight(&self) -> Weight {
self.weight
}
}
impl<C: Component> TransformMarkup<C> {
pub fn new(f: FnActionTransformMarkup<C>) -> Self {
TransformMarkup {
f,
referer_type_id: Some(UniqueId::of::<C>()),
referer_id: AttrId::default(),
weight: 0,
}
}
pub fn filter_by_referer_id(mut self, id: impl AsRef<str>) -> Self {
self.referer_id.alter_id(id);
self
}
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}
#[inline]
pub(crate) fn dispatch(component: &C, cx: &Context, markup: Markup) -> Markup {
let mut output = markup;
dispatch_actions(
&ActionKey::new(UniqueId::of::<Self>(), Some(UniqueId::of::<C>()), None),
|action: &Self| {
let taken = std::mem::replace(&mut output, html! {});
output = (action.f)(component, cx, taken);
},
);
if let Some(id) = component.id() {
dispatch_actions(
&ActionKey::new(UniqueId::of::<Self>(), Some(UniqueId::of::<C>()), Some(id)),
|action: &Self| {
let taken = std::mem::replace(&mut output, html! {});
output = (action.f)(component, cx, taken);
},
);
}
output
}
}