2021-07-29 01:46:53 +00:00
|
|
|
//!
|
|
|
|
//!
|
|
|
|
//!
|
|
|
|
//!
|
2021-01-21 07:25:44 +00:00
|
|
|
//! This crate demonstrates how to implement a custom renderer for Dioxus VNodes via the `TextRenderer` renderer.
|
|
|
|
//! The `TextRenderer` consumes a Dioxus Virtual DOM, progresses its event queue, and renders the VNodes to a String.
|
|
|
|
//!
|
|
|
|
//! While `VNode` supports "to_string" directly, it renders child components as the RSX! macro tokens. For custom components,
|
|
|
|
//! an external renderer is needed to progress the component lifecycles. The `TextRenderer` shows how to use the Virtual DOM
|
|
|
|
//! API to progress these lifecycle events to generate a fully-mounted Virtual DOM instance which can be renderer in the
|
|
|
|
//! `render` method.
|
|
|
|
|
2021-07-11 21:24:47 +00:00
|
|
|
use std::fmt::{Display, Formatter};
|
2021-01-21 07:25:44 +00:00
|
|
|
|
2021-10-18 16:53:56 +00:00
|
|
|
use dioxus_core::exports::bumpalo;
|
2021-10-18 21:46:31 +00:00
|
|
|
use dioxus_core::exports::bumpalo::Bump;
|
2021-10-18 16:53:56 +00:00
|
|
|
use dioxus_core::nodes::IntoVNode;
|
2021-07-13 03:44:20 +00:00
|
|
|
use dioxus_core::*;
|
2021-07-11 18:49:52 +00:00
|
|
|
|
2021-10-18 21:46:31 +00:00
|
|
|
/// A memory pool for rendering
|
2021-10-18 16:53:56 +00:00
|
|
|
pub struct SsrRenderer {
|
|
|
|
inner: bumpalo::Bump,
|
2021-10-18 21:46:31 +00:00
|
|
|
cfg: SsrConfig,
|
2021-10-18 16:53:56 +00:00
|
|
|
}
|
2021-10-18 21:46:31 +00:00
|
|
|
|
|
|
|
impl SsrRenderer {
|
|
|
|
pub fn new(cfg: impl FnOnce(SsrConfig) -> SsrConfig) -> Self {
|
2021-10-18 16:53:56 +00:00
|
|
|
Self {
|
2021-10-18 21:46:31 +00:00
|
|
|
cfg: cfg(SsrConfig::default()),
|
2021-10-18 16:53:56 +00:00
|
|
|
inner: bumpalo::Bump::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:46:31 +00:00
|
|
|
pub fn render_lazy<'a, F: FnOnce(NodeFactory<'a>) -> VNode<'a>>(
|
|
|
|
&'a mut self,
|
|
|
|
f: LazyNodes<'a, F>,
|
|
|
|
) -> String {
|
|
|
|
let bump = &mut self.inner as *mut _;
|
|
|
|
let s = self.render_inner(f);
|
|
|
|
// reuse the bump's memory
|
|
|
|
unsafe { (&mut *bump as &mut bumpalo::Bump).reset() };
|
|
|
|
s
|
2021-10-18 16:53:56 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 21:46:31 +00:00
|
|
|
fn render_inner<'a, F: FnOnce(NodeFactory<'a>) -> VNode<'a>>(
|
2021-10-18 16:53:56 +00:00
|
|
|
&'a self,
|
|
|
|
f: LazyNodes<'a, F>,
|
|
|
|
) -> String {
|
|
|
|
let factory = NodeFactory::new(&self.inner);
|
|
|
|
let root = f.into_vnode(factory);
|
|
|
|
format!(
|
|
|
|
"{:}",
|
|
|
|
TextRenderer {
|
2021-10-18 21:46:31 +00:00
|
|
|
cfg: self.cfg.clone(),
|
2021-10-18 16:53:56 +00:00
|
|
|
root: &root,
|
|
|
|
vdom: None
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:46:31 +00:00
|
|
|
pub fn render_lazy<'a, F: FnOnce(NodeFactory<'a>) -> VNode<'a>>(f: LazyNodes<'a, F>) -> String {
|
|
|
|
let bump = bumpalo::Bump::new();
|
|
|
|
let borrowed = ≎
|
|
|
|
|
|
|
|
// Safety
|
|
|
|
//
|
|
|
|
// The lifetimes bounds on LazyNodes are really complicated - they need to support the nesting restrictions in
|
|
|
|
// regular component usage. The <'a> lifetime is used to enforce that all calls of IntoVnode use the same allocator.
|
|
|
|
//
|
|
|
|
// When LazyNodes are provided, they are FnOnce, but do not come with a allocator selected to borrow from. The <'a>
|
|
|
|
// lifetime is therefore longer than the lifetime of the allocator which doesn't exist yet.
|
|
|
|
//
|
|
|
|
// Therefore, we cast our local bump alloactor into right lifetime. This is okay because our usage of the bump arena
|
|
|
|
// is *definitely* shorter than the <'a> lifetime, and we return owned data - not borrowed data.
|
|
|
|
// Therefore, we know that no references are leaking.
|
|
|
|
let _b: &'a Bump = unsafe { std::mem::transmute(borrowed) };
|
|
|
|
|
|
|
|
let root = f.into_vnode(NodeFactory::new(_b));
|
|
|
|
|
|
|
|
format!(
|
|
|
|
"{:}",
|
|
|
|
TextRenderer {
|
|
|
|
cfg: SsrConfig::default(),
|
|
|
|
root: &root,
|
|
|
|
vdom: None
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2021-07-18 07:54:42 +00:00
|
|
|
|
2021-07-29 01:46:53 +00:00
|
|
|
pub fn render_vdom(dom: &VirtualDom, cfg: impl FnOnce(SsrConfig) -> SsrConfig) -> String {
|
|
|
|
format!(
|
|
|
|
"{:}",
|
|
|
|
TextRenderer::from_vdom(dom, cfg(SsrConfig::default()))
|
|
|
|
)
|
2021-07-18 07:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn render_vdom_scope(vdom: &VirtualDom, scope: ScopeId) -> Option<String> {
|
|
|
|
Some(format!(
|
|
|
|
"{:}",
|
|
|
|
TextRenderer {
|
|
|
|
cfg: SsrConfig::default(),
|
2021-09-13 22:55:43 +00:00
|
|
|
root: vdom.get_scope(scope).unwrap().root_node(),
|
2021-07-18 07:54:42 +00:00
|
|
|
vdom: Some(vdom)
|
|
|
|
}
|
|
|
|
))
|
2021-03-23 03:52:54 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 18:49:52 +00:00
|
|
|
/// A configurable text renderer for the Dioxus VirtualDOM.
|
|
|
|
///
|
2021-01-21 07:25:44 +00:00
|
|
|
///
|
2021-07-11 18:49:52 +00:00
|
|
|
/// ## Details
|
2021-01-21 07:25:44 +00:00
|
|
|
///
|
2021-07-11 18:49:52 +00:00
|
|
|
/// This uses the `Formatter` infrastructure so you can write into anything that supports `write_fmt`. We can't accept
|
|
|
|
/// any generic writer, so you need to "Display" the text renderer. This is done through `format!` or `format_args!`
|
2021-01-21 07:25:44 +00:00
|
|
|
///
|
2021-07-11 19:17:55 +00:00
|
|
|
/// ## Example
|
|
|
|
/// ```ignore
|
2021-10-16 21:37:28 +00:00
|
|
|
/// static App: FC<()> = |(cx, props)|cx.render(rsx!(div { "hello world" }));
|
2021-07-11 19:17:55 +00:00
|
|
|
/// let mut vdom = VirtualDom::new(App);
|
2021-08-24 16:43:46 +00:00
|
|
|
/// vdom.rebuild();
|
2021-07-11 18:49:52 +00:00
|
|
|
///
|
2021-07-11 19:17:55 +00:00
|
|
|
/// let renderer = TextRenderer::new(&vdom);
|
|
|
|
/// let output = format!("{}", renderer);
|
|
|
|
/// assert_eq!(output, "<div>hello world</div>");
|
|
|
|
/// ```
|
2021-10-18 16:53:56 +00:00
|
|
|
pub struct TextRenderer<'a, 'b> {
|
2021-07-18 07:54:42 +00:00
|
|
|
vdom: Option<&'a VirtualDom>,
|
2021-10-18 16:53:56 +00:00
|
|
|
root: &'b VNode<'a>,
|
2021-07-11 19:17:55 +00:00
|
|
|
cfg: SsrConfig,
|
2021-01-21 07:25:44 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 16:53:56 +00:00
|
|
|
impl Display for TextRenderer<'_, '_> {
|
2021-07-18 07:54:42 +00:00
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
self.html_render(self.root, f, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 16:53:56 +00:00
|
|
|
impl<'a> TextRenderer<'a, '_> {
|
2021-07-29 01:46:53 +00:00
|
|
|
pub fn from_vdom(vdom: &'a VirtualDom, cfg: SsrConfig) -> Self {
|
2021-07-11 19:17:55 +00:00
|
|
|
Self {
|
2021-07-29 01:46:53 +00:00
|
|
|
cfg,
|
2021-09-13 22:55:43 +00:00
|
|
|
root: vdom.base_scope().root_node(),
|
2021-07-18 07:54:42 +00:00
|
|
|
vdom: Some(vdom),
|
2021-07-11 19:17:55 +00:00
|
|
|
}
|
2021-01-21 07:25:44 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 23:31:07 +00:00
|
|
|
fn html_render(&self, node: &VNode, f: &mut std::fmt::Formatter, il: u16) -> std::fmt::Result {
|
2021-08-24 16:43:46 +00:00
|
|
|
match &node {
|
2021-08-20 14:34:41 +00:00
|
|
|
VNode::Text(text) => {
|
2021-07-11 23:31:07 +00:00
|
|
|
if self.cfg.indent {
|
|
|
|
for _ in 0..il {
|
|
|
|
write!(f, " ")?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write!(f, "{}", text.text)?
|
|
|
|
}
|
2021-10-18 21:46:31 +00:00
|
|
|
VNode::Anchor(_anchor) => {
|
2021-07-30 21:04:04 +00:00
|
|
|
//
|
|
|
|
if self.cfg.indent {
|
|
|
|
for _ in 0..il {
|
|
|
|
write!(f, " ")?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write!(f, "<!-- -->")?;
|
|
|
|
}
|
2021-08-20 14:34:41 +00:00
|
|
|
VNode::Element(el) => {
|
2021-07-11 23:31:07 +00:00
|
|
|
if self.cfg.indent {
|
|
|
|
for _ in 0..il {
|
|
|
|
write!(f, " ")?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-11 18:49:52 +00:00
|
|
|
write!(f, "<{}", el.tag_name)?;
|
2021-07-15 15:06:52 +00:00
|
|
|
let mut attr_iter = el.attributes.iter().peekable();
|
|
|
|
|
|
|
|
while let Some(attr) = attr_iter.next() {
|
|
|
|
match attr.namespace {
|
|
|
|
None => write!(f, " {}=\"{}\"", attr.name, attr.value)?,
|
|
|
|
|
|
|
|
Some(ns) => {
|
|
|
|
// write the opening tag
|
|
|
|
write!(f, " {}=\"", ns)?;
|
|
|
|
let mut cur_ns_el = attr;
|
|
|
|
'ns_parse: loop {
|
|
|
|
write!(f, "{}:{};", cur_ns_el.name, cur_ns_el.value)?;
|
|
|
|
match attr_iter.peek() {
|
|
|
|
Some(next_attr) if next_attr.namespace == Some(ns) => {
|
|
|
|
cur_ns_el = attr_iter.next().unwrap();
|
|
|
|
}
|
|
|
|
_ => break 'ns_parse,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// write the closing tag
|
|
|
|
write!(f, "\"")?;
|
|
|
|
}
|
|
|
|
}
|
2021-07-11 18:49:52 +00:00
|
|
|
}
|
2021-07-15 15:06:52 +00:00
|
|
|
|
2021-07-29 01:46:53 +00:00
|
|
|
// we write the element's id as a data attribute
|
|
|
|
//
|
|
|
|
// when the page is loaded, the `querySelectorAll` will be used to collect all the nodes, and then add
|
|
|
|
// them interpreter's stack
|
2021-10-18 21:46:31 +00:00
|
|
|
if let (true, Some(id)) = (self.cfg.pre_render, node.try_mounted_id()) {
|
|
|
|
write!(f, " dio_el=\"{}\"", id)?;
|
|
|
|
|
|
|
|
for _listener in el.listeners {
|
|
|
|
// todo: write the listeners
|
2021-07-29 01:46:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-11 19:17:55 +00:00
|
|
|
match self.cfg.newline {
|
2021-10-18 21:46:31 +00:00
|
|
|
true => writeln!(f, ">")?,
|
2021-07-11 19:17:55 +00:00
|
|
|
false => write!(f, ">")?,
|
|
|
|
}
|
|
|
|
|
2021-07-11 18:49:52 +00:00
|
|
|
for child in el.children {
|
2021-07-11 23:31:07 +00:00
|
|
|
self.html_render(child, f, il + 1)?;
|
2021-07-11 18:49:52 +00:00
|
|
|
}
|
2021-07-11 23:31:07 +00:00
|
|
|
|
|
|
|
if self.cfg.newline {
|
2021-10-18 21:46:31 +00:00
|
|
|
writeln!(f)?;
|
2021-07-11 23:31:07 +00:00
|
|
|
}
|
|
|
|
if self.cfg.indent {
|
|
|
|
for _ in 0..il {
|
|
|
|
write!(f, " ")?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
write!(f, "</{}>", el.tag_name)?;
|
|
|
|
if self.cfg.newline {
|
2021-10-18 21:46:31 +00:00
|
|
|
writeln!(f)?;
|
2021-07-11 19:17:55 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-20 14:34:41 +00:00
|
|
|
VNode::Fragment(frag) => {
|
2021-07-11 19:17:55 +00:00
|
|
|
for child in frag.children {
|
2021-07-11 23:31:07 +00:00
|
|
|
self.html_render(child, f, il + 1)?;
|
2021-07-11 19:17:55 +00:00
|
|
|
}
|
2021-07-11 18:49:52 +00:00
|
|
|
}
|
2021-08-20 14:34:41 +00:00
|
|
|
VNode::Component(vcomp) => {
|
2021-08-27 13:53:26 +00:00
|
|
|
let idx = vcomp.associated_scope.get().unwrap();
|
2021-10-18 21:46:31 +00:00
|
|
|
|
|
|
|
if let (Some(vdom), false) = (self.vdom, self.cfg.skip_components) {
|
|
|
|
let new_node = vdom.get_scope(idx).unwrap().root_node();
|
|
|
|
self.html_render(new_node, f, il + 1)?;
|
|
|
|
} else {
|
2021-07-18 07:54:42 +00:00
|
|
|
}
|
2021-07-11 18:49:52 +00:00
|
|
|
}
|
2021-08-20 14:34:41 +00:00
|
|
|
VNode::Suspended { .. } => {
|
2021-07-15 07:38:09 +00:00
|
|
|
// we can't do anything with suspended nodes
|
|
|
|
}
|
2021-07-11 18:49:52 +00:00
|
|
|
}
|
2021-07-11 19:17:55 +00:00
|
|
|
Ok(())
|
2021-01-21 07:25:44 +00:00
|
|
|
}
|
2021-07-11 18:49:52 +00:00
|
|
|
}
|
2021-01-21 07:25:44 +00:00
|
|
|
|
2021-10-18 21:46:31 +00:00
|
|
|
#[derive(Clone, Debug, Default)]
|
2021-07-29 01:46:53 +00:00
|
|
|
pub struct SsrConfig {
|
2021-09-25 02:15:50 +00:00
|
|
|
/// currently not supported - control if we indent the HTML output
|
2021-07-29 01:46:53 +00:00
|
|
|
indent: bool,
|
|
|
|
|
2021-09-25 02:15:50 +00:00
|
|
|
/// Control if elements are written onto a new line
|
2021-07-29 01:46:53 +00:00
|
|
|
newline: bool,
|
|
|
|
|
2021-09-25 02:15:50 +00:00
|
|
|
/// Choose to write ElementIDs into elements so the page can be re-hydrated later on
|
2021-07-29 01:46:53 +00:00
|
|
|
pre_render: bool,
|
|
|
|
|
|
|
|
// Currently not implemented
|
|
|
|
// Don't proceed onto new components. Instead, put the name of the component.
|
|
|
|
// TODO: components don't have names :(
|
|
|
|
skip_components: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SsrConfig {
|
|
|
|
pub fn indent(mut self, a: bool) -> Self {
|
|
|
|
self.indent = a;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
pub fn newline(mut self, a: bool) -> Self {
|
|
|
|
self.newline = a;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
pub fn pre_render(mut self, a: bool) -> Self {
|
|
|
|
self.pre_render = a;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
pub fn skip_components(mut self, a: bool) -> Self {
|
|
|
|
self.skip_components = a;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-11 18:49:52 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2021-01-21 07:25:44 +00:00
|
|
|
|
2021-07-11 18:49:52 +00:00
|
|
|
use dioxus_core as dioxus;
|
2021-07-11 21:24:47 +00:00
|
|
|
use dioxus_core::prelude::*;
|
2021-09-25 01:46:23 +00:00
|
|
|
use dioxus_core_macro::*;
|
2021-09-25 02:15:50 +00:00
|
|
|
use dioxus_html as dioxus_elements;
|
2021-02-03 07:26:04 +00:00
|
|
|
|
2021-10-18 21:46:31 +00:00
|
|
|
static SIMPLE_APP: FC<()> = |(cx, _)| {
|
2021-07-11 18:49:52 +00:00
|
|
|
cx.render(rsx!(div {
|
|
|
|
"hello world!"
|
|
|
|
}))
|
|
|
|
};
|
2021-01-21 07:25:44 +00:00
|
|
|
|
2021-10-18 21:46:31 +00:00
|
|
|
static SLIGHTLY_MORE_COMPLEX: FC<()> = |(cx, _)| {
|
2021-07-11 18:49:52 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
title: "About W3Schools"
|
|
|
|
{(0..20).map(|f| rsx!{
|
|
|
|
div {
|
|
|
|
title: "About W3Schools"
|
|
|
|
style: "color:blue;text-align:center"
|
|
|
|
class: "About W3Schools"
|
|
|
|
p {
|
|
|
|
title: "About W3Schools"
|
|
|
|
"Hello world!: {f}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2021-10-18 21:46:31 +00:00
|
|
|
static NESTED_APP: FC<()> = |(cx, _)| {
|
2021-07-11 21:24:47 +00:00
|
|
|
cx.render(rsx!(
|
|
|
|
div {
|
|
|
|
SIMPLE_APP {}
|
|
|
|
}
|
|
|
|
))
|
|
|
|
};
|
2021-10-18 21:46:31 +00:00
|
|
|
static FRAGMENT_APP: FC<()> = |(cx, _)| {
|
2021-07-11 21:24:47 +00:00
|
|
|
cx.render(rsx!(
|
|
|
|
div { "f1" }
|
|
|
|
div { "f2" }
|
|
|
|
div { "f3" }
|
|
|
|
div { "f4" }
|
|
|
|
))
|
|
|
|
};
|
|
|
|
|
2021-07-11 18:49:52 +00:00
|
|
|
#[test]
|
2021-07-11 21:24:47 +00:00
|
|
|
fn to_string_works() {
|
2021-07-11 18:49:52 +00:00
|
|
|
let mut dom = VirtualDom::new(SIMPLE_APP);
|
2021-08-24 19:12:20 +00:00
|
|
|
dom.rebuild();
|
2021-07-29 01:46:53 +00:00
|
|
|
dbg!(render_vdom(&dom, |c| c));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hydration() {
|
|
|
|
let mut dom = VirtualDom::new(NESTED_APP);
|
2021-08-24 19:12:20 +00:00
|
|
|
dom.rebuild();
|
2021-07-29 01:46:53 +00:00
|
|
|
dbg!(render_vdom(&dom, |c| c.pre_render(true)));
|
2021-01-21 07:25:44 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 18:49:52 +00:00
|
|
|
#[test]
|
2021-07-11 21:24:47 +00:00
|
|
|
fn nested() {
|
|
|
|
let mut dom = VirtualDom::new(NESTED_APP);
|
2021-08-24 19:12:20 +00:00
|
|
|
dom.rebuild();
|
2021-07-29 01:46:53 +00:00
|
|
|
dbg!(render_vdom(&dom, |c| c));
|
2021-07-11 21:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fragment_app() {
|
|
|
|
let mut dom = VirtualDom::new(FRAGMENT_APP);
|
2021-08-24 19:12:20 +00:00
|
|
|
dom.rebuild();
|
2021-07-29 01:46:53 +00:00
|
|
|
dbg!(render_vdom(&dom, |c| c));
|
2021-07-11 21:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn write_to_file() {
|
2021-07-11 18:49:52 +00:00
|
|
|
use std::fs::File;
|
2021-07-11 21:24:47 +00:00
|
|
|
use std::io::Write;
|
2021-07-11 18:49:52 +00:00
|
|
|
|
|
|
|
let mut file = File::create("index.html").unwrap();
|
|
|
|
|
2021-07-11 19:17:55 +00:00
|
|
|
let mut dom = VirtualDom::new(SLIGHTLY_MORE_COMPLEX);
|
2021-08-24 19:12:20 +00:00
|
|
|
dom.rebuild();
|
2021-07-11 18:49:52 +00:00
|
|
|
|
2021-07-29 01:46:53 +00:00
|
|
|
file.write_fmt(format_args!(
|
|
|
|
"{}",
|
|
|
|
TextRenderer::from_vdom(&dom, SsrConfig::default())
|
|
|
|
))
|
|
|
|
.unwrap();
|
2021-01-16 04:25:29 +00:00
|
|
|
}
|
2021-07-15 15:06:52 +00:00
|
|
|
|
2021-07-29 01:46:53 +00:00
|
|
|
#[test]
|
|
|
|
fn styles() {
|
2021-10-18 21:46:31 +00:00
|
|
|
static STLYE_APP: FC<()> = |(cx, _)| {
|
2021-07-29 01:46:53 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
div { style: { color: "blue", font_size: "46px" } }
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut dom = VirtualDom::new(STLYE_APP);
|
2021-08-24 19:12:20 +00:00
|
|
|
dom.rebuild();
|
2021-07-29 01:46:53 +00:00
|
|
|
dbg!(render_vdom(&dom, |c| c));
|
|
|
|
}
|
2021-10-18 16:53:56 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lazy() {
|
2021-10-18 21:46:31 +00:00
|
|
|
let p1 = SsrRenderer::new(|c| c).render_lazy(rsx! {
|
|
|
|
div { "ello" }
|
|
|
|
});
|
|
|
|
|
|
|
|
let p2 = render_lazy(rsx! {
|
2021-10-18 16:53:56 +00:00
|
|
|
div {
|
|
|
|
"ello"
|
|
|
|
}
|
|
|
|
});
|
2021-10-18 21:46:31 +00:00
|
|
|
assert_eq!(p1, p2);
|
|
|
|
}
|
2021-10-18 16:53:56 +00:00
|
|
|
|
2021-10-18 21:46:31 +00:00
|
|
|
#[test]
|
|
|
|
fn big_lazy() {
|
|
|
|
let s = render_lazy(rsx! {
|
2021-10-18 16:53:56 +00:00
|
|
|
div {
|
2021-10-18 21:46:31 +00:00
|
|
|
div {
|
|
|
|
div {
|
|
|
|
h1 { "ello world" }
|
|
|
|
h1 { "ello world" }
|
|
|
|
h1 { "ello world" }
|
|
|
|
h1 { "ello world" }
|
|
|
|
h1 { "ello world" }
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 16:53:56 +00:00
|
|
|
}
|
|
|
|
});
|
2021-10-18 21:46:31 +00:00
|
|
|
|
|
|
|
dbg!(s);
|
2021-10-18 16:53:56 +00:00
|
|
|
}
|
2021-01-16 04:25:29 +00:00
|
|
|
}
|