remove some generics from LaunchBuilder
This commit is contained in:
1 parent
16e2c3f2f2
commit
25ad3da659
14 files changed
+142
-304
No files matched your search
@@ -13,7 +13,6 @@ mod fragment;
|
||||
mod global_context;
|
||||
mod mutations;
|
||||
mod nodes;
|
||||
mod platform;
|
||||
mod properties;
|
||||
mod runtime;
|
||||
mod scope_arena;
|
||||
@@ -32,7 +31,6 @@ pub(crate) mod innerlude {
|
||||
pub use crate::global_context::*;
|
||||
pub use crate::mutations::*;
|
||||
pub use crate::nodes::*;
|
||||
pub use crate::platform::*;
|
||||
pub use crate::properties::*;
|
||||
pub use crate::runtime::{Runtime, RuntimeGuard};
|
||||
pub use crate::scopes::*;
|
||||
@@ -76,11 +74,11 @@ pub(crate) mod innerlude {
|
||||
|
||||
pub use crate::innerlude::{
|
||||
fc_to_builder, generation, schedule_update, schedule_update_any, use_hook, vdom_is_rendering,
|
||||
AnyProps, AnyValue, Attribute, AttributeValue, BoxedContext, CapturedError, Component,
|
||||
ComponentFunction, CrossPlatformConfig, DynamicNode, Element, ElementId, Event, Fragment,
|
||||
HasAttributes, IntoDynNode, Mutation, Mutations, NoOpMutations, PlatformBuilder, Properties,
|
||||
RenderReturn, Runtime, ScopeId, ScopeState, Task, Template, TemplateAttribute, TemplateNode,
|
||||
VComponent, VNode, VNodeInner, VPlaceholder, VProps, VText, VirtualDom, WriteMutations,
|
||||
AnyProps, AnyValue, Attribute, AttributeValue, CapturedError, Component, ComponentFunction,
|
||||
DynamicNode, Element, ElementId, Event, Fragment, HasAttributes, IntoDynNode, Mutation,
|
||||
Mutations, NoOpMutations, Properties, RenderReturn, Runtime, ScopeId, ScopeState, Task,
|
||||
Template, TemplateAttribute, TemplateNode, VComponent, VNode, VNodeInner, VPlaceholder, VProps,
|
||||
VText, VirtualDom, WriteMutations,
|
||||
};
|
||||
|
||||
/// The purpose of this module is to alleviate imports of many common types
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
use std::any::Any;
|
||||
|
||||
use crate::{
|
||||
any_props::{AnyProps, VProps},
|
||||
properties::ComponentFunction,
|
||||
VirtualDom,
|
||||
};
|
||||
|
||||
/// A boxed object that can be injected into a component's context.
|
||||
pub struct BoxedContext(Box<dyn ClonableAny>);
|
||||
|
||||
impl BoxedContext {
|
||||
/// Create a new boxed context.
|
||||
pub fn new(value: impl Any + Clone + 'static) -> Self {
|
||||
Self(Box::new(value))
|
||||
}
|
||||
|
||||
/// Unwrap the boxed context into its inner value.
|
||||
pub fn into_inner(self) -> Box<dyn Any> {
|
||||
self.0.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for BoxedContext {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.clone_box())
|
||||
}
|
||||
}
|
||||
|
||||
trait ClonableAny: Any {
|
||||
fn clone_box(&self) -> Box<dyn ClonableAny>;
|
||||
|
||||
fn into_inner(self: Box<Self>) -> Box<dyn Any>;
|
||||
}
|
||||
|
||||
impl<T: Any + Clone> ClonableAny for T {
|
||||
fn clone_box(&self) -> Box<dyn ClonableAny> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
|
||||
fn into_inner(self: Box<Self>) -> Box<dyn Any> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// The platform-independent part of the config needed to launch an application.
|
||||
#[derive(Clone)]
|
||||
pub struct CrossPlatformConfig<P: AnyProps> {
|
||||
/// The root component function.
|
||||
props: P,
|
||||
// /// The contexts to provide to the root component.
|
||||
// root_contexts: Vec<BoxedContext>,
|
||||
}
|
||||
|
||||
impl<P: AnyProps> CrossPlatformConfig<P> {}
|
||||
|
||||
impl<P: AnyProps> CrossPlatformConfig<P> {
|
||||
/// Create a new cross-platform config.
|
||||
pub fn new(props: P) -> Self {
|
||||
CrossPlatformConfig {
|
||||
props,
|
||||
// root_contexts,
|
||||
}
|
||||
}
|
||||
|
||||
// /// Push a new context into the root component's context.
|
||||
// pub fn push_context<T: Any + Clone + 'static>(&mut self, context: T) {
|
||||
// self.root_contexts.push(BoxedContext::new(context));
|
||||
// }
|
||||
|
||||
/// Build a virtual dom from the config.
|
||||
pub fn build_vdom(self) -> VirtualDom {
|
||||
let mut vdom = VirtualDom::new_with_component(self.props);
|
||||
|
||||
// for context in self.root_contexts {
|
||||
// vdom.insert_boxed_root_context(context);
|
||||
// }
|
||||
|
||||
vdom
|
||||
}
|
||||
}
|
||||
|
||||
/// A builder to launch a specific platform.
|
||||
pub trait PlatformBuilder<P: AnyProps> {
|
||||
/// The platform-specific config needed to launch an application.
|
||||
type Config: Default;
|
||||
|
||||
/// Launch the app.
|
||||
fn launch(config: CrossPlatformConfig<P>, platform_config: Self::Config);
|
||||
}
|
||||
|
||||
impl<P: AnyProps> PlatformBuilder<P> for () {
|
||||
type Config = ();
|
||||
|
||||
fn launch(_: CrossPlatformConfig<P>, _: Self::Config) {
|
||||
panic!("No platform is currently enabled. Please enable a platform feature for the dioxus crate.");
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use crate::{
|
||||
nodes::{Template, TemplateId},
|
||||
runtime::{Runtime, RuntimeGuard},
|
||||
scopes::ScopeId,
|
||||
AttributeValue, BoxedContext, ComponentFunction, Element, Event, Mutations, Task, VProps,
|
||||
AttributeValue, ComponentFunction, Element, Event, Mutations, Task, VProps,
|
||||
};
|
||||
use futures_util::{pin_mut, StreamExt};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
@@ -361,10 +361,8 @@ impl VirtualDom {
|
||||
/// Build the virtualdom with a global context inserted into the base scope
|
||||
///
|
||||
/// This method is useful for when you want to provide a context in your app without knowing its type
|
||||
pub fn insert_boxed_root_context(&mut self, context: BoxedContext) {
|
||||
self.base_scope()
|
||||
.context()
|
||||
.provide_any_context(context.into_inner());
|
||||
pub fn insert_any_root_context(&mut self, context: Box<dyn Any>) {
|
||||
self.base_scope().context().provide_any_context(context);
|
||||
}
|
||||
|
||||
/// Manually mark a scope as requiring a re-render
|
||||
|
||||
Reference in new issue
Block a user