🎨 Passes action keys by reference in dispatch
This commit is contained in:
parent
b481d84cba
commit
5f9c1e4b15
9 changed files with 41 additions and 31 deletions
|
|
@ -44,18 +44,19 @@ impl<C: ComponentTrait> AfterPrepare<C> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[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(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None),
|
||||
|action: &Self| (action.f)(component, cx),
|
||||
);
|
||||
if component.id().is_some() {
|
||||
if let Some(id) = component.id() {
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
&ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
None,
|
||||
Some(TypeId::of::<C>()),
|
||||
component.id(),
|
||||
Some(id),
|
||||
),
|
||||
|action: &Self| (action.f)(component, cx),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -44,18 +44,19 @@ impl<C: ComponentTrait> BeforePrepare<C> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[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(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None),
|
||||
|action: &Self| (action.f)(component, cx),
|
||||
);
|
||||
if component.id().is_some() {
|
||||
if let Some(id) = component.id() {
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
&ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
None,
|
||||
Some(TypeId::of::<C>()),
|
||||
component.id(),
|
||||
Some(id),
|
||||
),
|
||||
|action: &Self| (action.f)(component, cx),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -44,30 +44,33 @@ impl<C: ComponentTrait> IsRenderable<C> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(clippy::inline_always)]
|
||||
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(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None),
|
||||
|action: &Self| {
|
||||
if renderable && !(action.f)(component, cx) {
|
||||
renderable = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
if renderable && component.id().is_some() {
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
None,
|
||||
Some(TypeId::of::<C>()),
|
||||
component.id(),
|
||||
),
|
||||
|action: &Self| {
|
||||
if renderable && !(action.f)(component, cx) {
|
||||
renderable = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
if renderable {
|
||||
if let Some(id) = component.id() {
|
||||
dispatch_actions(
|
||||
&ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
None,
|
||||
Some(TypeId::of::<C>()),
|
||||
Some(id),
|
||||
),
|
||||
|action: &Self| {
|
||||
if renderable && !(action.f)(component, cx) {
|
||||
renderable = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
renderable
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,10 @@ impl AfterPrepareBody {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(clippy::inline_always)]
|
||||
pub(crate) fn dispatch(page: &mut Page) {
|
||||
dispatch_actions(
|
||||
ActionKey::new(TypeId::of::<Self>(), None, None, None),
|
||||
&ActionKey::new(TypeId::of::<Self>(), None, None, None),
|
||||
|action: &Self| (action.f)(page),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,10 @@ impl BeforePrepareBody {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(clippy::inline_always)]
|
||||
pub(crate) fn dispatch(page: &mut Page) {
|
||||
dispatch_actions(
|
||||
ActionKey::new(TypeId::of::<Self>(), None, None, None),
|
||||
&ActionKey::new(TypeId::of::<Self>(), None, None, None),
|
||||
|action: &Self| (action.f)(page),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,10 @@ impl<C: ComponentTrait> AfterPrepare<C> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(clippy::inline_always)]
|
||||
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
&ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
Some(cx.theme().type_id()),
|
||||
Some(TypeId::of::<C>()),
|
||||
|
|
|
|||
|
|
@ -28,9 +28,10 @@ impl<C: ComponentTrait> BeforePrepare<C> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(clippy::inline_always)]
|
||||
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
&ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
Some(cx.theme().type_id()),
|
||||
Some(TypeId::of::<C>()),
|
||||
|
|
|
|||
|
|
@ -28,10 +28,11 @@ impl<C: ComponentTrait> RenderComponent<C> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(clippy::inline_always)]
|
||||
pub(crate) fn dispatch(component: &C, cx: &mut Context) -> Option<Markup> {
|
||||
let mut render_component: Option<Markup> = None;
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
&ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
Some(cx.theme().type_id()),
|
||||
Some(TypeId::of::<C>()),
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ pub fn add_action(action: ActionBox) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn dispatch_actions<A, B, F>(key: ActionKey, f: F)
|
||||
pub fn dispatch_actions<A, B, F>(key: &ActionKey, f: F)
|
||||
where
|
||||
A: ActionTrait,
|
||||
F: FnMut(&A) -> B,
|
||||
{
|
||||
if let Some(list) = ACTIONS.read().unwrap().get(&key) {
|
||||
list.iter_map(f)
|
||||
if let Some(list) = ACTIONS.read().unwrap().get(key) {
|
||||
list.iter_map(f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue