Simplify the launch builder (#2967)

* improve documentation for the fullstack server context

* Add a section about axum integration to the crate root docs

* make serve_dioxus_application accept the cfg builder directly

* remove unused server_fn module

* improve fullstack config docs

* improve documentation for the server function macro

* fix axum router extension link

* Fix doc tests

* Fix launch builder

* Simplify the launch builder

* don't re-export launch in the prelude

* refactor fullstack launch

* Fix fullstack launch builder

* Update static generation with the new builder api

* fix some formatting/overly broad launch replacements

* fix custom menu example

* fix fullstack/static generation examples

* Fix static generation launch

* A few small formatting fixes

* Fix a few doc tests

* implement LaunchConfig for serve configs

* fix fullstack launch with separate web and server launch methods

* fix check with all features

* dont expose inner core module

* clippy and check

* fix readme

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Evan AlmloffandJonathan Kelley authored and GitHub committed 2024-10-10 16:00:58 -07:00
1 parent 2d7bef44e8
commit 20d146d9bd
126 files changed
+618 -989

No files matched your search

+3
View File
@@ -1,3 +1,4 @@
use dioxus_core::LaunchConfig;
use wasm_bindgen::JsCast as _;
/// Configuration for the WebSys renderer for the Dioxus VirtualDOM.
@@ -15,6 +16,8 @@ pub struct Config {
pub(crate) default_panic_hook: bool,
}
impl LaunchConfig for Config {}
pub(crate) enum ConfigRoot {
RootName(String),
RootNode(web_sys::Node),
+7 -3
View File
@@ -9,13 +9,17 @@ use std::any::Any;
/// For a builder API, see `LaunchBuilder` defined in the `dioxus` crate.
pub fn launch(
root: fn() -> Element,
contexts: Vec<Box<dyn Fn() -> Box<dyn Any>>>,
platform_config: Config,
contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
platform_config: Vec<Box<dyn Any>>,
) {
let mut vdom = VirtualDom::new(root);
for context in contexts {
vdom.insert_any_root_context(context());
}
let platform_config = *platform_config
.into_iter()
.find_map(|cfg| cfg.downcast::<Config>().ok())
.unwrap_or_default();
launch_virtual_dom(vdom, platform_config)
}
@@ -30,5 +34,5 @@ pub fn launch_virtual_dom(vdom: VirtualDom, platform_config: Config) {
/// Launch the web application with the given root component and config
pub fn launch_cfg(root: fn() -> Element, platform_config: Config) {
launch(root, Vec::new(), platform_config);
launch(root, Vec::new(), vec![Box::new(platform_config)])
}