Make it easier to provide context to fullstack (#2515)
* pass context providers into server functions * add an example for FromContext * clean up DioxusRouterExt * fix server function context * fix fullstack desktop example * fix axum auth example * fix fullstack context type * fix context providers path
This commit is contained in:
1 parent
7ee3dc41fc
commit
b0caf442ab
12 files changed
+152
-64
No files matched your search
@@ -27,6 +27,7 @@ dioxus-liveview = { workspace = true, optional = true }
|
||||
dioxus-ssr ={ workspace = true, optional = true }
|
||||
|
||||
serde = { version = "1.0.136", optional = true }
|
||||
axum = { workspace = true, optional = true }
|
||||
|
||||
[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "android")))'.dependencies]
|
||||
dioxus-hot-reload = { workspace = true, optional = true }
|
||||
@@ -50,7 +51,7 @@ web = ["dep:dioxus-web", "dioxus-fullstack?/web", "dioxus-static-site-generation
|
||||
ssr = ["dep:dioxus-ssr", "dioxus-router?/ssr", "dioxus-config-macro/ssr"]
|
||||
liveview = ["dep:dioxus-liveview", "dioxus-config-macro/liveview", "dioxus-router?/liveview"]
|
||||
static-generation = ["dep:dioxus-static-site-generation", "dioxus-config-macro/static-generation"]
|
||||
axum = ["dioxus-fullstack?/axum", "dioxus-fullstack?/server", "dioxus-static-site-generation?/server", "ssr", "dioxus-liveview?/axum"]
|
||||
axum = ["dioxus-fullstack?/axum", "dioxus-fullstack?/server", "dioxus-static-site-generation?/server", "ssr", "dioxus-liveview?/axum", "dep:axum"]
|
||||
|
||||
# This feature just disables the no-renderer-enabled warning
|
||||
third-party-renderer = []
|
||||
|
||||
@@ -31,7 +31,7 @@ type ValidContext = SendContext;
|
||||
)))]
|
||||
type ValidContext = UnsendContext;
|
||||
|
||||
type SendContext = dyn Fn() -> Box<dyn Any> + Send + Sync + 'static;
|
||||
type SendContext = dyn Fn() -> Box<dyn Any + Send + Sync> + Send + Sync + 'static;
|
||||
|
||||
type UnsendContext = dyn Fn() -> Box<dyn Any> + 'static;
|
||||
|
||||
@@ -137,7 +137,7 @@ impl<Cfg> LaunchBuilder<Cfg, SendContext> {
|
||||
/// Inject state into the root component's context that is created on the thread that the app is launched on.
|
||||
pub fn with_context_provider(
|
||||
mut self,
|
||||
state: impl Fn() -> Box<dyn Any> + Send + Sync + 'static,
|
||||
state: impl Fn() -> Box<dyn Any + Send + Sync> + Send + Sync + 'static,
|
||||
) -> Self {
|
||||
self.contexts.push(Box::new(state) as Box<SendContext>);
|
||||
self
|
||||
|
||||
@@ -110,6 +110,10 @@ pub mod prelude {
|
||||
#[cfg(feature = "router")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "router")))]
|
||||
pub use dioxus_router::prelude::*;
|
||||
|
||||
#[cfg(feature = "axum")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "axum")))]
|
||||
pub use axum;
|
||||
}
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
|
||||
Reference in new issue
Block a user