@@ -107,27 +107,48 @@ impl ScopeContext {
107107 ///
108108 /// Clones the state if it exists.
109109 pub fn consume_context < T : ' static + Clone > ( & self ) -> Option < T > {
110+ tracing:: trace!(
111+ "looking for context {} ({:?}) in {}" ,
112+ std:: any:: type_name:: <T >( ) ,
113+ std:: any:: TypeId :: of:: <T >( ) ,
114+ self . name
115+ ) ;
110116 if let Some ( this_ctx) = self . has_context ( ) {
111117 return Some ( this_ctx) ;
112118 }
113119
114120 let mut search_parent = self . parent_id ;
115- with_runtime ( |runtime| {
121+ match with_runtime ( |runtime : & crate :: runtime :: Runtime | {
116122 while let Some ( parent_id) = search_parent {
117123 let parent = runtime. get_context ( parent_id) . unwrap ( ) ;
118- if let Some ( shared) = parent
119- . shared_contexts
120- . borrow ( )
121- . iter ( )
122- . find_map ( |any| any. downcast_ref :: < T > ( ) )
123- {
124+ tracing:: trace!(
125+ "looking for context {} ({:?}) in {}" ,
126+ std:: any:: type_name:: <T >( ) ,
127+ std:: any:: TypeId :: of:: <T >( ) ,
128+ parent. name
129+ ) ;
130+ if let Some ( shared) = parent. shared_contexts . borrow ( ) . iter ( ) . find_map ( |any| {
131+ tracing:: trace!( "found context {:?}" , any. type_id( ) ) ;
132+ any. downcast_ref :: < T > ( )
133+ } ) {
124134 return Some ( shared. clone ( ) ) ;
125135 }
126136 search_parent = parent. parent_id ;
127137 }
128138 None
129139 } )
130140 . flatten ( )
141+ {
142+ Some ( ctx) => Some ( ctx) ,
143+ None => {
144+ tracing:: trace!(
145+ "context {} ({:?}) not found" ,
146+ std:: any:: type_name:: <T >( ) ,
147+ std:: any:: TypeId :: of:: <T >( )
148+ ) ;
149+ None
150+ }
151+ }
131152 }
132153
133154 /// Expose state to children further down the [`crate::VirtualDom`] Tree. Requires `Clone` on the context to allow getting values down the tree.
@@ -152,6 +173,12 @@ impl ScopeContext {
152173 /// }
153174 /// ```
154175 pub fn provide_context < T : ' static + Clone > ( & self , value : T ) -> T {
176+ tracing:: trace!(
177+ "providing context {} ({:?}) in {}" ,
178+ std:: any:: type_name:: <T >( ) ,
179+ std:: any:: TypeId :: of:: <T >( ) ,
180+ self . name
181+ ) ;
155182 let mut contexts = self . shared_contexts . borrow_mut ( ) ;
156183
157184 // If the context exists, swap it out for the new value
0 commit comments