Skip to content

Commit

Permalink
fixed formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
its-the-shrimp committed Aug 20, 2023
1 parent 89bfee5 commit 437d7d9
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 39 deletions.
5 changes: 2 additions & 3 deletions packages/yew/src/html/component/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,16 @@ mod feat_ssr {
};
use crate::platform::fmt::BufWriter;
use crate::platform::pinned::oneshot;
use crate::scheduler;
use crate::virtual_dom::Collectable;
use crate::SpecialVTagKind;
use crate::{scheduler, SpecialVTagKind};

impl<COMP: BaseComponent> Scope<COMP> {
pub(crate) async fn render_into_stream(
&self,
w: &mut BufWriter,
props: Rc<COMP::Properties>,
hydratable: bool,
parent_vtag_kind: SpecialVTagKind
parent_vtag_kind: SpecialVTagKind,
) {
// Rust's Future implementation is stack-allocated and incurs zero runtime-cost.
//
Expand Down
16 changes: 12 additions & 4 deletions packages/yew/src/server_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ use crate::platform::{LocalHandle, Runtime};
#[cfg(feature = "ssr")]
#[derive(Default, Clone, Copy)]
pub(crate) enum SpecialVTagKind {
Style, // <style> tag
Style, // <style> tag
Script, // <script> tag
#[default] Other
#[default]
Other,
}

#[cfg(feature = "ssr")]
Expand All @@ -27,7 +28,9 @@ impl<T: AsRef<str>> From<T> for SpecialVTagKind {
Self::Style
} else if value.eq_ignore_ascii_case("script") {
Self::Script
} else {Self::Other}
} else {
Self::Other
}
}
}

Expand Down Expand Up @@ -121,7 +124,12 @@ where
let render_span = tracing::debug_span!("render_stream_item");
render_span.follows_from(outer_span);
scope
.render_into_stream(&mut w, self.props.into(), self.hydratable, Default::default())
.render_into_stream(
&mut w,
self.props.into(),
self.hydratable,
Default::default(),
)
.instrument(render_span)
.await;
})
Expand Down
6 changes: 3 additions & 3 deletions packages/yew/src/virtual_dom/vcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(crate) trait Mountable {
w: &'a mut BufWriter,
parent_scope: &'a AnyScope,
hydratable: bool,
parent_vtag_kind: SpecialVTagKind
parent_vtag_kind: SpecialVTagKind,
) -> LocalBoxFuture<'a, ()>;

#[cfg(feature = "hydration")]
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<COMP: BaseComponent> Mountable for PropsWrapper<COMP> {
w: &'a mut BufWriter,
parent_scope: &'a AnyScope,
hydratable: bool,
parent_vtag_kind: SpecialVTagKind
parent_vtag_kind: SpecialVTagKind,
) -> LocalBoxFuture<'a, ()> {
let scope: Scope<COMP> = Scope::new(Some(parent_scope.clone()));

