pub async fn add_dynamic_child(
        realm: &Arc<Self>,
        collection_name: String,
        child_decl: &ChildDecl,
    ) -> Result<(), ModelError> {
        match child_decl.startup {
            fsys::StartupMode::Lazy => {}
            fsys::StartupMode::Eager => {
                return Err(ModelError::unsupported("Eager startup"));
            }
        }
        Realm::resolve_decl(realm).await?;
        let child_realm = {
            let mut state = realm.lock_state().await;
            let state = state.as_mut().expect("add_dynamic_child: not resolved");
            let collection_decl = state
                .decl()
                .find_collection(&collection_name)
                .ok_or_else(|| ModelError::collection_not_found(collection_name.clone()))?;
            match collection_decl.durability {
                fsys::Durability::Transient => {}
                fsys::Durability::Persistent => {
                    return Err(ModelError::unsupported("Persistent durability"));
                }
            }
            if let Some(child_realm) =
                state.add_child_realm(realm, child_decl, Some(collection_name.clone())).await
            {
                child_realm
            } else {
                let partial_moniker =
                    PartialMoniker::new(child_decl.name.clone(), Some(collection_name));
                return Err(ModelError::instance_already_exists(
                    realm.abs_moniker.clone(),
                    partial_moniker,
                ));
            }
        };
        // Call hooks outside of lock
        let event = Event::new(
            child_realm.abs_moniker.clone(),
            EventPayload::AddDynamicChild { component_url: child_realm.component_url.clone() },
        );
        realm.hooks.dispatch(&event).await?;
        Ok(())
    }
/// Adds the dynamic child defined by `child_decl` to the given `collection_name`. Once
/// added, the component instance exists but is not bound.
Adds the dynamic child defined by `child_decl` to the given `collection_name`. Once
added, the component instance exists but is not bound.
Adds the dynamic child defined by ` child_decl ` to the given ` collection_name ` . Once added the component instance exists but is not bound .
pub async fn add_dynamic_child(
        realm: &Arc<Self>,
        collection_name: String,
        child_decl: &ChildDecl,
    ) -> Result<(), ModelError> {
        match child_decl.startup {
            fsys::StartupMode::Lazy => {}
            fsys::StartupMode::Eager => {
                return Err(ModelError::unsupported("Eager startup"));
            }
        }
        Realm::resolve_decl(realm).await?;
        let child_realm = {
            let mut state = realm.lock_state().await;
            let state = state.as_mut().expect("add_dynamic_child: not resolved");
            let collection_decl = state
                .decl()
                .find_collection(&collection_name)
                .ok_or_else(|| ModelError::collection_not_found(collection_name.clone()))?;
            match collection_decl.durability {
                fsys::Durability::Transient => {}
                fsys::Durability::Persistent => {
                    return Err(ModelError::unsupported("Persistent durability"));
                }
            }
            if let Some(child_realm) =
                state.add_child_realm(realm, child_decl, Some(collection_name.clone())).await
            {
                child_realm
            } else {
                let partial_moniker =
                    PartialMoniker::new(child_decl.name.clone(), Some(collection_name));
                return Err(ModelError::instance_already_exists(
                    realm.abs_moniker.clone(),
                    partial_moniker,
                ));
            }
        };
        // Call hooks outside of lock
        let event = Event::new(
            child_realm.abs_moniker.clone(),
            EventPayload::AddDynamicChild { component_url: child_realm.component_url.clone() },
        );
        realm.hooks.dispatch(&event).await?;
        Ok(())
    }
pub async fn add_dynamic_child ( realm : & Arc < Self > , collection_name : String , child_decl : & ChildDecl , ) -> Result < ( ) , ModelError > { match child_decl . startup { fsys :: StartupMode :: Lazy => { } fsys :: StartupMode :: Eager => { return Err ( ModelError :: unsupported ( " " ) ) ; } } Realm :: resolve_decl ( realm ) . await ? ; let child_realm = { let mut state = realm . lock_state ( ) . await ; let state = state . as_mut ( ) . expect ( " " ) ; let collection_decl = state . decl ( ) . find_collection ( & collection_name ) . ok_or_else ( | | ModelError :: collection_not_found ( collection_name . clone ( ) ) ) ? ; match collection_decl . durability { fsys :: Durability :: Transient => { } fsys :: Durability :: Persistent => { return Err ( ModelError :: unsupported ( " " ) ) ; } } if let Some ( child_realm ) = state . add_child_realm ( realm , child_decl , Some ( collection_name . clone ( ) ) ) . await { child_realm } else { let partial_moniker = PartialMoniker :: new ( child_decl . name . clone ( ) , Some ( collection_name ) ) ; return Err ( ModelError :: instance_already_exists ( realm . abs_moniker . clone ( ) , partial_moniker , ) ) ; } } ; // Call hooks outside of lock let event = Event :: new ( child_realm . abs_moniker . clone ( ) , EventPayload :: AddDynamicChild { component_url : child_realm . component_url . clone ( ) } , ) ; realm . hooks . dispatch ( & event ) . await ? ; Ok ( ( ) ) }
Adds the dynamic child defined by `child_decl` to the given `collection_name`.
Adds the dynamic child defined by ` child_decl ` to the given ` collection_name ` .
realm
&Arc<Self>
collection_name
String
child_decl
&ChildDecl