wip: comment out examples and move lifetime in FC type
This commit is contained in:
1 parent
07341d2c65
commit
62d4ad5878
12 files changed
+300
-175
No files matched your search
@@ -81,11 +81,8 @@ pub mod prelude {
|
||||
pub use nodes::*;
|
||||
// pub use nodes::iterables::IterableNodes;
|
||||
|
||||
// FC is a shorthand for statics to easily declare a function that takes a context and produces a dom tree
|
||||
// The DomTree is lazy and needs to be evaluated with an arena for any allocation to take place
|
||||
// Hmmm, maybe get statics to work again?
|
||||
// pub type FC<'a, T> = fn(&'a Context<T>) -> VNode<'a>;
|
||||
pub use crate::virtual_dom::{__domtree_helper, FC};
|
||||
/// This type alias is an internal way of abstracting over the static functions that represent components.
|
||||
pub type FC<P> = for<'a> fn(&'a Context<P>) -> VNode<'a>;
|
||||
|
||||
// TODO @Jon, fix this
|
||||
// hack the VNode type until VirtualNode is fixed in the macro crate
|
||||
@@ -93,4 +90,7 @@ pub mod prelude {
|
||||
|
||||
// Re-export from the macro crate
|
||||
pub use dioxus_html_macro::html;
|
||||
|
||||
// Re-export the FC macro
|
||||
pub use dioxus_core_macro::fc;
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use crate::nodes::{Attribute, Listener, NodeKey, VNode};
|
||||
type Node<'g> = VNode<'g>;
|
||||
// use crate::{node::NodeKey, Attribute, Listener, Node, RootRender, VdomWeak};
|
||||
use bumpalo::Bump;
|
||||
|
||||
/// A virtual DOM element builder.
|
||||
|
||||
@@ -71,7 +71,7 @@ impl VirtualDom {
|
||||
///
|
||||
/// This means that the root component must either consumes its own context, or statics are used to generate the page.
|
||||
/// The root component can access things like routing in its context.
|
||||
pub fn new<F: DomTree>(root: FC<(), F>) -> Self {
|
||||
pub fn new(root: FC<()>) -> Self {
|
||||
Self::new_with_props(root)
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ impl VirtualDom {
|
||||
///
|
||||
/// This is useful when a component tree can be driven by external state (IE SSR) but it would be too expensive
|
||||
/// to toss out the entire tree.
|
||||
pub fn new_with_props<P: Properties, F: DomTree>(root: FC<P, F>) -> Self {
|
||||
pub fn new_with_props<P: Properties>(root: FC<P>) -> Self {
|
||||
Self {
|
||||
components: Arena::new(),
|
||||
event_queue: vec![],
|
||||
@@ -116,19 +116,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// This type alias is an internal way of abstracting over the static functions that represent components.
|
||||
pub type FC<P: Properties, F: DomTree> = fn(&Context<P>) -> F;
|
||||
|
||||
/// A gross AF helper that connects the dots for lifetimes
|
||||
/// sigh.. todo: move this into the html macro or core crates
|
||||
/// https://github.com/rust-lang/rust/issues/41078
|
||||
#[inline]
|
||||
pub fn __domtree_helper(
|
||||
arg: impl for<'a> FnOnce(&'a Bump) -> VNode<'a>,
|
||||
) -> impl for<'a> FnOnce(&'a Bump) -> VNode<'a> {
|
||||
arg
|
||||
}
|
||||
|
||||
/// The `Component` trait refers to any struct or funciton that can be used as a component
|
||||
/// We automatically implement Component for FC<T>
|
||||
pub trait Component {
|
||||
@@ -138,7 +125,7 @@ pub trait Component {
|
||||
|
||||
// Auto implement component for a FC
|
||||
// Calling the FC is the same as "rendering" it
|
||||
impl<'a, P: Properties, F: DomTree> Component for FC<P, F> {
|
||||
impl<P: Properties> Component for FC<P> {
|
||||
type Props = P;
|
||||
|
||||
fn builder(&self) -> Self::Props {
|
||||
@@ -235,14 +222,14 @@ pub struct HookState {}
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub struct Context<T> {
|
||||
// pub struct Context<'source, T> {
|
||||
// todo: force lifetime of source into T as a valid lifetime too
|
||||
// it's definitely possible, just needs some more messing around
|
||||
pub struct Context<'source, T> {
|
||||
/// Direct access to the properties used to create this component.
|
||||
pub props: T,
|
||||
// pub props: &'source T,
|
||||
pub props: &'source T,
|
||||
}
|
||||
|
||||
impl<'a, T> Context<T> {
|
||||
impl<'a, T> Context<'a, T> {
|
||||
// impl<'a, T> Context<'a, T> {
|
||||
/// Access the children elements passed into the component
|
||||
pub fn children(&self) -> Vec<VNode> {
|
||||
@@ -260,9 +247,18 @@ impl<'a, T> Context<T> {
|
||||
|| {}
|
||||
}
|
||||
|
||||
/// Create VNodes from macros that use efficient allcators
|
||||
/// The VDOM is configured to use a special allocator for VNodes
|
||||
pub fn view(&self, v: impl Fn(&'a Bump) -> VNode<'a>) -> VNode<'a> {
|
||||
/// Take a lazy VNode structure and actually build it with the context of the VDom's efficient VNode allocator.
|
||||
///
|
||||
/// ```ignore
|
||||
/// fn Component(ctx: Context<Props>) -> VNode {
|
||||
/// // Lazy assemble the VNode tree
|
||||
/// let lazy_tree = html! {<div>"Hello World"</div>};
|
||||
///
|
||||
/// // Actually build the tree and allocate it
|
||||
/// ctx.view(lazy_tree)
|
||||
/// }
|
||||
///```
|
||||
pub fn view(&self, v: impl FnOnce(&'a Bump) -> VNode<'a>) -> VNode<'a> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user