pub fn load_js_module(mut code: String) -> Result<PendingScript, DivError> {
    let window = web_sys::window().ok_or(DivError::MissingWindow)?;
    let doc = window.document().ok_or(DivError::MissingDocument)?;
    let script: HtmlScriptElement = doc
        .create_element("script")?
        .dyn_into()
        .map_err(|_| DivError::JsCastError)?;
    script.set_attribute("type", "module")?;
    code += "\nwindow.__div_rs = window.__div_rs || {};";
    code += "\nwindow.__div_rs.loaded = (window.div.loaded || 0) + 1;";
    script.set_text(&code)?;

    let head = doc.head().ok_or(DivError::MissingHead)?;
    head.append_child(&script)?;

    // At this point, everything is set up for the event loop to load our script in the future.
    // We can poll this simple future to check when that is done.
    let ticket = LOADED.fetch_add(1, Ordering::Relaxed);
    Ok(PendingScript { ticket })
}
/// **Experimental: This API is experimental and my not be included in later versions**
/// Asynchronously loads a JS module by appending a script tag to the head with th e provided string as content.
/// Poll the future until it resolves to know when the script has been loaded for sure.
/// In contrast to the more conventional Future design, the JS module will be loaded even if the Future is not polled.
/// The Future only checks if it has already finished.
This API is experimental and my not be included in later versions
Asynchronously loads a JS module by appending a script tag to the head with th e provided string as content.
Poll the future until it resolves to know when the script has been loaded for sure.
In contrast to the more conventional Future design, the JS module will be loaded even if the Future is not polled.
The Future only checks if it has already finished.
This API is experimental and my not be included in later versions Asynchronously loads a JS module by appending a script tag to the head with th e provided string as content . Poll the future until it resolves to know when the script has been loaded for sure . In contrast to the more conventional Future design the JS module will be loaded even if the Future is not polled . The Future only checks if it has already finished .
pub fn load_js_module(mut code: String) -> Result<PendingScript, DivError> {
    let window = web_sys::window().ok_or(DivError::MissingWindow)?;
    let doc = window.document().ok_or(DivError::MissingDocument)?;
    let script: HtmlScriptElement = doc
        .create_element("script")?
        .dyn_into()
        .map_err(|_| DivError::JsCastError)?;
    script.set_attribute("type", "module")?;
    code += "\nwindow.__div_rs = window.__div_rs || {};";
    code += "\nwindow.__div_rs.loaded = (window.div.loaded || 0) + 1;";
    script.set_text(&code)?;
    let head = doc.head().ok_or(DivError::MissingHead)?;
    head.append_child(&script)?;
    // At this point, everything is set up for the event loop to load our script in the future.
    // We can poll this simple future to check when that is done.
    let ticket = LOADED.fetch_add(1, Ordering::Relaxed);
    Ok(PendingScript { ticket })
}
pub fn load_js_module ( mut code : String ) -> Result < PendingScript , DivError > { let window = web_sys :: window ( ) . ok_or ( DivError :: MissingWindow ) ? ; let doc = window . document ( ) . ok_or ( DivError :: MissingDocument ) ? ; let script : HtmlScriptElement = doc . create_element ( " " ) ? . dyn_into ( ) . map_err ( | _ | DivError :: JsCastError ) ? ; script . set_attribute ( " " , " " ) ? ; code += " \n " ; code += " \n " ; script . set_text ( & code ) ? ; let head = doc . head ( ) . ok_or ( DivError :: MissingHead ) ? ; head . append_child ( & script ) ? ; // At this point, everything is set up for the event loop to load our script in the future. // We can poll this simple future to check when that is done. let ticket = LOADED . fetch_add ( 1 , Ordering :: Relaxed ) ; Ok ( PendingScript { ticket } ) }
Experimental: This API is experimental and my not be included in later versions
Asynchronously loads a JS module by appending a script tag to the head with th e provided string as content.
Experimental : This API is experimental and my not be included in later versions Asynchronously loads a JS module by appending a script tag to the head with th e provided string as content .
code
String
code
String