/// Adds a new child of this instance for the given `ChildDecl`. Returns the child, or None if
/// it already existed.
Adds a new child of this instance for the given `ChildDecl`. Returns the child, or None if
it already existed.
Adds a new child of this instance for the given ` ChildDecl ` . Returns the child or None if it already existed .
async fn add_child(
        &mut self,
        component: &Arc<ComponentInstance>,
        child: &ChildDecl,
        collection: Option<&CollectionDecl>,
    ) -> Option<Arc<ComponentInstance>> {
        let instance_id = match collection {
            Some(_) => {
                let id = self.next_dynamic_instance_id;
                self.next_dynamic_instance_id += 1;
                id
            }
            None => 0,
        };
        let child_moniker =
            ChildMoniker::new(child.name.clone(), collection.map(|c| c.name.clone()), instance_id);
        let partial_moniker = child_moniker.to_partial();
        if self.get_live_child(&partial_moniker).is_none() {
            let child = ComponentInstance::new(
                self.environment_for_child(component, child, collection.clone()),
                component.abs_moniker.child(child_moniker.clone()),
                child.url.clone(),
                child.startup,
                component.context.clone(),
                WeakExtendedInstance::Component(WeakComponentInstance::from(component)),
                Arc::new(Hooks::new(Some(component.hooks.clone()))),
            );
            self.children.insert(child_moniker, child.clone());
            self.live_children.insert(partial_moniker, (instance_id, child.clone()));
            // We can dispatch a Discovered event for the component now that it's installed in the
            // tree, which means any Discovered hooks will capture it.
            {
                let mut actions = child.lock_actions().await;
                let _ = actions.register_no_wait(&child, DiscoverAction::new());
            }
            Some(child)
        } else {
            None
        }
    }
async fn add_child ( & mut self , component : & Arc < ComponentInstance > , child : & ChildDecl , collection : Option < & CollectionDecl > , ) -> Option < Arc < ComponentInstance > > { let instance_id = match collection { Some ( _ ) => { let id = self . next_dynamic_instance_id ; self . next_dynamic_instance_id += 1 ; id } None => 0 , } ; let child_moniker = ChildMoniker :: new ( child . name . clone ( ) , collection . map ( | c | c . name . clone ( ) ) , instance_id ) ; let partial_moniker = child_moniker . to_partial ( ) ; if self . get_live_child ( & partial_moniker ) . is_none ( ) { let child = ComponentInstance :: new ( self . environment_for_child ( component , child , collection . clone ( ) ) , component . abs_moniker . child ( child_moniker . clone ( ) ) , child . url . clone ( ) , child . startup , component . context . clone ( ) , WeakExtendedInstance :: Component ( WeakComponentInstance :: from ( component ) ) , Arc :: new ( Hooks :: new ( Some ( component . hooks . clone ( ) ) ) ) , ) ; self . children . insert ( child_moniker , child . clone ( ) ) ; self . live_children . insert ( partial_moniker , ( instance_id , child . clone ( ) ) ) ; // We can dispatch a Discovered event for the component now that it's installed in the // tree, which means any Discovered hooks will capture it. { let mut actions = child . lock_actions ( ) . await ; let _ = actions . register_no_wait ( & child , DiscoverAction :: new ( ) ) ; } Some ( child ) } else { None } }
Adds a new child of this instance for the given `ChildDecl`.
Adds a new child of this instance for the given ` ChildDecl ` .
&mut self
component
&Arc<ComponentInstance>
child
&ChildDecl
collection
Option<&CollectionDecl>