Expand Down Expand Up @@ -265,7 +265,7 @@ mod feat_ssr {
w: &mut BufWriter,
parent_scope: &AnyScope,
hydratable: bool,
parent_vtag_kind: SpecialVTagKind
parent_vtag_kind: SpecialVTagKind,
) {
self.mountable
.as_ref()
Expand Down
9 changes: 5 additions & 4 deletions packages/yew/src/virtual_dom/vlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ mod feat_ssr {
w: &mut BufWriter,
parent_scope: &AnyScope,
hydratable: bool,
parent_vtag_kind: SpecialVTagKind
parent_vtag_kind: SpecialVTagKind,
) {
match &self[..] {
[] => {}
[child] => {
child.render_into_stream(w, parent_scope, hydratable, parent_vtag_kind)
child
.render_into_stream(w, parent_scope, hydratable, parent_vtag_kind)
.await;
}
_ => {
Expand All @@ -206,7 +207,7 @@ mod feat_ssr {
w: &mut BufWriter,
parent_scope: &AnyScope,
hydratable: bool,
parent_vtag_kind: SpecialVTagKind
parent_vtag_kind: SpecialVTagKind,
) where
I: Iterator<Item = &'a VNode>,
{
Expand Down Expand Up @@ -236,7 +237,7 @@ mod feat_ssr {
&mut next_w,
parent_scope,
hydratable,
parent_vtag_kind
parent_vtag_kind,
)
.await;
}
Expand Down
32 changes: 18 additions & 14 deletions packages/yew/src/virtual_dom/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,28 +204,32 @@ mod feat_ssr {
w: &'a mut BufWriter,
parent_scope: &'a AnyScope,
hydratable: bool,
parent_vtag_kind: SpecialVTagKind
parent_vtag_kind: SpecialVTagKind,
) -> LocalBoxFuture<'a, ()> {
async fn render_into_stream_(
this: &VNode,
w: &mut BufWriter,
parent_scope: &AnyScope,
hydratable: bool,
parent_vtag_kind: SpecialVTagKind
parent_vtag_kind: SpecialVTagKind,
) {
match this {
VNode::VTag(vtag) =>
vtag.render_into_stream(w, parent_scope, hydratable)
.await,
VNode::VText(vtext) =>
vtext.render_into_stream(w, parent_scope, hydratable, parent_vtag_kind)
.await,
VNode::VComp(vcomp) =>
vcomp.render_into_stream(w, parent_scope, hydratable, parent_vtag_kind)
.await,
VNode::VList(vlist) =>
vlist.render_into_stream(w, parent_scope, hydratable, parent_vtag_kind)
.await,
VNode::VTag(vtag) => vtag.render_into_stream(w, parent_scope, hydratable).await,
VNode::VText(vtext) => {
vtext
.render_into_stream(w, parent_scope, hydratable, parent_vtag_kind)
.await
}
VNode::VComp(vcomp) => {
vcomp
.render_into_stream(w, parent_scope, hydratable, parent_vtag_kind)
.await
}
VNode::VList(vlist) => {
vlist
.render_into_stream(w, parent_scope, hydratable, parent_vtag_kind)
.await
}
// We are pretty safe here as it's not possible to get a web_sys::Node without
// DOM support in the first place.
//
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/virtual_dom/vraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod feat_ssr {
&self,
w: &mut BufWriter,
_parent_scope: &AnyScope,
hydratable: bool
hydratable: bool,
) {
let collectable = Collectable::Raw;

Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/virtual_dom/vsuspense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ impl VSuspense {
#[cfg(feature = "ssr")]
mod feat_ssr {
use super::*;
use crate::SpecialVTagKind;
use crate::html::AnyScope;
use crate::platform::fmt::BufWriter;
use crate::virtual_dom::Collectable;
use crate::SpecialVTagKind;

impl VSuspense {
pub(crate) async fn render_into_stream(
&self,
w: &mut BufWriter,
parent_scope: &AnyScope,
hydratable: bool,
parent_vtag_kind: SpecialVTagKind
parent_vtag_kind: SpecialVTagKind,
) {
let collectable = Collectable::Suspense;

Expand Down
13 changes: 5 additions & 8 deletions packages/yew/src/virtual_dom/vtext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,22 @@ mod feat_ssr {
use std::fmt::Write;

use super::*;
use crate::SpecialVTagKind;
use crate::html::AnyScope;
use crate::platform::fmt::BufWriter;
use crate::SpecialVTagKind;

impl VText {
pub(crate) async fn render_into_stream(
&self,
w: &mut BufWriter,
_parent_scope: &AnyScope,
_hydratable: bool,
parent_vtag_kind: SpecialVTagKind
parent_vtag_kind: SpecialVTagKind,
) {
_ = w.write_str(&match parent_vtag_kind {
SpecialVTagKind::Style =>
html_escape::encode_style(&self.text),
SpecialVTagKind::Script =>
html_escape::encode_script(&self.text),
SpecialVTagKind::Other =>
html_escape::encode_text(&self.text)
SpecialVTagKind::Style => html_escape::encode_style(&self.text),
SpecialVTagKind::Script => html_escape::encode_script(&self.text),
SpecialVTagKind::Other => html_escape::encode_text(&self.text),
})
}
}
Expand Down

0 comments on commit 437d7d9

Please sign in to comment.