♻️ Major code restructuring

This commit is contained in:
Manuel Cillero 2024-02-09 14:05:38 +01:00
parent a96e203bb3
commit fa66d628a0
221 changed files with 228 additions and 315 deletions

View file

@ -0,0 +1,9 @@
use crate::prelude::*;
pub type FnActionComponent<C> = fn(component: &mut C, cx: &mut Context);
mod before_prepare_component;
pub use before_prepare_component::*;
mod after_prepare_component;
pub use after_prepare_component::*;

View file

@ -0,0 +1,55 @@
use crate::prelude::*;
use crate::BaseHandle;
use super::FnActionComponent;
#[derive(BaseHandle)]
pub struct AfterPrepareComponent<C: ComponentTrait> {
f: FnActionComponent<C>,
referer_handle: Option<Handle>,
referer_id: OptionId,
weight: Weight,
}
impl<C: ComponentTrait> ActionTrait for AfterPrepareComponent<C> {
fn referer_handle(&self) -> Option<Handle> {
self.referer_handle
}
fn referer_id(&self) -> Option<String> {
self.referer_id.get()
}
fn weight(&self) -> Weight {
self.weight
}
}
impl<C: ComponentTrait> AfterPrepareComponent<C> {
pub fn new(f: FnActionComponent<C>) -> Self {
AfterPrepareComponent {
f,
referer_handle: Some(C::static_handle()),
referer_id: OptionId::default(),
weight: 0,
}
}
pub fn filter_by_referer_id(mut self, id: impl Into<String>) -> Self {
self.referer_id.alter_value(id);
self
}
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}
#[inline(always)]
pub(crate) fn dispatch(component: &mut C, cx: &mut Context, referer_id: Option<String>) {
dispatch_actions(
(Self::static_handle(), Some(component.handle()), referer_id),
|action| (action_ref::<AfterPrepareComponent<C>>(&**action).f)(component, cx),
);
}
}

View file

@ -0,0 +1,55 @@
use crate::prelude::*;
use crate::BaseHandle;
use super::FnActionComponent;
#[derive(BaseHandle)]
pub struct BeforePrepareComponent<C: ComponentTrait> {
f: FnActionComponent<C>,
referer_handle: Option<Handle>,
referer_id: OptionId,
weight: Weight,
}
impl<C: ComponentTrait> ActionTrait for BeforePrepareComponent<C> {
fn referer_handle(&self) -> Option<Handle> {
self.referer_handle
}
fn referer_id(&self) -> Option<String> {
self.referer_id.get()
}
fn weight(&self) -> Weight {
self.weight
}
}
impl<C: ComponentTrait> BeforePrepareComponent<C> {
pub fn new(f: FnActionComponent<C>) -> Self {
BeforePrepareComponent {
f,
referer_handle: Some(C::static_handle()),
referer_id: OptionId::default(),
weight: 0,
}
}
pub fn filter_by_referer_id(mut self, id: impl Into<String>) -> Self {
self.referer_id.alter_value(id);
self
}
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}
#[inline(always)]
pub(crate) fn dispatch(component: &mut C, cx: &mut Context, referer_id: Option<String>) {
dispatch_actions(
(Self::static_handle(), Some(component.handle()), referer_id),
|action| (action_ref::<BeforePrepareComponent<C>>(&**action).f)(component, cx),
);
}
}

9
src/base/action/page.rs Normal file
View file

@ -0,0 +1,9 @@
use crate::prelude::*;
pub type FnActionPage = fn(page: &mut Page);
mod before_prepare_body;
pub use before_prepare_body::*;
mod after_prepare_body;
pub use after_prepare_body::*;

View file

@ -0,0 +1,34 @@
use crate::prelude::*;
use crate::BaseHandle;
use super::FnActionPage;
#[derive(BaseHandle)]
pub struct AfterPrepareBody {
f: FnActionPage,
weight: Weight,
}
impl ActionTrait for AfterPrepareBody {
fn weight(&self) -> Weight {
self.weight
}
}
impl AfterPrepareBody {
pub fn new(f: FnActionPage) -> Self {
AfterPrepareBody { f, weight: 0 }
}
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}
#[inline(always)]
pub(crate) fn dispatch(page: &mut Page) {
dispatch_actions((Self::static_handle(), None, None), |action| {
(action_ref::<AfterPrepareBody>(&**action).f)(page)
});
}
}

View file

@ -0,0 +1,34 @@
use crate::prelude::*;
use crate::BaseHandle;
use super::FnActionPage;
#[derive(BaseHandle)]
pub struct BeforePrepareBody {
f: FnActionPage,
weight: Weight,
}
impl ActionTrait for BeforePrepareBody {
fn weight(&self) -> Weight {
self.weight
}
}
impl BeforePrepareBody {
pub fn new(f: FnActionPage) -> Self {
BeforePrepareBody { f, weight: 0 }
}
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}
#[inline(always)]
pub(crate) fn dispatch(page: &mut Page) {
dispatch_actions((Self::static_handle(), None, None), |action| {
(action_ref::<BeforePrepareBody>(&**action).f)(page)
});
}
}