use std::rc::Rc;
use dioxus_core::LaunchConfig;
use wasm_bindgen::JsCast as _;
pub struct Config {
pub(crate) hydrate: bool,
#[allow(dead_code)]
pub(crate) panic_hook: bool,
pub(crate) root: ConfigRoot,
#[cfg(feature = "document")]
pub(crate) history: Option<Rc<dyn dioxus_history::History>>,
}
impl LaunchConfig for Config {}
pub(crate) enum ConfigRoot {
RootName(String),
RootNode(web_sys::Node),
}
impl Config {
pub fn new() -> Self {
Self::default()
}
#[cfg(feature = "hydrate")]
pub fn hydrate(mut self, f: bool) -> Self {
self.hydrate = f;
self
}
pub fn rootname(mut self, name: impl Into<String>) -> Self {
self.root = ConfigRoot::RootName(name.into());
self
}
pub fn rootelement(mut self, elem: web_sys::Element) -> Self {
self.root = ConfigRoot::RootNode(elem.unchecked_into());
self
}
pub fn rootnode(mut self, node: web_sys::Node) -> Self {
self.root = ConfigRoot::RootNode(node);
self
}
pub fn history(mut self, history: Rc<dyn dioxus_history::History>) -> Self {
#[cfg(feature = "document")]
{
self.history = Some(history);
}
self
}
}
impl Default for Config {
fn default() -> Self {
Self {
hydrate: false,
root: ConfigRoot::RootName("main".to_string()),
#[cfg(feature = "document")]
history: None,
panic_hook: true,
}
}
}