pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T, cfg: WebConfig) {
    let mut dom = VirtualDom::new_with_props(root, root_props);

    for s in crate::cache::BUILTIN_INTERNED_STRINGS {
        wasm_bindgen::intern(s);
    }
    for s in &cfg.cached_strings {
        wasm_bindgen::intern(s);
    }

    let tasks = dom.get_scheduler_channel();

    let sender_callback: Rc<dyn Fn(SchedulerMsg)> =
        Rc::new(move |event| tasks.unbounded_send(event).unwrap());

    let should_hydrate = cfg.hydrate;

    let mut websys_dom = dom::WebsysDom::new(cfg, sender_callback);

    log::trace!("rebuilding app");

    if should_hydrate {
        // todo: we need to split rebuild and initialize into two phases
        // it's a waste to produce edits just to get the vdom loaded
        let _ = dom.rebuild();

        if let Err(err) = websys_dom.rehydrate(&dom) {
            log::error!(
                "Rehydration failed {:?}. Rebuild DOM into element from scratch",
                &err
            );

            websys_dom.root.set_text_content(None);

            // errrrr we should split rebuild into two phases
            // one that initializes things and one that produces edits
            let edits = dom.rebuild();

            websys_dom.apply_edits(edits.edits);
        }
    } else {
        let edits = dom.rebuild();
        websys_dom.apply_edits(edits.edits);
    }

    let work_loop = ric_raf::RafLoop::new();

    loop {
        log::trace!("waiting for work");
        // if virtualdom has nothing, wait for it to have something before requesting idle time
        // if there is work then this future resolves immediately.
        dom.wait_for_work().await;

        log::trace!("working..");

        // wait for the mainthread to schedule us in
        let mut deadline = work_loop.wait_for_idle_time().await;

        // run the virtualdom work phase until the frame deadline is reached
        let mutations = dom.work_with_deadline(|| (&mut deadline).now_or_never().is_some());

        // wait for the animation frame to fire so we can apply our changes
        work_loop.wait_for_raf().await;

        for edit in mutations {
            // actually apply our changes during the animation frame
            websys_dom.apply_edits(edit.edits);
        }
    }
}
/// Runs the app as a future that can be scheduled around the main thread.
///
/// Polls futures internal to the VirtualDOM, hence the async nature of this function.
///
/// # Example
///
/// ```ignore
/// fn main() {
///     let app_fut = dioxus_web::run_with_props(App, RootProps { name: String::from("joe") });
///     wasm_bindgen_futures::spawn_local(app_fut);
/// }
/// ```
Runs the app as a future that can be scheduled around the main thread.
Polls futures internal to the VirtualDOM, hence the async nature of this function.
Runs the app as a future that can be scheduled around the main thread . Polls futures internal to the VirtualDOM hence the async nature of this function .
pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T, cfg: WebConfig) {
    let mut dom = VirtualDom::new_with_props(root, root_props);
    for s in crate::cache::BUILTIN_INTERNED_STRINGS {
        wasm_bindgen::intern(s);
    }
    for s in &cfg.cached_strings {
        wasm_bindgen::intern(s);
    }
    let tasks = dom.get_scheduler_channel();
    let sender_callback: Rc<dyn Fn(SchedulerMsg)> =
        Rc::new(move |event| tasks.unbounded_send(event).unwrap());
    let should_hydrate = cfg.hydrate;
    let mut websys_dom = dom::WebsysDom::new(cfg, sender_callback);
    log::trace!("rebuilding app");
    if should_hydrate {
        // todo: we need to split rebuild and initialize into two phases
        // it's a waste to produce edits just to get the vdom loaded
        let _ = dom.rebuild();
        if let Err(err) = websys_dom.rehydrate(&dom) {
            log::error!(
                "Rehydration failed {:?}. Rebuild DOM into element from scratch",
                &err
            );
            websys_dom.root.set_text_content(None);
            // errrrr we should split rebuild into two phases
            // one that initializes things and one that produces edits
            let edits = dom.rebuild();
            websys_dom.apply_edits(edits.edits);
        }
    } else {
        let edits = dom.rebuild();
        websys_dom.apply_edits(edits.edits);
    }
    let work_loop = ric_raf::RafLoop::new();
    loop {
        log::trace!("waiting for work");
        // if virtualdom has nothing, wait for it to have something before requesting idle time
        // if there is work then this future resolves immediately.
        dom.wait_for_work().await;
        log::trace!("working..");
        // wait for the mainthread to schedule us in
        let mut deadline = work_loop.wait_for_idle_time().await;
        // run the virtualdom work phase until the frame deadline is reached
        let mutations = dom.work_with_deadline(|| (&mut deadline).now_or_never().is_some());
        // wait for the animation frame to fire so we can apply our changes
        work_loop.wait_for_raf().await;
        for edit in mutations {
            // actually apply our changes during the animation frame
            websys_dom.apply_edits(edit.edits);
        }
    }
}
pub async fn run_with_props < T : ' static + Send > ( root : Component < T > , root_props : T , cfg : WebConfig ) { let mut dom = VirtualDom :: new_with_props ( root , root_props ) ; for s in crate :: cache :: BUILTIN_INTERNED_STRINGS { wasm_bindgen :: intern ( s ) ; } for s in & cfg . cached_strings { wasm_bindgen :: intern ( s ) ; } let tasks = dom . get_scheduler_channel ( ) ; let sender_callback : Rc < dyn Fn ( SchedulerMsg ) > = Rc :: new ( move | event | tasks . unbounded_send ( event ) . unwrap ( ) ) ; let should_hydrate = cfg . hydrate ; let mut websys_dom = dom :: WebsysDom :: new ( cfg , sender_callback ) ; log :: trace ! ( " " ) ; if should_hydrate { // todo: we need to split rebuild and initialize into two phases // it's a waste to produce edits just to get the vdom loaded let _ = dom . rebuild ( ) ; if let Err ( err ) = websys_dom . rehydrate ( & dom ) { log :: error ! ( " " err ) ; websys_dom . root . set_text_content ( None ) ; // errrrr we should split rebuild into two phases // one that initializes things and one that produces edits let edits = dom . rebuild ( ) ; websys_dom . apply_edits ( edits . edits ) ; } } else { let edits = dom . rebuild ( ) ; websys_dom . apply_edits ( edits . edits ) ; } let work_loop = ric_raf :: RafLoop :: new ( ) ; loop { log :: trace ! ( " " ) ; // if virtualdom has nothing, wait for it to have something before requesting idle time // if there is work then this future resolves immediately. dom . wait_for_work ( ) . await ; log :: trace ! ( " " ) ; // wait for the mainthread to schedule us in let mut deadline = work_loop . wait_for_idle_time ( ) . await ; // run the virtualdom work phase until the frame deadline is reached let mutations = dom . work_with_deadline ( | | ( & mut deadline ) . now_or_never ( ) . is_some ( ) ) ; // wait for the animation frame to fire so we can apply our changes work_loop . wait_for_raf ( ) . await ; for edit in mutations { // actually apply our changes during the animation frame websys_dom . apply_edits ( edit . edits ) ; } } }
Runs the app as a future that can be scheduled around the main thread.
Runs the app as a future that can be scheduled around the main thread .
root
Component<T>
root_props
T
cfg
WebConfig
example
```ignore
fn main() {
let app_fut = dioxus_web::run_with_props(App, RootProps { name: String::from("joe") });
wasm_bindgen_futures::spawn_local(app_fut);
}
```
` ` ` ignore fn main () { let app_fut = dioxus_web :: run_with_props ( App RootProps { name : String :: from ( " joe " ) } ) ; wasm_bindgen_futures :: spawn_local ( app_fut ) ; } ` ` `