spread.rs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. use dioxus::{
  2. core::{exports::bumpalo::Bump, Attribute, HasAttributesBox},
  3. html::{ExtendedGlobalAttributesMarker, GlobalAttributesExtension},
  4. prelude::*,
  5. };
  6. fn main() {
  7. let mut dom = VirtualDom::new(app);
  8. let _ = dom.rebuild();
  9. let html = dioxus_ssr::render(&dom);
  10. println!("{}", html);
  11. }
  12. fn app(cx: Scope) -> Element {
  13. cx.render(::dioxus::core::LazyNodes::new(
  14. move |__cx: &::dioxus::core::ScopeState| -> ::dioxus::core::VNode {
  15. static TEMPLATE: ::dioxus::core::Template = ::dioxus::core::Template {
  16. name: "src/main.rs:15:15:289",
  17. roots: &[::dioxus::core::TemplateNode::Dynamic { id: 0usize }],
  18. node_paths: &[&[0u8]],
  19. attr_paths: &[],
  20. };
  21. ::dioxus::core::VNode {
  22. parent: None,
  23. key: None,
  24. template: std::cell::Cell::new(TEMPLATE),
  25. root_ids: dioxus::core::exports::bumpalo::collections::Vec::with_capacity_in(
  26. 1usize,
  27. __cx.bump(),
  28. )
  29. .into(),
  30. dynamic_nodes: __cx.bump().alloc([__cx.component(
  31. Component,
  32. Props {
  33. bump: __cx.bump(),
  34. attributes: Vec::new(),
  35. }
  36. .width(10)
  37. .height("100px"),
  38. "Component",
  39. )]),
  40. dynamic_attrs: __cx.bump().alloc([]),
  41. }
  42. },
  43. ))
  44. }
  45. #[derive(Props)]
  46. struct Props<'a> {
  47. bump: &'a Bump,
  48. attributes: Vec<Attribute<'a>>,
  49. }
  50. impl<'a> HasAttributesBox<'a, Props<'a>> for Props<'a> {
  51. fn push_attribute(
  52. mut self,
  53. name: &'a str,
  54. ns: Option<&'static str>,
  55. attr: impl IntoAttributeValue<'a>,
  56. volatile: bool,
  57. ) -> Self {
  58. self.attributes.push(Attribute {
  59. name,
  60. namespace: ns,
  61. value: attr.into_value(self.bump),
  62. volatile,
  63. });
  64. self
  65. }
  66. }
  67. impl ExtendedGlobalAttributesMarker for Props<'_> {}
  68. fn Component<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
  69. let attributes = &cx.props.attributes;
  70. render! {
  71. audio {
  72. ..attributes,
  73. }
  74. }
  75. }