mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 04:33:06 +00:00
chore: clean up the repo some
This commit is contained in:
parent
5a0ae67ccb
commit
5673017def
13 changed files with 30 additions and 27 deletions
|
@ -10,7 +10,7 @@ fn main() {
|
|||
let mut dom = VirtualDom::new(app);
|
||||
let _ = dom.rebuild();
|
||||
|
||||
let output = dioxus_ssr::render_vdom(&dom);
|
||||
let output = dioxus_ssr::render(&dom);
|
||||
|
||||
println!("{}", output);
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
//! It also proves that lifetimes work properly, especially when used with use_ref
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_ssr::config::Config;
|
||||
|
||||
fn main() {
|
||||
let mut vdom = VirtualDom::new(example);
|
||||
_ = vdom.rebuild();
|
||||
|
||||
let out = dioxus_ssr::render_vdom_cfg(&vdom, Config::default().newline(true).indent(true));
|
||||
println!("{}", out);
|
||||
let mut renderer = dioxus_ssr::Renderer::new();
|
||||
renderer.pretty = true;
|
||||
renderer.render(&vdom);
|
||||
}
|
||||
|
||||
fn example(cx: Scope) -> Element {
|
||||
|
|
|
@ -24,7 +24,7 @@ macro_rules! use_callback {
|
|||
)
|
||||
};
|
||||
}
|
||||
pub fn use_callback<'a, T, R, F>(cx: &'a ScopeState, make: impl FnOnce() -> R) -> impl FnMut(T) + 'a
|
||||
pub fn use_callback<T, R, F>(cx: &ScopeState, make: impl FnOnce() -> R) -> impl FnMut(T) + '_
|
||||
where
|
||||
R: FnMut(T) -> F + 'static,
|
||||
F: Future<Output = ()> + 'static,
|
||||
|
|
|
@ -51,7 +51,7 @@ where
|
|||
|
||||
// Clone in our cells
|
||||
let values = state.values.clone();
|
||||
let _schedule_update = state.update.clone();
|
||||
let schedule_update = state.update.clone();
|
||||
let waker = state.waker.clone();
|
||||
|
||||
// Cancel the current future
|
||||
|
@ -66,10 +66,7 @@ where
|
|||
// if there's a waker, we dont re-render the component. Instead we just progress that future
|
||||
match waker.borrow().as_ref() {
|
||||
Some(waker) => waker.wake_by_ref(),
|
||||
None => {
|
||||
|
||||
// schedule_update()
|
||||
}
|
||||
None => schedule_update(),
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element {
|
|||
}
|
||||
};
|
||||
|
||||
let route = use_route(&cx);
|
||||
let route = use_route(cx);
|
||||
let url = route.url();
|
||||
let path = url.path();
|
||||
let active = path == cx.props.to;
|
||||
|
|
|
@ -32,7 +32,7 @@ pub struct RedirectProps<'a> {
|
|||
///
|
||||
/// It will replace the current route rather than pushing the current one to the stack.
|
||||
pub fn Redirect<'a>(cx: Scope<'a, RedirectProps<'a>>) -> Element {
|
||||
let router = use_router(&cx);
|
||||
let router = use_router(cx);
|
||||
|
||||
let immediate_redirect = cx.use_hook(|| {
|
||||
if let Some(from) = cx.props.from {
|
||||
|
|
|
@ -42,7 +42,7 @@ pub fn Route<'a>(cx: Scope<'a, RouteProps<'a>>) -> Element {
|
|||
});
|
||||
|
||||
// submit our rout
|
||||
router_root.register_total_route(route_context.total_route.clone(), cx.scope_id());
|
||||
router_root.register_total_route(route_context.total_route, cx.scope_id());
|
||||
});
|
||||
|
||||
log::trace!("Checking Route: {:?}", cx.props.to);
|
||||
|
|
|
@ -41,7 +41,7 @@ pub struct RouterProps<'a> {
|
|||
pub fn Router<'a>(cx: Scope<'a, RouterProps<'a>>) -> Element {
|
||||
let svc = use_context_provider(cx, || {
|
||||
RouterService::new(
|
||||
&cx,
|
||||
cx,
|
||||
RouterCfg {
|
||||
base_url: cx.props.base_url.map(|s| s.to_string()),
|
||||
active_class: cx.props.active_class.map(|s| s.to_string()),
|
||||
|
|
|
@ -60,7 +60,7 @@ impl Component {
|
|||
match self
|
||||
.fields
|
||||
.iter()
|
||||
.find(|f| f.name.to_string() == "key")
|
||||
.find(|f| f.name == "key")
|
||||
.map(|f| &f.content)
|
||||
{
|
||||
Some(ContentField::Formatted(fmt)) => Some(fmt),
|
||||
|
|
|
@ -21,10 +21,7 @@ pub struct IfmtInput {
|
|||
|
||||
impl IfmtInput {
|
||||
pub fn is_static(&self) -> bool {
|
||||
match self.segments.as_slice() {
|
||||
&[Segment::Literal(_)] => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.segments.as_slice(), &[Segment::Literal(_)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -180,10 +180,10 @@ impl<'a> DynamicContext<'a> {
|
|||
// [0, 2]
|
||||
// [0, 2, 1]
|
||||
|
||||
let static_attrs = el.attributes.iter().filter_map(|attr| match &attr.attr {
|
||||
let static_attrs = el.attributes.iter().map(|attr| match &attr.attr {
|
||||
ElementAttr::AttrText { name, value } if value.is_static() => {
|
||||
let value = value.source.as_ref().unwrap();
|
||||
Some(quote! {
|
||||
quote! {
|
||||
::dioxus::core::TemplateAttribute::Static {
|
||||
name: dioxus_elements::#el_name::#name.0,
|
||||
namespace: dioxus_elements::#el_name::#name.1,
|
||||
|
@ -192,12 +192,12 @@ impl<'a> DynamicContext<'a> {
|
|||
// todo: we don't diff these so we never apply the volatile flag
|
||||
// volatile: dioxus_elements::#el_name::#name.2,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
ElementAttr::CustomAttrText { name, value } if value.is_static() => {
|
||||
let value = value.source.as_ref().unwrap();
|
||||
Some(quote! {
|
||||
quote! {
|
||||
::dioxus::core::TemplateAttribute::Static {
|
||||
name: dioxus_elements::#el_name::#name.0,
|
||||
namespace: dioxus_elements::#el_name::#name.1,
|
||||
|
@ -206,7 +206,7 @@ impl<'a> DynamicContext<'a> {
|
|||
// todo: we don't diff these so we never apply the volatile flag
|
||||
// volatile: dioxus_elements::#el_name::#name.2,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
ElementAttr::AttrExpression { .. }
|
||||
|
@ -217,7 +217,7 @@ impl<'a> DynamicContext<'a> {
|
|||
let ct = self.dynamic_attributes.len();
|
||||
self.dynamic_attributes.push(attr);
|
||||
self.attr_paths.push(self.current_path.clone());
|
||||
Some(quote! { ::dioxus::core::TemplateAttribute::Dynamic { id: #ct } })
|
||||
quote! { ::dioxus::core::TemplateAttribute::Dynamic { id: #ct } }
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ impl ToTokens for BodyNode {
|
|||
pat, expr, body, ..
|
||||
} = exp;
|
||||
|
||||
let renderer = TemplateRenderer { roots: &body };
|
||||
let renderer = TemplateRenderer { roots: body };
|
||||
|
||||
tokens.append_all(quote! {
|
||||
__cx.make_node(
|
||||
|
|
|
@ -7,7 +7,7 @@ pub mod template;
|
|||
use dioxus_core::{Element, LazyNodes, Scope, VirtualDom};
|
||||
use std::cell::Cell;
|
||||
|
||||
use crate::renderer::Renderer;
|
||||
pub use crate::renderer::Renderer;
|
||||
|
||||
/// A convenience function to render an `rsx!` call to a string
|
||||
///
|
||||
|
@ -44,3 +44,12 @@ pub fn render_lazy(f: LazyNodes<'_, '_>) -> String {
|
|||
pub fn render(dom: &VirtualDom) -> String {
|
||||
Renderer::new().render(dom)
|
||||
}
|
||||
|
||||
/// A convenience function to pre-render an existing VirtualDom to a string
|
||||
///
|
||||
/// We generally recommend creating a new `Renderer` to take advantage of template caching.
|
||||
pub fn pre_render(dom: &VirtualDom) -> String {
|
||||
let mut renderer = Renderer::new();
|
||||
renderer.pre_render = true;
|
||||
renderer.render(dom)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue