|
@@ -5,6 +5,34 @@ use dioxus_lib::prelude::*;
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
/// Settings for a fullstack app.
|
|
|
+///
|
|
|
+/// Depending on what features are enabled, you can pass in configurations for each client platform as well as the server:
|
|
|
+/// ```rust, no_run
|
|
|
+/// # fn app() -> Element { todo!() }
|
|
|
+/// use dioxus::prelude::*;
|
|
|
+///
|
|
|
+/// let mut cfg = dioxus::fullstack::Config::new();
|
|
|
+///
|
|
|
+/// // Only set the server config if the server feature is enabled
|
|
|
+/// server_only! {
|
|
|
+/// cfg = cfg.with_server_config(ServeConfigBuilder::default());
|
|
|
+/// }
|
|
|
+///
|
|
|
+/// // Only set the web config if the web feature is enabled
|
|
|
+/// web! {
|
|
|
+/// cfg = cfg.with_web_config(dioxus::web::Config::default());
|
|
|
+/// }
|
|
|
+///
|
|
|
+/// // Only set the desktop config if the desktop feature is enabled
|
|
|
+/// desktop! {
|
|
|
+/// cfg = cfg.with_desktop_config(dioxus::desktop::Config::default());
|
|
|
+/// }
|
|
|
+///
|
|
|
+/// // Finally, launch the app with the config
|
|
|
+/// LaunchBuilder::new()
|
|
|
+/// .with_cfg(cfg)
|
|
|
+/// .launch(app);
|
|
|
+/// ```
|
|
|
pub struct Config {
|
|
|
#[cfg(feature = "server")]
|
|
|
pub(crate) server_cfg: ServeConfigBuilder,
|
|
@@ -41,7 +69,25 @@ impl Config {
|
|
|
Self::default()
|
|
|
}
|
|
|
|
|
|
- /// Set the incremental renderer config.
|
|
|
+ /// Set the incremental renderer config. The incremental config can be used to improve
|
|
|
+ /// performance of heavy routes by caching the rendered html in memory and/or the file system.
|
|
|
+ ///
|
|
|
+ /// ```rust, no_run
|
|
|
+ /// # fn app() -> Element { todo!() }
|
|
|
+ /// use dioxus::prelude::*;
|
|
|
+ ///
|
|
|
+ /// let mut cfg = dioxus::fullstack::Config::new();
|
|
|
+ ///
|
|
|
+ /// // Only set the server config if the server feature is enabled
|
|
|
+ /// server_only! {
|
|
|
+ /// cfg = cfg.incremental(IncrementalRendererConfig::default().with_memory_cache_limit(10000));
|
|
|
+ /// }
|
|
|
+ ///
|
|
|
+ /// // Finally, launch the app with the config
|
|
|
+ /// LaunchBuilder::new()
|
|
|
+ /// .with_cfg(cfg)
|
|
|
+ /// .launch(app);
|
|
|
+ /// ```
|
|
|
#[cfg(feature = "server")]
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
|
|
|
pub fn incremental(self, cfg: IncrementalRendererConfig) -> Self {
|
|
@@ -51,28 +97,94 @@ impl Config {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// Set the server config.
|
|
|
+ /// Set the server config
|
|
|
+ /// ```rust, no_run
|
|
|
+ /// # fn app() -> Element { todo!() }
|
|
|
+ /// use dioxus::prelude::*;
|
|
|
+ ///
|
|
|
+ /// let mut cfg = dioxus::fullstack::Config::new();
|
|
|
+ ///
|
|
|
+ /// // Only set the server config if the server feature is enabled
|
|
|
+ /// server_only! {
|
|
|
+ /// cfg = cfg.with_server_config(ServeConfigBuilder::default());
|
|
|
+ /// }
|
|
|
+ ///
|
|
|
+ /// // Finally, launch the app with the config
|
|
|
+ /// LaunchBuilder::new()
|
|
|
+ /// .with_cfg(cfg)
|
|
|
+ /// .launch(app);
|
|
|
+ /// ```
|
|
|
#[cfg(feature = "server")]
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
|
|
|
- pub fn with_server_cfg(self, server_cfg: ServeConfigBuilder) -> Self {
|
|
|
+ pub fn with_server_config(self, server_cfg: ServeConfigBuilder) -> Self {
|
|
|
Self { server_cfg, ..self }
|
|
|
}
|
|
|
|
|
|
- /// Set the server config.
|
|
|
+ /// Set the server config by modifying the config in place
|
|
|
+ ///
|
|
|
+ /// ```rust, no_run
|
|
|
+ /// # fn app() -> Element { todo!() }
|
|
|
+ /// use dioxus::prelude::*;
|
|
|
+ ///
|
|
|
+ /// let mut cfg = dioxus::fullstack::Config::new();
|
|
|
+ ///
|
|
|
+ /// // Only set the server config if the server feature is enabled
|
|
|
+ /// server_only! {
|
|
|
+ /// cfg.set_server_config(ServeConfigBuilder::default());
|
|
|
+ /// }
|
|
|
+ ///
|
|
|
+ /// // Finally, launch the app with the config
|
|
|
+ /// LaunchBuilder::new()
|
|
|
+ /// .with_cfg(cfg)
|
|
|
+ /// .launch(app);
|
|
|
+ /// ```
|
|
|
#[cfg(feature = "server")]
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
|
|
|
- pub fn set_server_cfg(&mut self, server_cfg: ServeConfigBuilder) {
|
|
|
+ pub fn set_server_config(&mut self, server_cfg: ServeConfigBuilder) {
|
|
|
self.server_cfg = server_cfg;
|
|
|
}
|
|
|
|
|
|
- /// Set the web config.
|
|
|
+ /// Set the web config
|
|
|
+ /// ```rust, no_run
|
|
|
+ /// # fn app() -> Element { todo!() }
|
|
|
+ /// use dioxus::prelude::*;
|
|
|
+ ///
|
|
|
+ /// let mut cfg = dioxus::fullstack::Config::new();
|
|
|
+ ///
|
|
|
+ /// // Only set the web config if the server feature is enabled
|
|
|
+ /// web! {
|
|
|
+ /// cfg = cfg.with_web_config(dioxus::web::Config::default());
|
|
|
+ /// }
|
|
|
+ ///
|
|
|
+ /// // Finally, launch the app with the config
|
|
|
+ /// LaunchBuilder::new()
|
|
|
+ /// .with_cfg(cfg)
|
|
|
+ /// .launch(app);
|
|
|
+ /// ```
|
|
|
#[cfg(feature = "web")]
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "web")))]
|
|
|
pub fn with_web_config(self, web_cfg: dioxus_web::Config) -> Self {
|
|
|
Self { web_cfg, ..self }
|
|
|
}
|
|
|
|
|
|
- /// Set the web config.
|
|
|
+ /// Set the server config by modifying the config in place
|
|
|
+ ///
|
|
|
+ /// ```rust, no_run
|
|
|
+ /// # fn app() -> Element { todo!() }
|
|
|
+ /// use dioxus::prelude::*;
|
|
|
+ ///
|
|
|
+ /// let mut cfg = dioxus::fullstack::Config::new();
|
|
|
+ ///
|
|
|
+ /// // Only set the web config if the server feature is enabled
|
|
|
+ /// web! {
|
|
|
+ /// cfg.set_web_config(dioxus::web::Config::default());
|
|
|
+ /// }
|
|
|
+ ///
|
|
|
+ /// // Finally, launch the app with the config
|
|
|
+ /// LaunchBuilder::new()
|
|
|
+ /// .with_cfg(cfg)
|
|
|
+ /// .launch(app);
|
|
|
+ /// ```
|
|
|
#[cfg(feature = "web")]
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "web")))]
|
|
|
pub fn set_web_config(&mut self, web_cfg: dioxus_web::Config) {
|
|
@@ -80,6 +192,22 @@ impl Config {
|
|
|
}
|
|
|
|
|
|
/// Set the desktop config
|
|
|
+ /// ```rust, no_run
|
|
|
+ /// # fn app() -> Element { todo!() }
|
|
|
+ /// use dioxus::prelude::*;
|
|
|
+ ///
|
|
|
+ /// let mut cfg = dioxus::fullstack::Config::new();
|
|
|
+ ///
|
|
|
+ /// // Only set the desktop config if the server feature is enabled
|
|
|
+ /// desktop! {
|
|
|
+ /// cfg = cfg.with_desktop_config(dioxus::desktop::Config::default());
|
|
|
+ /// }
|
|
|
+ ///
|
|
|
+ /// // Finally, launch the app with the config
|
|
|
+ /// LaunchBuilder::new()
|
|
|
+ /// .with_cfg(cfg)
|
|
|
+ /// .launch(app);
|
|
|
+ /// ```
|
|
|
#[cfg(feature = "desktop")]
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "desktop")))]
|
|
|
pub fn with_desktop_config(self, desktop_cfg: dioxus_desktop::Config) -> Self {
|
|
@@ -89,17 +217,73 @@ impl Config {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// Set the desktop config.
|
|
|
+ /// Set the desktop config by modifying the config in place
|
|
|
+ ///
|
|
|
+ /// ```rust, no_run
|
|
|
+ /// # fn app() -> Element { todo!() }
|
|
|
+ /// use dioxus::prelude::*;
|
|
|
+ ///
|
|
|
+ /// let mut cfg = dioxus::fullstack::Config::new();
|
|
|
+ ///
|
|
|
+ /// // Only set the desktop config if the server feature is enabled
|
|
|
+ /// desktop! {
|
|
|
+ /// cfg.set_desktop_config(dioxus::desktop::Config::default());
|
|
|
+ /// }
|
|
|
+ ///
|
|
|
+ /// // Finally, launch the app with the config
|
|
|
+ /// LaunchBuilder::new()
|
|
|
+ /// .with_cfg(cfg)
|
|
|
+ /// .launch(app);
|
|
|
+ /// ```
|
|
|
#[cfg(feature = "desktop")]
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "desktop")))]
|
|
|
pub fn set_desktop_config(&mut self, desktop_cfg: dioxus_desktop::Config) {
|
|
|
self.desktop_cfg = desktop_cfg;
|
|
|
}
|
|
|
|
|
|
+ /// Set the mobile config
|
|
|
+ /// ```rust, no_run
|
|
|
+ /// # fn app() -> Element { todo!() }
|
|
|
+ /// use dioxus::prelude::*;
|
|
|
+ ///
|
|
|
+ /// let mut cfg = dioxus::fullstack::Config::new();
|
|
|
+ ///
|
|
|
+ /// // Only set the mobile config if the server feature is enabled
|
|
|
+ /// mobile! {
|
|
|
+ /// cfg = cfg.with_mobile_cfg(dioxus::mobile::Config::default());
|
|
|
+ /// }
|
|
|
+ ///
|
|
|
+ /// // Finally, launch the app with the config
|
|
|
+ /// LaunchBuilder::new()
|
|
|
+ /// .with_cfg(cfg)
|
|
|
+ /// .launch(app);
|
|
|
/// Set the mobile config.
|
|
|
#[cfg(feature = "mobile")]
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "mobile")))]
|
|
|
pub fn with_mobile_cfg(self, mobile_cfg: dioxus_mobile::Config) -> Self {
|
|
|
Self { mobile_cfg, ..self }
|
|
|
}
|
|
|
+
|
|
|
+ /// Set the mobile config by modifying the config in place
|
|
|
+ /// ```rust, no_run
|
|
|
+ /// # fn app() -> Element { todo!() }
|
|
|
+ /// use dioxus::prelude::*;
|
|
|
+ ///
|
|
|
+ /// let mut cfg = dioxus::fullstack::Config::new();
|
|
|
+ ///
|
|
|
+ /// // Only set the mobile config if the server feature is enabled
|
|
|
+ /// mobile! {
|
|
|
+ /// cfg.set_mobile_cfg(dioxus::mobile::Config::default());
|
|
|
+ /// }
|
|
|
+ ///
|
|
|
+ /// // Finally, launch the app with the config
|
|
|
+ /// LaunchBuilder::new()
|
|
|
+ /// .with_cfg(cfg)
|
|
|
+ /// .launch(app);
|
|
|
+ /// Set the mobile config.
|
|
|
+ #[cfg(feature = "mobile")]
|
|
|
+ #[cfg_attr(docsrs, doc(cfg(feature = "mobile")))]
|
|
|
+ pub fn set_mobile_cfg(&mut self, mobile_cfg: dioxus_mobile::Config) {
|
|
|
+ self.mobile_cfg = mobile_cfg;
|
|
|
+ }
|
|
|
}
|