2021-09-24 20:11:30 -04:00
|
|
|
/// Configuration for the WebSys renderer for the Dioxus VirtualDOM.
|
|
|
|
///
|
|
|
|
/// This struct helps configure the specifics of hydration and render destination for WebSys.
|
|
|
|
///
|
|
|
|
/// # Example
|
2022-01-13 22:51:01 -05:00
|
|
|
///
|
2021-09-24 20:11:30 -04:00
|
|
|
/// ```rust, ignore
|
2022-09-13 16:22:27 -07:00
|
|
|
/// dioxus_web::launch(App, Config::new().hydrate(true).root_name("myroot"))
|
2021-09-24 20:11:30 -04:00
|
|
|
/// ```
|
2022-09-13 16:22:27 -07:00
|
|
|
pub struct Config {
|
2021-07-28 21:46:53 -04:00
|
|
|
pub(crate) hydrate: bool,
|
2021-08-05 22:23:41 -04:00
|
|
|
pub(crate) rootname: String,
|
2021-12-12 19:47:13 -05:00
|
|
|
pub(crate) cached_strings: Vec<String>,
|
2022-09-13 16:22:27 -07:00
|
|
|
pub(crate) default_panic_hook: bool,
|
2021-07-28 21:46:53 -04:00
|
|
|
}
|
2021-09-24 20:11:30 -04:00
|
|
|
|
2022-09-13 16:22:27 -07:00
|
|
|
impl Default for Config {
|
2021-07-28 21:46:53 -04:00
|
|
|
fn default() -> Self {
|
2021-08-05 22:23:41 -04:00
|
|
|
Self {
|
|
|
|
hydrate: false,
|
2021-11-19 00:49:04 -05:00
|
|
|
rootname: "main".to_string(),
|
2021-12-12 19:47:13 -05:00
|
|
|
cached_strings: Vec::new(),
|
2022-09-13 16:22:27 -07:00
|
|
|
default_panic_hook: true,
|
2021-08-05 22:23:41 -04:00
|
|
|
}
|
2021-07-28 21:46:53 -04:00
|
|
|
}
|
|
|
|
}
|
2021-09-24 20:11:30 -04:00
|
|
|
|
2022-09-13 16:22:27 -07:00
|
|
|
impl Config {
|
|
|
|
/// Create a new Default instance of the Config.
|
|
|
|
///
|
|
|
|
/// This is no different than calling `Config::default()`
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self::default()
|
|
|
|
}
|
|
|
|
|
2021-07-28 21:46:53 -04:00
|
|
|
/// Enable SSR hydration
|
|
|
|
///
|
|
|
|
/// This enables Dioxus to pick up work from a pre-renderd HTML file. Hydration will completely skip over any async
|
|
|
|
/// work and suspended nodes.
|
|
|
|
///
|
|
|
|
/// Dioxus will load up all the elements with the `dio_el` data attribute into memory when the page is loaded.
|
2022-09-13 16:22:27 -07:00
|
|
|
pub fn hydrate(mut self, f: bool) -> Self {
|
2021-07-28 21:46:53 -04:00
|
|
|
self.hydrate = f;
|
|
|
|
self
|
|
|
|
}
|
2021-08-05 22:23:41 -04:00
|
|
|
|
2021-09-24 20:11:30 -04:00
|
|
|
/// Set the name of the element that Dioxus will use as the root.
|
|
|
|
///
|
|
|
|
/// This is akint to calling React.render() on the element with the specified name.
|
2022-09-13 16:22:27 -07:00
|
|
|
pub fn rootname(mut self, name: impl Into<String>) -> Self {
|
2021-08-05 22:23:41 -04:00
|
|
|
self.rootname = name.into();
|
|
|
|
self
|
|
|
|
}
|
2021-12-12 19:47:13 -05:00
|
|
|
|
|
|
|
/// Set the name of the element that Dioxus will use as the root.
|
|
|
|
///
|
|
|
|
/// This is akint to calling React.render() on the element with the specified name.
|
2022-09-13 16:22:27 -07:00
|
|
|
pub fn with_string_cache(mut self, cache: Vec<String>) -> Self {
|
2021-12-12 19:47:13 -05:00
|
|
|
self.cached_strings = cache;
|
|
|
|
self
|
|
|
|
}
|
2022-09-13 16:22:27 -07:00
|
|
|
|
|
|
|
/// Set whether or not Dioxus should use the built-in panic hook or defer to your own.
|
|
|
|
///
|
|
|
|
/// The panic hook is set to true normally so even the simplest apps have helpful error messages.
|
|
|
|
pub fn with_default_panic_hook(mut self, f: bool) -> Self {
|
|
|
|
self.default_panic_hook = f;
|
|
|
|
self
|
|
|
|
}
|
2021-07-28 21:46:53 -04:00
|
|
|
}
|