re export renderers in dioxus
This commit is contained in:
1 parent
b291a5c0b0
commit
af1749d7be
61 files changed
+860
-100
No files matched your search
@@ -14,21 +14,38 @@ rust-version = "1.65.0"
|
||||
dioxus-core = { workspace = true }
|
||||
dioxus-html = { workspace = true, optional = true }
|
||||
dioxus-core-macro = { workspace = true, optional = true }
|
||||
dioxus-config-macro = { workspace = true, optional = true }
|
||||
dioxus-hooks = { workspace = true, optional = true }
|
||||
dioxus-rsx = { workspace = true, optional = true }
|
||||
dioxus-signals = { workspace = true, optional = true }
|
||||
dioxus-router = { workspace = true, optional = true }
|
||||
dioxus-web = { workspace = true, optional = true }
|
||||
dioxus-desktop = { workspace = true, optional = true }
|
||||
dioxus-fullstack = { workspace = true, optional = true }
|
||||
dioxus-liveview = { workspace = true, optional = true }
|
||||
# dioxus-tui = { workspace = true, optional = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
dioxus-hot-reload = { workspace = true, optional = true }
|
||||
|
||||
[features]
|
||||
default = ["macro", "html", "hot-reload", "signals"]
|
||||
default = ["macro", "html", "hot-reload", "signals", "launch"]
|
||||
signals = ["dioxus-signals"]
|
||||
macro = ["dioxus-core-macro", "dioxus-rsx"]
|
||||
html = ["dioxus-html"]
|
||||
hooks = ["dioxus-hooks"]
|
||||
hot-reload = ["dioxus-hot-reload"]
|
||||
|
||||
launch = ["dioxus-config-macro"]
|
||||
router = ["dioxus-router"]
|
||||
|
||||
# Platforms
|
||||
fullstack = ["dioxus-fullstack"]
|
||||
desktop = ["dioxus-desktop", "dioxus-fullstack?/desktop"]
|
||||
web = ["dioxus-web", "dioxus-fullstack?/web"]
|
||||
ssr = ["dioxus-fullstack?/ssr"]
|
||||
liveview = ["dioxus-desktop"]
|
||||
# tui = ["dioxus-tui"]
|
||||
|
||||
[dev-dependencies]
|
||||
futures-util = { workspace = true }
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
//! Launch helper macros for fullstack apps
|
||||
#![allow(unused)]
|
||||
use std::any::Any;
|
||||
|
||||
use crate::prelude::*;
|
||||
use dioxus_core::prelude::*;
|
||||
use dioxus_core::ComponentFunction;
|
||||
|
||||
pub trait ClonableAny: Any {
|
||||
fn clone_box(&self) -> Box<dyn ClonableAny>;
|
||||
}
|
||||
|
||||
impl<T: Any + Clone> ClonableAny for T {
|
||||
fn clone_box(&self) -> Box<dyn ClonableAny> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
/// The platform-independent part of the config needed to launch an application.
|
||||
pub struct CrossPlatformConfig<F: ComponentFunction<P>, P> {
|
||||
/// The root component function.
|
||||
pub component: F,
|
||||
/// The props for the root component.
|
||||
pub props: P,
|
||||
/// The contexts to provide to the root component.
|
||||
pub root_contexts: Vec<Box<dyn ClonableAny>>,
|
||||
}
|
||||
|
||||
pub trait PlatformBuilder<P> {
|
||||
type Config;
|
||||
|
||||
/// Launch the app.
|
||||
fn launch<F: ComponentFunction<P>>(config: CrossPlatformConfig<F, P>, config: Self::Config);
|
||||
}
|
||||
|
||||
impl<P> PlatformBuilder<P> for () {
|
||||
type Config = ();
|
||||
|
||||
fn launch<F: ComponentFunction<P>>(config: CrossPlatformConfig<F, P>, _: ()) {}
|
||||
}
|
||||
|
||||
/// A builder for a fullstack app.
|
||||
pub struct LaunchBuilder<F: ComponentFunction<P>, P> {
|
||||
cross_platform_config: CrossPlatformConfig<F, P>,
|
||||
}
|
||||
|
||||
impl<F: ComponentFunction<P>, P> LaunchBuilder<F, P> {
|
||||
/// Create a new builder for your application.
|
||||
pub fn new(component: F) -> Self
|
||||
where
|
||||
P: Default,
|
||||
{
|
||||
Self {
|
||||
cross_platform_config: CrossPlatformConfig {
|
||||
component,
|
||||
props: Default::default(),
|
||||
root_contexts: vec![],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Pass some props to your application.
|
||||
pub fn props(mut self, props: P) -> Self {
|
||||
self.cross_platform_config.props = props;
|
||||
self
|
||||
}
|
||||
|
||||
/// Inject state into the root component's context.
|
||||
pub fn context(mut self, state: impl ClonableAny + 'static) -> Self {
|
||||
self.cross_platform_config
|
||||
.root_contexts
|
||||
.push(Box::new(state));
|
||||
self
|
||||
}
|
||||
|
||||
/// Provide a platform-specific config to the builder.
|
||||
pub fn platform_config(
|
||||
self,
|
||||
config: Option<<CurrentPlatform as PlatformBuilder<P>>::Config>,
|
||||
) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
/// Launch the app.
|
||||
pub fn launch(self) {}
|
||||
}
|
||||
|
||||
#[cfg(feature = "router")]
|
||||
impl<R: Routable> LaunchBuilder<crate::router::FullstackRouterConfig<R>>
|
||||
where
|
||||
<R as std::str::FromStr>::Err: std::fmt::Display,
|
||||
R: Clone + serde::Serialize + serde::de::DeserializeOwned + Send + Sync + 'static,
|
||||
{
|
||||
/// Create a new launch builder for the given router.
|
||||
pub fn router() -> Self {
|
||||
let component = crate::router::RouteWithCfg::<R>;
|
||||
let props = crate::router::FullstackRouterConfig::default();
|
||||
Self::new_with_props(component, props)
|
||||
}
|
||||
}
|
||||
|
||||
type CurrentPlatform = ();
|
||||
@@ -2,7 +2,12 @@
|
||||
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
|
||||
#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
|
||||
|
||||
pub use dioxus_core as core;
|
||||
pub use dioxus_core;
|
||||
|
||||
#[cfg(feature = "launch")]
|
||||
mod launch;
|
||||
#[cfg(feature = "launch")]
|
||||
pub use launch::*;
|
||||
|
||||
#[cfg(feature = "hooks")]
|
||||
pub use dioxus_hooks as hooks;
|
||||
@@ -37,6 +42,9 @@ pub mod prelude {
|
||||
#[allow(deprecated)]
|
||||
pub use dioxus_core_macro::{component, format_args_f, inline_props, render, rsx, Props};
|
||||
|
||||
#[cfg(feature = "launch")]
|
||||
pub use dioxus_config_macro::*;
|
||||
|
||||
#[cfg(feature = "html")]
|
||||
pub use dioxus_html as dioxus_elements;
|
||||
|
||||
@@ -45,4 +53,6 @@ pub mod prelude {
|
||||
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "hot-reload"))]
|
||||
pub use dioxus_hot_reload::{self, hot_reload_init};
|
||||
|
||||
pub use dioxus_core;
|
||||
}
|
||||
Reference in new issue
Block a user