wip: move examples around
This commit is contained in:
1 parent
d298b626d3
commit
1e6e5e611b
86 files changed
+160
-216
No files matched your search
@@ -5,7 +5,10 @@
|
||||
//! if the type supports PartialEq. The Properties trait is used by the rsx! and html! macros to generate the type-safe builder
|
||||
//! that ensures compile-time required and optional fields on cx.
|
||||
|
||||
use crate::innerlude::{Context, Element, VNode};
|
||||
use crate::{
|
||||
innerlude::{Context, Element, VAnchor, VFragment, VNode},
|
||||
LazyNodes, ScopeChildren,
|
||||
};
|
||||
/// A component is a wrapper around a Context and some Props that share a lifetime
|
||||
///
|
||||
///
|
||||
@@ -41,23 +44,39 @@ use crate::innerlude::{Context, Element, VNode};
|
||||
pub type Scope<'a, T> = (Context<'a>, &'a T);
|
||||
|
||||
pub struct FragmentProps<'a> {
|
||||
childen: &'a VNode<'a>,
|
||||
children: ScopeChildren<'a>,
|
||||
}
|
||||
pub struct FragmentPropsBuilder<'a> {
|
||||
childen: Option<&'a VNode<'a>>,
|
||||
|
||||
pub struct FragmentBuilder<'a, const BUILT: bool> {
|
||||
children: Option<ScopeChildren<'a>>,
|
||||
}
|
||||
impl<'a> FragmentBuilder<'a, false> {
|
||||
pub fn children(mut self, children: ScopeChildren<'a>) -> FragmentBuilder<'a, true> {
|
||||
FragmentBuilder {
|
||||
children: Some(children),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, const A: bool> FragmentBuilder<'a, A> {
|
||||
pub fn build(self) -> FragmentProps<'a> {
|
||||
FragmentProps {
|
||||
children: self.children.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Properties for FragmentProps<'a> {
|
||||
type Builder = FragmentPropsBuilder<'a>;
|
||||
type Builder = FragmentBuilder<'a, false>;
|
||||
|
||||
const IS_STATIC: bool = false;
|
||||
|
||||
fn builder() -> Self::Builder {
|
||||
todo!()
|
||||
FragmentBuilder { children: None }
|
||||
}
|
||||
|
||||
unsafe fn memoize(&self, other: &Self) -> bool {
|
||||
todo!()
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +102,10 @@ impl<'a> Properties for FragmentProps<'a> {
|
||||
/// You want to use this free-function when your fragment needs a key and simply returning multiple nodes from rsx! won't cut it.
|
||||
///
|
||||
#[allow(non_upper_case_globals, non_snake_case)]
|
||||
pub fn Fragment<'a>((_, props): Scope<'a, FragmentProps<'a>>) -> Element<'a> {
|
||||
Some(props.childen.decouple())
|
||||
pub fn Fragment<'a>((cx, props): Scope<'a, FragmentProps<'a>>) -> Element<'a> {
|
||||
cx.render(Some(LazyNodes::new(|f| {
|
||||
f.fragment_from_iter(&props.children)
|
||||
})))
|
||||
}
|
||||
|
||||
/// Every "Props" used for a component must implement the `Properties` trait. This trait gives some hints to Dioxus
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
//! The logic for this was borrowed from https://docs.rs/stack_dst/0.6.1/stack_dst/. Unfortunately, this crate does not
|
||||
//! support non-static closures, so we've implemented the core logic of `ValueA` in this module.
|
||||
|
||||
use crate::innerlude::{NodeFactory, VNode};
|
||||
use crate::prelude::{NodeFactory, VNode};
|
||||
use std::mem;
|
||||
|
||||
/// A concrete type provider for closures that build VNode structures.
|
||||
@@ -27,7 +27,7 @@ pub struct LazyNodes<'a, 'b> {
|
||||
inner: StackNodeStorage<'a, 'b>,
|
||||
}
|
||||
|
||||
type StackHeapSize = [usize; 12];
|
||||
type StackHeapSize = [usize; 0];
|
||||
|
||||
enum StackNodeStorage<'a, 'b> {
|
||||
Stack(LazyStack),
|
||||
@@ -77,7 +77,7 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
|
||||
}
|
||||
} else {
|
||||
log::debug!("lazy nodes fits on stack!");
|
||||
let mut buf: StackHeapSize = [0; 12];
|
||||
let mut buf: StackHeapSize = StackHeapSize::default();
|
||||
|
||||
assert!(info.len() + round_to_words(size) <= buf.as_ref().len());
|
||||
|
||||
@@ -97,6 +97,8 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
|
||||
*dataptr.add(i) = *src_ptr.add(i);
|
||||
}
|
||||
|
||||
std::mem::forget(val);
|
||||
|
||||
Self {
|
||||
inner: StackNodeStorage::Stack(LazyStack { _align: [], buf }),
|
||||
}
|
||||
|
||||
@@ -65,9 +65,9 @@ pub(crate) mod innerlude {
|
||||
}
|
||||
|
||||
pub use crate::innerlude::{
|
||||
Context, DioxusElement, DomEdit, Element, ElementId, EventPriority, MountType, Mutations,
|
||||
NodeFactory, Properties, SchedulerMsg, ScopeChildren, ScopeId, SuspendedContext, TaskHandle,
|
||||
TestDom, ThreadsafeVirtualDom, UserEvent, VNode, VirtualDom, FC,
|
||||
Context, DioxusElement, DomEdit, Element, ElementId, EventPriority, LazyNodes, MountType,
|
||||
Mutations, NodeFactory, Properties, SchedulerMsg, ScopeChildren, ScopeId, SuspendedContext,
|
||||
TaskHandle, TestDom, ThreadsafeVirtualDom, UserEvent, VNode, VirtualDom, FC,
|
||||
};
|
||||
|
||||
pub mod prelude {
|
||||
|
||||
@@ -765,6 +765,9 @@ impl<'a> ScopeChildren<'a> {
|
||||
pub fn new(root: VNode<'a>) -> Self {
|
||||
Self { root: Some(root) }
|
||||
}
|
||||
pub fn new_option(root: Option<VNode<'a>>) -> Self {
|
||||
Self { root }
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for &ScopeChildren<'_> {
|
||||
@@ -773,7 +776,7 @@ impl IntoIterator for &ScopeChildren<'_> {
|
||||
type IntoIter = std::iter::Once<Self>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
todo!()
|
||||
std::iter::once(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user