docs: update local examples and docs to support new syntaxes

This commit is contained in:
Jonathan Kelley committed 2021-12-15 15:56:53 -05:00
1 parent e495b09bf1
commit 4de16c4779
118 files changed
+520 -1154

No files matched your search

+4 -4
View File
@@ -5,7 +5,7 @@ Render a Dioxus VirtualDOM to a string.
```rust
// Our app:
const App: FC<()> = |cx, props| rsx!(cx, div {"hello world!"});
const App: Component<()> = |cx, props| rsx!(cx, div {"hello world!"});
// Build the virtualdom from our app
let mut vdom = VirtualDOM::new(App);
@@ -14,7 +14,7 @@ let mut vdom = VirtualDOM::new(App);
let _ = vdom.rebuild();
// Render the entire virtualdom from the root
let text = dioxus::ssr::render_vdom(&vdom, |c| c);
let text = dioxus::ssr::render_vdom(&vdom);
assert_eq!(text, "<div>hello world!</div>")
```
@@ -30,7 +30,7 @@ With pre-rendering enabled, this crate will generate element nodes with Element
To enable pre-rendering, simply configure the `SsrConfig` with pre-rendering enabled.
```rust
let dom = VirtualDom::new(App, |c| c);
let dom = VirtualDom::new(App);
let text = dioxus::ssr::render_vdom(App, |cfg| cfg.pre_render(true));
```
@@ -40,7 +40,7 @@ let text = dioxus::ssr::render_vdom(App, |cfg| cfg.pre_render(true));
Dioxus SSR can also be to render on the server. Obviously, you can just render the VirtualDOM to a string and send that down.
```rust
let text = dioxus::ssr::render_vdom(&vdom, |c| c);
let text = dioxus::ssr::render_vdom(&vdom);
assert_eq!(text, "<div>hello world!</div>")
```
+10 -7
View File
@@ -82,7 +82,10 @@ pub fn render_lazy<'a>(f: Option<LazyNodes<'a, '_>>) -> String {
)
}
pub fn render_vdom(dom: &VirtualDom, cfg: impl FnOnce(SsrConfig) -> SsrConfig) -> String {
pub fn render_vdom(dom: &VirtualDom) -> String {
format!("{:}", TextRenderer::from_vdom(dom, SsrConfig::default()))
}
pub fn render_vdom_cfg(dom: &VirtualDom, cfg: impl FnOnce(SsrConfig) -> SsrConfig) -> String {
format!(
"{:}",
TextRenderer::from_vdom(dom, cfg(SsrConfig::default()))
@@ -110,7 +113,7 @@ pub fn render_vdom_scope(vdom: &VirtualDom, scope: ScopeId) -> Option<String> {
///
/// ## Example
/// ```ignore
/// static App: FC<()> = |cx, props|cx.render(rsx!(div { "hello world" }));
/// static App: Component<()> = |cx, props|cx.render(rsx!(div { "hello world" }));
/// let mut vdom = VirtualDom::new(App);
/// vdom.rebuild();
///
@@ -343,28 +346,28 @@ mod tests {
fn to_string_works() {
let mut dom = VirtualDom::new(SIMPLE_APP);
dom.rebuild();
dbg!(render_vdom(&dom, |c| c));
dbg!(render_vdom(&dom));
}
#[test]
fn hydration() {
let mut dom = VirtualDom::new(NESTED_APP);
dom.rebuild();
dbg!(render_vdom(&dom, |c| c.pre_render(true)));
dbg!(render_vdom_cfg(&dom, |c| c.pre_render(true)));
}
#[test]
fn nested() {
let mut dom = VirtualDom::new(NESTED_APP);
dom.rebuild();
dbg!(render_vdom(&dom, |c| c));
dbg!(render_vdom(&dom));
}
#[test]
fn fragment_app() {
let mut dom = VirtualDom::new(FRAGMENT_APP);
dom.rebuild();
dbg!(render_vdom(&dom, |c| c));
dbg!(render_vdom(&dom));
}
#[test]
@@ -394,7 +397,7 @@ mod tests {
let mut dom = VirtualDom::new(STLYE_APP);
dom.rebuild();
dbg!(render_vdom(&dom, |c| c));
dbg!(render_vdom(&dom));
}
#[test]