make fullstack hello world compile
This commit is contained in:
1 parent
499e81fa82
commit
ae3e167cfe
19 files changed
+288
-155
No files matched your search
@@ -25,6 +25,8 @@ dioxus-fullstack = { workspace = true, optional = true }
|
||||
dioxus-liveview = { workspace = true, optional = true }
|
||||
# dioxus-tui = { workspace = true, optional = true }
|
||||
|
||||
serde = { version = "1.0.136", optional = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
dioxus-hot-reload = { workspace = true, optional = true }
|
||||
|
||||
@@ -40,11 +42,14 @@ launch = ["dioxus-config-macro"]
|
||||
router = ["dioxus-router"]
|
||||
|
||||
# Platforms
|
||||
fullstack = ["dioxus-fullstack", "dioxus-config-macro/fullstack"]
|
||||
fullstack = ["dioxus-fullstack", "dioxus-config-macro/fullstack", "serde"]
|
||||
desktop = ["dioxus-desktop", "dioxus-fullstack?/desktop", "dioxus-config-macro/desktop"]
|
||||
web = ["dioxus-web", "dioxus-fullstack?/web", "dioxus-config-macro/web"]
|
||||
ssr = ["dioxus-fullstack?/ssr", "dioxus-config-macro/ssr"]
|
||||
liveview = ["dioxus-desktop", "dioxus-config-macro/liveview"]
|
||||
axum = ["dioxus-fullstack?/axum"]
|
||||
salvo = ["dioxus-fullstack?/salvo"]
|
||||
warp = ["dioxus-fullstack?/warp"]
|
||||
# tui = ["dioxus-tui", "dioxus-config-macro/tui"]
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
+102
-19
@@ -13,18 +13,26 @@ pub struct LaunchBuilder<P: AnyProps, Platform: PlatformBuilder<P> = CurrentPlat
|
||||
platform_config: Option<<Platform as PlatformBuilder<P>>::Config>,
|
||||
}
|
||||
|
||||
// Default platform builder
|
||||
impl<F: ComponentFunction<Props, M>, Props: Clone + Default + 'static, M: 'static>
|
||||
LaunchBuilder<VProps<F, Props, M>>
|
||||
#[cfg(feature = "fullstack")]
|
||||
// Fullstack platform builder
|
||||
impl<
|
||||
F: ComponentFunction<Props, M> + Send + Sync,
|
||||
Props: Clone + Send + Sync + 'static,
|
||||
M: Send + Sync + 'static,
|
||||
> LaunchBuilder<VProps<F, Props, M>>
|
||||
{
|
||||
/// Create a new builder for your application. This will create a launch configuration for the current platform based on the features enabled on the `dioxus` crate.
|
||||
pub fn new(component: F) -> Self {
|
||||
pub fn new(component: F) -> Self
|
||||
where
|
||||
Props: Default,
|
||||
{
|
||||
Self {
|
||||
cross_platform_config: CrossPlatformConfig::new(
|
||||
cross_platform_config: CrossPlatformConfig::new(VProps::new(
|
||||
component,
|
||||
|_, _| true,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
),
|
||||
"root",
|
||||
)),
|
||||
platform_config: None,
|
||||
}
|
||||
}
|
||||
@@ -32,19 +40,59 @@ impl<F: ComponentFunction<Props, M>, Props: Clone + Default + 'static, M: 'stati
|
||||
/// Create a new builder for your application with some root props. This will create a launch configuration for the current platform based on the features enabled on the `dioxus` crate.
|
||||
pub fn new_with_props(component: F, props: Props) -> Self {
|
||||
Self {
|
||||
cross_platform_config: CrossPlatformConfig::new(component, props, Default::default()),
|
||||
cross_platform_config: CrossPlatformConfig::new(VProps::new(
|
||||
component,
|
||||
|_, _| true,
|
||||
props,
|
||||
"root",
|
||||
)),
|
||||
platform_config: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "fullstack"))]
|
||||
// Default platform builder
|
||||
impl<F: ComponentFunction<Props, M>, Props: Clone + 'static, M: 'static>
|
||||
LaunchBuilder<VProps<F, Props, M>>
|
||||
{
|
||||
/// Create a new builder for your application. This will create a launch configuration for the current platform based on the features enabled on the `dioxus` crate.
|
||||
pub fn new(component: F) -> Self
|
||||
where
|
||||
Props: Default,
|
||||
{
|
||||
Self {
|
||||
cross_platform_config: CrossPlatformConfig::new(VProps::new(
|
||||
component,
|
||||
|_, _| true,
|
||||
Default::default(),
|
||||
"root",
|
||||
)),
|
||||
platform_config: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new builder for your application with some root props. This will create a launch configuration for the current platform based on the features enabled on the `dioxus` crate.
|
||||
pub fn new_with_props(component: F, props: Props) -> Self {
|
||||
Self {
|
||||
cross_platform_config: CrossPlatformConfig::new(VProps::new(
|
||||
component,
|
||||
|_, _| true,
|
||||
props,
|
||||
"root",
|
||||
)),
|
||||
platform_config: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: AnyProps, Platform: PlatformBuilder<P>> LaunchBuilder<P, Platform> {
|
||||
/// Inject state into the root component's context.
|
||||
pub fn context(mut self, state: impl Any + Clone + 'static) -> Self {
|
||||
self.cross_platform_config
|
||||
.push_context(BoxedContext::new(state));
|
||||
self
|
||||
}
|
||||
// /// Inject state into the root component's context.
|
||||
// pub fn context(mut self, state: impl Any + Clone + 'static) -> Self {
|
||||
// self.cross_platform_config
|
||||
// .push_context(BoxedContext::new(state));
|
||||
// self
|
||||
// }
|
||||
|
||||
/// Provide a platform-specific config to the builder.
|
||||
pub fn cfg(
|
||||
@@ -89,13 +137,37 @@ impl<P: AnyProps> LaunchBuilder<P, dioxus_desktop::DesktopPlatform> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "desktop")]
|
||||
#[cfg(feature = "fullstack")]
|
||||
impl<P: AnyProps + Clone + Send + Sync> LaunchBuilder<P, dioxus_fullstack::FullstackPlatform> {
|
||||
/// Launch your fullstack application.
|
||||
pub fn launch_fullstack(self) {
|
||||
dioxus_fullstack::FullstackPlatform::launch(
|
||||
self.cross_platform_config,
|
||||
self.platform_config.unwrap_or_default(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "fullstack")]
|
||||
type CurrentPlatform = dioxus_fullstack::FullstackPlatform;
|
||||
#[cfg(all(feature = "desktop", not(feature = "fullstack")))]
|
||||
type CurrentPlatform = dioxus_desktop::DesktopPlatform;
|
||||
#[cfg(all(feature = "web", not(feature = "desktop")))]
|
||||
#[cfg(all(feature = "web", not(any(feature = "desktop", feature = "fullstack"))))]
|
||||
type CurrentPlatform = dioxus_web::WebPlatform;
|
||||
#[cfg(not(any(feature = "desktop", feature = "web")))]
|
||||
#[cfg(not(any(feature = "desktop", feature = "web", feature = "fullstack")))]
|
||||
type CurrentPlatform = ();
|
||||
|
||||
#[cfg(feature = "fullstack")]
|
||||
/// Launch your application without any additional configuration. See [`LaunchBuilder`] for more options.
|
||||
pub fn launch<Props, Marker>(component: impl ComponentFunction<Props, Marker> + Send + Sync)
|
||||
where
|
||||
Props: Default + Send + Sync + Clone + 'static,
|
||||
Marker: Send + Sync + 'static,
|
||||
{
|
||||
LaunchBuilder::new(component).launch()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "fullstack"))]
|
||||
/// Launch your application without any additional configuration. See [`LaunchBuilder`] for more options.
|
||||
pub fn launch<Props, Marker: 'static>(component: impl ComponentFunction<Props, Marker>)
|
||||
where
|
||||
@@ -104,7 +176,7 @@ where
|
||||
LaunchBuilder::new(component).launch()
|
||||
}
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
#[cfg(all(feature = "web", not(feature = "fullstack")))]
|
||||
/// Launch your web application without any additional configuration. See [`LaunchBuilder`] for more options.
|
||||
pub fn launch_web<Props, Marker: 'static>(component: impl ComponentFunction<Props, Marker>)
|
||||
where
|
||||
@@ -113,7 +185,7 @@ where
|
||||
LaunchBuilder::new(component).launch_web()
|
||||
}
|
||||
|
||||
#[cfg(feature = "desktop")]
|
||||
#[cfg(all(feature = "desktop", not(feature = "fullstack")))]
|
||||
/// Launch your desktop application without any additional configuration. See [`LaunchBuilder`] for more options.
|
||||
pub fn launch_desktop<Props, Marker: 'static>(component: impl ComponentFunction<Props, Marker>)
|
||||
where
|
||||
@@ -121,3 +193,14 @@ where
|
||||
{
|
||||
LaunchBuilder::new(component).launch_desktop()
|
||||
}
|
||||
|
||||
#[cfg(feature = "fullstack")]
|
||||
/// Launch your fullstack application without any additional configuration. See [`LaunchBuilder`] for more options.
|
||||
pub fn launch_fullstack<Props, Marker>(
|
||||
component: impl ComponentFunction<Props, Marker> + Send + Sync,
|
||||
) where
|
||||
Props: Default + Send + Sync + Clone + 'static,
|
||||
Marker: Send + Sync + 'static,
|
||||
{
|
||||
LaunchBuilder::new(component).launch_fullstack()
|
||||
}
|
||||
@@ -57,6 +57,9 @@ pub mod prelude {
|
||||
pub use dioxus_hot_reload::{self, hot_reload_init};
|
||||
|
||||
pub use dioxus_core;
|
||||
|
||||
#[cfg(feature = "fullstack")]
|
||||
pub use dioxus_fullstack::prelude::*;
|
||||
}
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
|
||||
Reference in new issue
Block a user