add context_provider method for !Send context in fullstack apps

This commit is contained in:
Evan Almloff committed 2024-01-17 20:18:39 -06:00
1 parent 25ad3da659
commit 5291b00798
1 file changed
+16
+16
View File
@@ -27,6 +27,22 @@ impl LaunchBuilder {
}
}
#[cfg(feature = "fullstack")]
/// Inject state into the root component's context that is created on the thread that the app is launched on.
pub fn context_provider(mut self, state: impl Fn() -> Box<dyn Any> + Send + 'static) -> Self {
self.contexts
.push(Box::new(state) as Box<dyn Fn() -> Box<dyn Any> + Send>);
self
}
#[cfg(not(feature = "fullstack"))]
/// Inject state into the root component's context that is created on the thread that the app is launched on.
pub fn context_provider(mut self, state: impl Fn() -> Box<dyn Any> + 'static) -> Self {
self.contexts
.push(Box::new(state) as Box<dyn Fn() -> Box<dyn Any>>);
self
}
#[cfg(feature = "fullstack")]
/// Inject state into the root component's context.
pub fn context(mut self, state: impl Any + Clone + Send + 'static) -> Self {