wip: move some examples around
This commit is contained in:
1 parent
cca7c5fc3a
commit
98a09339fd
70 files changed
+111
-117
No files matched your search
@@ -150,7 +150,7 @@ pub mod on {
|
||||
$(
|
||||
$(#[$method_attr])*
|
||||
pub fn $name<'a>(
|
||||
c: &'_ NodeFactory<'a>,
|
||||
c: NodeFactory<'a>,
|
||||
callback: impl Fn($wrapper) + 'a,
|
||||
) -> Listener<'a> {
|
||||
let bump = &c.bump();
|
||||
|
||||
@@ -23,7 +23,7 @@ use std::{
|
||||
/// Usage:
|
||||
/// ```ignore
|
||||
/// static Example: FC<()> = |cx| {
|
||||
/// let (counter, set_counter) = use_state(&cx, || 0);
|
||||
/// let (counter, set_counter) = use_state(cx, || 0);
|
||||
/// let increment = |_| set_couter(counter + 1);
|
||||
/// let decrement = |_| set_couter(counter + 1);
|
||||
///
|
||||
@@ -145,7 +145,7 @@ impl<'a, T: 'static + Display> std::fmt::Display for UseState<T> {
|
||||
/// Usage:
|
||||
/// ```ignore
|
||||
/// static Example: FC<()> = |cx| {
|
||||
/// let (counter, set_counter) = use_state(&cx, || 0);
|
||||
/// let (counter, set_counter) = use_state(cx, || 0);
|
||||
/// let increment = |_| set_couter(counter + 1);
|
||||
/// let decrement = |_| set_couter(counter + 1);
|
||||
///
|
||||
|
||||
@@ -620,23 +620,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// impl IntoVNode<'_> for () {
|
||||
// fn into_vnode<'a>(self, cx: NodeFactory<'a>) -> VNode<'a> {
|
||||
// todo!();
|
||||
// VNode::Suspended {
|
||||
// real: Cell::new(RealDomNode::empty()),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
impl IntoVNode<'_> for () {
|
||||
fn into_vnode<'a>(self, cx: NodeFactory<'a>) -> VNode<'a> {
|
||||
cx.fragment_from_iter(None as Option<VNode>)
|
||||
}
|
||||
}
|
||||
|
||||
// impl IntoVNode<'_> for Option<()> {
|
||||
// fn into_vnode<'a>(self, cx: NodeFactory<'a>) -> VNode<'a> {
|
||||
// todo!();
|
||||
// VNode::Suspended {
|
||||
// real: Cell::new(RealDomNode::empty()),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
impl IntoVNode<'_> for Option<()> {
|
||||
fn into_vnode<'a>(self, cx: NodeFactory<'a>) -> VNode<'a> {
|
||||
cx.fragment_from_iter(None as Option<VNode>)
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a text VNode.
|
||||
///
|
||||
@@ -717,8 +711,6 @@ pub fn virtual_child<'a, T: Properties + 'a>(
|
||||
VNode::Component(
|
||||
cx.bump()
|
||||
.alloc(crate::nodes::VComponent::new(&cx, f, props, key, children)),
|
||||
// cx.bump()
|
||||
// .alloc(crate::nodes::VComponent::new(f, props, key)),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -786,6 +778,26 @@ impl<'a> NodeFactory<'a> {
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn virtual_child<T: Properties + 'a, C>(
|
||||
&self,
|
||||
f: FC<T>,
|
||||
props: T,
|
||||
key: Option<&'a str>, // key: NodeKey<'a>,
|
||||
children: C,
|
||||
) -> VNode<'a>
|
||||
where
|
||||
C: 'a + AsRef<[VNode<'a>]>,
|
||||
{
|
||||
let children: &'a C = self.bump().alloc(children);
|
||||
VNode::Component(self.bump().alloc(crate::nodes::VComponent::new(
|
||||
self,
|
||||
f,
|
||||
props,
|
||||
key,
|
||||
children.as_ref(),
|
||||
)))
|
||||
}
|
||||
|
||||
pub fn fragment_from_iter(
|
||||
self,
|
||||
node_iter: impl IntoIterator<Item = impl IntoVNode<'a>>,
|
||||
|
||||
Reference in new issue
Block a user