@@ -3,24 +3,21 @@ use crate::prelude::*;
33use super :: FnAction ;
44
55pub struct BeforePrepareComponent < C : ComponentTrait > {
6- action : Option < FnAction < C > > ,
7- referer : Option < Handle > ,
6+ f : Option < FnAction < C > > ,
7+ referer_handle : Option < Handle > ,
8+ referer_id : OptionId ,
89 weight : Weight ,
910}
1011
1112impl_handle ! ( ACTION_BEFORE_PREPARE_COMPONENT for BeforePrepareComponent <ComponentTrait >) ;
1213
1314impl < C : ComponentTrait > ActionTrait for BeforePrepareComponent < C > {
14- fn new ( ) -> Self {
15- BeforePrepareComponent {
16- action : None ,
17- referer : Some ( C :: static_handle ( ) ) ,
18- weight : 0 ,
19- }
15+ fn referer_handle ( & self ) -> Option < Handle > {
16+ self . referer_handle
2017 }
2118
22- fn referer_handle ( & self ) -> Option < Handle > {
23- self . referer
19+ fn referer_id ( & self ) -> Option < String > {
20+ self . referer_id . get ( )
2421 }
2522
2623 fn weight ( & self ) -> Weight {
@@ -29,33 +26,38 @@ impl<C: ComponentTrait> ActionTrait for BeforePrepareComponent<C> {
2926}
3027
3128impl < C : ComponentTrait > BeforePrepareComponent < C > {
32- pub fn with ( action : FnAction < C > ) -> Self {
29+ pub fn with ( f : FnAction < C > ) -> Self {
3330 BeforePrepareComponent {
34- action : Some ( action) ,
35- referer : Some ( C :: static_handle ( ) ) ,
31+ f : Some ( f) ,
32+ referer_handle : Some ( C :: static_handle ( ) ) ,
33+ referer_id : OptionId :: default ( ) ,
3634 weight : 0 ,
3735 }
3836 }
3937
38+ pub fn filtering_id ( mut self , id : impl Into < String > ) -> Self {
39+ self . referer_id . alter_value ( id) ;
40+ self
41+ }
42+
4043 pub fn with_weight ( mut self , value : Weight ) -> Self {
4144 self . weight = value;
4245 self
4346 }
4447
45- pub ( crate ) fn run ( & self , component : & mut C , cx : & mut Context ) {
46- if let Some ( action) = self . action {
47- action ( component, cx)
48- }
48+ #[ inline( always) ]
49+ pub ( crate ) fn dispatch ( component : & mut C , cx : & mut Context , id : Option < String > ) {
50+ dispatch_actions (
51+ (
52+ ACTION_BEFORE_PREPARE_COMPONENT ,
53+ Some ( component. handle ( ) ) ,
54+ id,
55+ ) ,
56+ |action| {
57+ if let Some ( f) = action_ref :: < BeforePrepareComponent < C > > ( & * * action) . f {
58+ f ( component, cx)
59+ }
60+ } ,
61+ ) ;
4962 }
5063}
51-
52- #[ inline( always) ]
53- pub ( crate ) fn run_actions_before_prepare_component < C : ComponentTrait > (
54- component : & mut C ,
55- cx : & mut Context ,
56- ) {
57- run_actions (
58- ( ACTION_BEFORE_PREPARE_COMPONENT , Some ( component. handle ( ) ) ) ,
59- |action| action_ref :: < BeforePrepareComponent < C > > ( & * * action) . run ( component, cx) ,
60- ) ;
61- }
0 commit comments