WIP: add extends to the props macro

This commit is contained in:
Evan Almloff committed 2023-09-26 19:23:00 -05:00
1 parent 56b1a0aefc
commit 7b51bb8060
6 files changed
+270 -151

No files matched your search

+13 -56
View File
@@ -1,3 +1,4 @@
use crate::dioxus_elements::ExtendedDivMarker;
use dioxus::{
core::{exports::bumpalo::Bump, Attribute, HasAttributesBox},
html::{ExtendedGlobalAttributesMarker, GlobalAttributesExtension},
@@ -13,65 +14,15 @@ fn main() {
}
fn app(cx: Scope) -> Element {
cx.render(::dioxus::core::LazyNodes::new(
move |__cx: &::dioxus::core::ScopeState| -> ::dioxus::core::VNode {
static TEMPLATE: ::dioxus::core::Template = ::dioxus::core::Template {
name: "src/main.rs:15:15:289",
roots: &[::dioxus::core::TemplateNode::Dynamic { id: 0usize }],
node_paths: &[&[0u8]],
attr_paths: &[],
};
::dioxus::core::VNode {
parent: None,
key: None,
template: std::cell::Cell::new(TEMPLATE),
root_ids: dioxus::core::exports::bumpalo::collections::Vec::with_capacity_in(
1usize,
__cx.bump(),
)
.into(),
dynamic_nodes: __cx.bump().alloc([__cx.component(
Component,
Props {
bump: __cx.bump(),
attributes: Vec::new(),
}
.width(10)
.height("100px"),
"Component",
)]),
dynamic_attrs: __cx.bump().alloc([]),
}
},
))
}
#[derive(Props)]
struct Props<'a> {
bump: &'a Bump,
attributes: Vec<Attribute<'a>>,
}
impl<'a> HasAttributesBox<'a, Props<'a>> for Props<'a> {
fn push_attribute(
mut self,
name: &'a str,
ns: Option<&'static str>,
attr: impl IntoAttributeValue<'a>,
volatile: bool,
) -> Self {
self.attributes.push(Attribute {
name,
namespace: ns,
value: attr.into_value(self.bump),
volatile,
});
self
render! {
Component {
width: "10px",
height: "10px",
left: 1,
}
}
}
impl ExtendedGlobalAttributesMarker for Props<'_> {}
fn Component<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
let attributes = &*cx.props.attributes;
render! {
@@ -80,3 +31,9 @@ fn Component<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
}
}
}
#[derive(Props)]
struct Props<'a> {
#[props(extends = GlobalAttributes)]
attributes: Vec<Attribute<'a>>,
}