Merge branch 'master' into jk/router2dotoh
This commit is contained in:
commit
59f8b49fb6
26 files changed
+324
-322
No files matched your search
@@ -187,8 +187,12 @@ impl Parse for ComponentField {
|
||||
}
|
||||
|
||||
if input.peek(LitStr) && input.peek2(Token![,]) {
|
||||
let content = ContentField::Formatted(input.parse()?);
|
||||
return Ok(Self { name, content });
|
||||
let t: LitStr = input.fork().parse()?;
|
||||
|
||||
if is_literal_foramtted(&t) {
|
||||
let content = ContentField::Formatted(input.parse()?);
|
||||
return Ok(Self { name, content });
|
||||
}
|
||||
}
|
||||
|
||||
if input.peek(LitStr) && input.peek2(LitStr) {
|
||||
@@ -209,3 +213,19 @@ impl ToTokens for ComponentField {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn is_literal_foramtted(lit: &LitStr) -> bool {
|
||||
let s = lit.value();
|
||||
let mut chars = s.chars();
|
||||
|
||||
while let Some(next) = chars.next() {
|
||||
if next == '{' {
|
||||
let nen = chars.next();
|
||||
if nen == Some('{') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
//! This is all kinda WIP, but the bones are there.
|
||||
|
||||
use crate::{ElementId, ScopeId};
|
||||
use std::{any::Any, cell::Cell, rc::Rc, sync::Arc};
|
||||
use std::{any::Any, cell::Cell, fmt::Debug, rc::Rc, sync::Arc};
|
||||
|
||||
pub(crate) struct BubbleState {
|
||||
pub canceled: Cell<bool>,
|
||||
@@ -143,6 +143,12 @@ pub struct UiEvent<T> {
|
||||
bubble_state: Rc<BubbleState>,
|
||||
}
|
||||
|
||||
impl<T: Debug> std::fmt::Debug for UiEvent<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("UiEvent").field("data", &self.data).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> std::ops::Deref for UiEvent<T> {
|
||||
type Target = T;
|
||||
|
||||
|
||||
@@ -690,8 +690,6 @@ impl ScopeState {
|
||||
}
|
||||
|
||||
/// Pushes the future onto the poll queue to be polled after the component renders.
|
||||
///
|
||||
/// The future is forcibly dropped if the component is not ready by the next render
|
||||
pub fn push_future(&self, fut: impl Future<Output = ()> + 'static) -> TaskId {
|
||||
// wake up the scheduler if it is sleeping
|
||||
self.tasks
|
||||
|
||||
@@ -66,7 +66,6 @@ use tao::{
|
||||
event::{Event, StartCause, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
|
||||
keyboard::{KeyCode, ModifiersState},
|
||||
menu::{MenuBar, MenuItem},
|
||||
window::{Window, WindowId},
|
||||
};
|
||||
pub use wry;
|
||||
@@ -293,7 +292,7 @@ impl DesktopController {
|
||||
match req.method.as_str() {
|
||||
"user_event" => {
|
||||
let event = events::trigger_from_serialized(req.params.unwrap());
|
||||
log::debug!("User event: {:?}", event);
|
||||
log::trace!("User event: {:?}", event);
|
||||
sender.unbounded_send(SchedulerMsg::Event(event)).unwrap();
|
||||
}
|
||||
"initialize" => {
|
||||
|
||||
@@ -59,7 +59,11 @@ impl<'a, T: 'static> UseState<'a, T> {
|
||||
|
||||
pub fn setter(&self) -> Rc<dyn Fn(T)> {
|
||||
let slot = self.0.wip.clone();
|
||||
Rc::new(move |new| *slot.borrow_mut() = Some(new))
|
||||
let callback = self.0.update_callback.clone();
|
||||
Rc::new(move |new| {
|
||||
callback();
|
||||
*slot.borrow_mut() = Some(new)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn wtih(&self, f: impl FnOnce(&mut T)) {
|
||||
|
||||
@@ -38,7 +38,7 @@ pub struct LinkProps<'a> {
|
||||
}
|
||||
|
||||
pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element {
|
||||
let service = cx.consume_context::<RouterService>().unwrap();
|
||||
let service = cx.consume_context::<RouterService>()?;
|
||||
cx.render(rsx! {
|
||||
a {
|
||||
href: "{cx.props.to}",
|
||||
|
||||
@@ -47,7 +47,7 @@ pub fn Route<'a>(cx: Scope<'a, RouteProps<'a>>) -> Element {
|
||||
Some(RouteInner {})
|
||||
});
|
||||
|
||||
log::debug!("Checking route {}", cx.props.to);
|
||||
log::trace!("Checking route {}", cx.props.to);
|
||||
|
||||
if router_root.should_render(cx.scope_id()) {
|
||||
cx.render(rsx!(&cx.props.children))
|
||||
|
||||
@@ -15,7 +15,7 @@ impl<'a> UseRoute<'a> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn last_segment(&self) -> Option<&str> {
|
||||
pub fn last_segment(&self) -> Option<&'a str> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
@@ -25,6 +25,6 @@ impl<'a> UseRoute<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn use_route(cx: &ScopeState) -> UseRoute {
|
||||
pub fn use_route<'a>(cx: &'a ScopeState) -> UseRoute<'a> {
|
||||
todo!()
|
||||
}
|
||||
@@ -47,7 +47,7 @@ impl RouterService {
|
||||
_root_found.set(false);
|
||||
// checking if the route is valid is cheap, so we do it
|
||||
for (slot, _) in _slots.borrow_mut().iter().rev() {
|
||||
log::debug!("regenerating slot {:?}", slot);
|
||||
log::trace!("regenerating slot {:?}", slot);
|
||||
regen(*slot);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,6 +19,7 @@ dioxus-core = { path = "../core", version = "^0.1.6", features = ["serialize"] }
|
||||
[dev-dependencies]
|
||||
dioxus-hooks = { path = "../hooks" }
|
||||
dioxus-html = { path = "../html" }
|
||||
dioxus-core-macro = { path = "../core-macro" }
|
||||
thiserror = "1.0.23"
|
||||
log = "0.4.13"
|
||||
fern = { version = "0.6.0", features = ["colored"] }
|
||||
@@ -27,4 +28,3 @@ argh = "0.1.4"
|
||||
serde = "1.0.120"
|
||||
serde_json = "1.0.61"
|
||||
fs_extra = "1.2.0"
|
||||
dioxus-core-macro = { path = "../core-macro" }
|
||||
@@ -17,7 +17,7 @@ This crate is a part of the broader Dioxus ecosystem. For more resources about D
|
||||
|
||||
Dioxus SSR provides utilities to render Dioxus components to valid HTML. Once rendered, the HTML can be rehydrated client side or served from your web-server of choice.
|
||||
|
||||
```rust
|
||||
```rust, ignore
|
||||
let app: Component = |cx| cx.render(rsx!(div {"hello world!"}));
|
||||
|
||||
let mut vdom = VirtualDom::new(app);
|
||||
@@ -32,7 +32,7 @@ assert_eq!(text, "<div>hello world!</div>")
|
||||
|
||||
The simplest example is to simply render some `rsx!` nodes to html. This can be done with the [`render_lazy`] api.
|
||||
|
||||
```rust
|
||||
```rust, ignore
|
||||
let content = dioxus::ssr::render(rsx!{
|
||||
div {
|
||||
(0..5).map(|i| rsx!(
|
||||
@@ -44,7 +44,7 @@ let content = dioxus::ssr::render(rsx!{
|
||||
|
||||
## Rendering a VirtualDom
|
||||
|
||||
```rust
|
||||
```rust, ignore
|
||||
let mut dom = VirtualDom::new(app);
|
||||
let _ = dom.rebuild();
|
||||
|
||||
@@ -54,7 +54,7 @@ let content = dioxus::ssr::render_vdom(&dom);
|
||||
## Configuring output
|
||||
It's possible to configure the output of the generated HTML.
|
||||
|
||||
```rust
|
||||
```rust, ignore
|
||||
let content = dioxus::ssr::render_vdom(&dom, |config| config.pretty(true).prerender(true));
|
||||
```
|
||||
|
||||
@@ -62,7 +62,7 @@ let content = dioxus::ssr::render_vdom(&dom, |config| config.pretty(true).preren
|
||||
|
||||
We provide the basic `SsrFormatter` object that implements `Display`, so you can integrate SSR into an existing string, or write directly to a file.
|
||||
|
||||
```rust
|
||||
```rust, ignore
|
||||
use std::fmt::{Error, Write};
|
||||
|
||||
let mut buf = String::new();
|
||||
@@ -92,7 +92,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
|
||||
```rust, ignore
|
||||
let dom = VirtualDom::new(App);
|
||||
|
||||
let text = dioxus::ssr::render_vdom(App, |cfg| cfg.pre_render(true));
|
||||
@@ -102,7 +102,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
|
||||
```rust, ignore
|
||||
let text = dioxus::ssr::render_vdom(&vdom);
|
||||
assert_eq!(text, "<div>hello world!</div>")
|
||||
```
|
||||
@@ -113,7 +113,7 @@ The rest of the space - IE doing this more efficiently, caching the virtualdom,
|
||||
|
||||
Dioxus SSR needs an arena to allocate from - whether it be the VirtualDom or a dedicated Bump allocator. To render `rsx!` directly to a string, you'll want to create an `SsrRenderer` and call `render_lazy`.
|
||||
|
||||
```rust
|
||||
```rust, ignore
|
||||
let text = dioxus::ssr::SsrRenderer::new().render_lazy(rsx!{
|
||||
div { "hello world" }
|
||||
});
|
||||
@@ -122,7 +122,7 @@ assert_eq!(text, "<div>hello world!</div>")
|
||||
|
||||
This can be automated with the `render_lazy!` macro:
|
||||
|
||||
```rust
|
||||
```rust, ignore
|
||||
let text = render_lazy!(rsx!( div { "hello world" } ));
|
||||
```
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
asd
|
||||
<div title="About W3Schools"><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 0</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 1</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 2</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 3</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 4</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 5</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 6</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 7</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 8</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 9</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 10</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 11</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 12</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 13</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 14</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 15</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 16</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 17</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 18</p></div><div title="About W3Schools" style="color:blue;text-align:center" class="About W3Schools"><p title="About W3Schools">Hello world!: 19</p></div></div>
|
||||
+12
-168
@@ -2,13 +2,15 @@
|
||||
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use dioxus_core::exports::bumpalo;
|
||||
use dioxus_core::exports::bumpalo::Bump;
|
||||
use dioxus_core::IntoVNode;
|
||||
use dioxus_core::*;
|
||||
|
||||
fn app(_cx: Scope) -> Element {
|
||||
None
|
||||
}
|
||||
|
||||
pub struct SsrRenderer {
|
||||
inner: bumpalo::Bump,
|
||||
vdom: VirtualDom,
|
||||
cfg: SsrConfig,
|
||||
}
|
||||
|
||||
@@ -16,21 +18,14 @@ impl SsrRenderer {
|
||||
pub fn new(cfg: impl FnOnce(SsrConfig) -> SsrConfig) -> Self {
|
||||
Self {
|
||||
cfg: cfg(SsrConfig::default()),
|
||||
inner: bumpalo::Bump::new(),
|
||||
vdom: VirtualDom::new(app),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_lazy<'a>(&'a mut self, f: LazyNodes<'a, '_>) -> String {
|
||||
let bump = &mut self.inner as *mut _;
|
||||
let s = self.render_inner(f);
|
||||
let scope = self.vdom.base_scope();
|
||||
let factory = NodeFactory::new(&scope);
|
||||
|
||||
// reuse the bump's memory
|
||||
unsafe { (&mut *bump as &mut bumpalo::Bump).reset() };
|
||||
s
|
||||
}
|
||||
|
||||
fn render_inner<'a>(&'a self, f: LazyNodes<'a, '_>) -> String {
|
||||
let factory = NodeFactory::new(&self.inner);
|
||||
let root = f.into_vnode(factory);
|
||||
format!(
|
||||
"{:}",
|
||||
@@ -44,8 +39,8 @@ impl SsrRenderer {
|
||||
}
|
||||
|
||||
pub fn render_lazy<'a>(f: LazyNodes<'a, '_>) -> String {
|
||||
let bump = bumpalo::Bump::new();
|
||||
let borrowed = ≎
|
||||
let vdom = VirtualDom::new(app);
|
||||
let scope: *const ScopeState = vdom.base_scope();
|
||||
|
||||
// Safety
|
||||
//
|
||||
@@ -57,9 +52,9 @@ pub fn render_lazy<'a>(f: LazyNodes<'a, '_>) -> String {
|
||||
//
|
||||
// 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.
|
||||
let scope = unsafe { &*scope };
|
||||
|
||||
let _b = unsafe { std::mem::transmute::<&Bump, &'a Bump>(borrowed) };
|
||||
let root = f.into_vnode(NodeFactory::new(_b));
|
||||
let root = f.into_vnode(NodeFactory::new(&scope));
|
||||
|
||||
format!(
|
||||
"{:}",
|
||||
@@ -282,154 +277,3 @@ impl SsrConfig {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use dioxus_core::prelude::*;
|
||||
use dioxus_core_macro::*;
|
||||
use dioxus_html as dioxus_elements;
|
||||
|
||||
static SIMPLE_APP: Component = |cx| {
|
||||
cx.render(rsx!(div {
|
||||
"hello world!"
|
||||
}))
|
||||
};
|
||||
|
||||
static SLIGHTLY_MORE_COMPLEX: Component = |cx| {
|
||||
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}"
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
static NESTED_APP: Component = |cx| {
|
||||
cx.render(rsx!(
|
||||
div {
|
||||
SIMPLE_APP {}
|
||||
}
|
||||
))
|
||||
};
|
||||
static FRAGMENT_APP: Component = |cx| {
|
||||
cx.render(rsx!(
|
||||
div { "f1" }
|
||||
div { "f2" }
|
||||
div { "f3" }
|
||||
div { "f4" }
|
||||
))
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn to_string_works() {
|
||||
let mut dom = VirtualDom::new(SIMPLE_APP);
|
||||
dom.rebuild();
|
||||
dbg!(render_vdom(&dom));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hydration() {
|
||||
let mut dom = VirtualDom::new(NESTED_APP);
|
||||
dom.rebuild();
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fragment_app() {
|
||||
let mut dom = VirtualDom::new(FRAGMENT_APP);
|
||||
dom.rebuild();
|
||||
dbg!(render_vdom(&dom));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_to_file() {
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
let mut file = File::create("index.html").unwrap();
|
||||
|
||||
let mut dom = VirtualDom::new(SLIGHTLY_MORE_COMPLEX);
|
||||
dom.rebuild();
|
||||
|
||||
file.write_fmt(format_args!(
|
||||
"{}",
|
||||
TextRenderer::from_vdom(&dom, SsrConfig::default())
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn styles() {
|
||||
static STLYE_APP: Component = |cx| {
|
||||
cx.render(rsx! {
|
||||
div { color: "blue", font_size: "46px" }
|
||||
})
|
||||
};
|
||||
|
||||
let mut dom = VirtualDom::new(STLYE_APP);
|
||||
dom.rebuild();
|
||||
dbg!(render_vdom(&dom));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lazy() {
|
||||
let p1 = SsrRenderer::new(|c| c).render_lazy(rsx! {
|
||||
div { "ello" }
|
||||
});
|
||||
|
||||
let p2 = render_lazy(rsx! {
|
||||
div {
|
||||
"ello"
|
||||
}
|
||||
});
|
||||
assert_eq!(p1, p2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn big_lazy() {
|
||||
let s = render_lazy(rsx! {
|
||||
div {
|
||||
div {
|
||||
div {
|
||||
h1 { "ello world" }
|
||||
h1 { "ello world" }
|
||||
h1 { "ello world" }
|
||||
h1 { "ello world" }
|
||||
h1 { "ello world" }
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dbg!(s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inner_html() {
|
||||
let s = render_lazy(rsx! {
|
||||
div {
|
||||
dangerous_inner_html: "<div> ack </div>"
|
||||
}
|
||||
});
|
||||
|
||||
dbg!(s);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
use dioxus_core::prelude::*;
|
||||
use dioxus_core_macro::*;
|
||||
use dioxus_html as dioxus_elements;
|
||||
use dioxus_ssr::{render_lazy, render_vdom, render_vdom_cfg, SsrConfig, SsrRenderer, TextRenderer};
|
||||
|
||||
static SIMPLE_APP: Component = |cx| {
|
||||
cx.render(rsx!(div {
|
||||
"hello world!"
|
||||
}))
|
||||
};
|
||||
|
||||
static SLIGHTLY_MORE_COMPLEX: Component = |cx| {
|
||||
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}"
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
static NESTED_APP: Component = |cx| {
|
||||
cx.render(rsx!(
|
||||
div {
|
||||
SIMPLE_APP {}
|
||||
}
|
||||
))
|
||||
};
|
||||
static FRAGMENT_APP: Component = |cx| {
|
||||
cx.render(rsx!(
|
||||
div { "f1" }
|
||||
div { "f2" }
|
||||
div { "f3" }
|
||||
div { "f4" }
|
||||
))
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn to_string_works() {
|
||||
let mut dom = VirtualDom::new(SIMPLE_APP);
|
||||
dom.rebuild();
|
||||
dbg!(render_vdom(&dom));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hydration() {
|
||||
let mut dom = VirtualDom::new(NESTED_APP);
|
||||
dom.rebuild();
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fragment_app() {
|
||||
let mut dom = VirtualDom::new(FRAGMENT_APP);
|
||||
dom.rebuild();
|
||||
dbg!(render_vdom(&dom));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_to_file() {
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
let mut file = File::create("index.html").unwrap();
|
||||
|
||||
let mut dom = VirtualDom::new(SLIGHTLY_MORE_COMPLEX);
|
||||
dom.rebuild();
|
||||
|
||||
file.write_fmt(format_args!(
|
||||
"{}",
|
||||
TextRenderer::from_vdom(&dom, SsrConfig::default())
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn styles() {
|
||||
static STLYE_APP: Component = |cx| {
|
||||
cx.render(rsx! {
|
||||
div { color: "blue", font_size: "46px" }
|
||||
})
|
||||
};
|
||||
|
||||
let mut dom = VirtualDom::new(STLYE_APP);
|
||||
dom.rebuild();
|
||||
dbg!(render_vdom(&dom));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lazy() {
|
||||
let p1 = SsrRenderer::new(|c| c).render_lazy(rsx! {
|
||||
div { "ello" }
|
||||
});
|
||||
|
||||
let p2 = render_lazy(rsx! {
|
||||
div {
|
||||
"ello"
|
||||
}
|
||||
});
|
||||
assert_eq!(p1, p2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn big_lazy() {
|
||||
let s = render_lazy(rsx! {
|
||||
div {
|
||||
div {
|
||||
div {
|
||||
h1 { "ello world" }
|
||||
h1 { "ello world" }
|
||||
h1 { "ello world" }
|
||||
h1 { "ello world" }
|
||||
h1 { "ello world" }
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dbg!(s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inner_html() {
|
||||
let s = render_lazy(rsx! {
|
||||
div {
|
||||
dangerous_inner_html: "<div> ack </div>"
|
||||
}
|
||||
});
|
||||
|
||||
dbg!(s);
|
||||
}
|
||||
@@ -281,7 +281,7 @@ impl WebsysDom {
|
||||
if name == synthetic_event.name
|
||||
|| name.trim_start_matches("on") == synthetic_event.name
|
||||
{
|
||||
log::debug!("Preventing default");
|
||||
log::trace!("Preventing default");
|
||||
event.prevent_default();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T
|
||||
|
||||
let mut websys_dom = dom::WebsysDom::new(root_el, cfg, sender_callback);
|
||||
|
||||
log::debug!("rebuilding app");
|
||||
log::trace!("rebuilding app");
|
||||
let mut mutations = dom.rebuild();
|
||||
|
||||
// hydrating is simply running the dom for a single render. If the page is already written, then the corresponding
|
||||
@@ -169,12 +169,12 @@ pub async fn run_with_props<T: 'static + Send>(root: Component<T>, root_props: T
|
||||
let work_loop = ric_raf::RafLoop::new();
|
||||
|
||||
loop {
|
||||
log::debug!("waiting for work");
|
||||
log::trace!("waiting for work");
|
||||
// if virtualdom has nothing, wait for it to have something before requesting idle time
|
||||
// if there is work then this future resolves immediately.
|
||||
dom.wait_for_work().await;
|
||||
|
||||
log::debug!("working..");
|
||||
log::trace!("working..");
|
||||
|
||||
// wait for the mainthread to schedule us in
|
||||
let mut deadline = work_loop.wait_for_idle_time().await;
|
||||
|
||||
Reference in new issue
Block a user