Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanceras committed Apr 17, 2024
1 parent 3b7d88c commit c13ddab
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 30 deletions.
11 changes: 3 additions & 8 deletions crates/core/src/dom/component/stateful_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ pub trait StatefulComponent {
/// and the attributes of the custom-element has been modified
///
/// if the listed attributes in the observed attributes are modified
fn attribute_changed(
&mut self,
attr_name: &str,
new_value: Vec<DomAttrValue>,
);
fn attribute_changed(&mut self, attr_name: &str, new_value: Vec<DomAttrValue>);
/// remove the attribute with this name
fn remove_attribute(&mut self, _attr_name: AttributeName) {}

Expand Down Expand Up @@ -163,10 +159,9 @@ where
#[cfg(feature = "with-dom")]
impl From<wasm_bindgen::JsValue> for DomAttrValue {
fn from(val: wasm_bindgen::JsValue) -> Self {
if val.is_null(){
if val.is_null() {
DomAttrValue::Empty
}
else if let Some(v) = val.as_bool() {
} else if let Some(v) = val.as_bool() {
DomAttrValue::Simple(v.into())
} else if let Some(v) = val.as_f64() {
DomAttrValue::Simple(v.into())
Expand Down
29 changes: 18 additions & 11 deletions crates/core/src/dom/dom_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl DomNode {

/// returns true if this an element node
pub fn is_element(&self) -> bool {
matches!(&self.inner, DomInner::Element{..})
matches!(&self.inner, DomInner::Element { .. })
}

/// returns true if this a fragment node
Expand Down Expand Up @@ -223,7 +223,7 @@ impl DomNode {
DomInner::Element { element, .. } => element.clone(),
DomInner::Fragment { fragment, .. } => {
let fragment: web_sys::Element = fragment.clone().unchecked_into();
fragment
fragment
}
DomInner::Text(text_node) => text_node.clone().unchecked_into(),
DomInner::Symbol(_) => unreachable!("symbol should be handled separately"),
Expand Down Expand Up @@ -386,7 +386,10 @@ impl DomNode {
replacement.dispatch_mount_event();
children.borrow_mut().insert(child_index, replacement);
} else {
log::warn!("unable to find target_child: {target_child:#?} with a replacement: {:?}", replacement);
log::warn!(
"unable to find target_child: {target_child:#?} with a replacement: {:?}",
replacement
);
// if can not find the child, then must be the root node
unreachable!("must find the child...");
}
Expand Down Expand Up @@ -551,16 +554,18 @@ impl DomNode {

/// always dispatch the mount event on stateful component
/// dispatch mount event to element that has on_mount callback set.
fn should_dispatch_mount_event(&self) -> bool{
match self.inner{
DomInner::Element{has_mount_callback,..} => has_mount_callback,
DomInner::StatefulComponent{..} => true,
fn should_dispatch_mount_event(&self) -> bool {
match self.inner {
DomInner::Element {
has_mount_callback, ..
} => has_mount_callback,
DomInner::StatefulComponent { .. } => true,
_ => false,
}
}

fn dispatch_mount_event(&self) {
if self.should_dispatch_mount_event(){
if self.should_dispatch_mount_event() {
let event_target: web_sys::EventTarget = self.as_element().unchecked_into();
event_target
.dispatch_event(&MountEvent::create_web_event())
Expand Down Expand Up @@ -827,9 +832,11 @@ where
),
);

let dom_attrs:Vec<DomAttr> = comp.attrs.iter().map(|a|self.convert_attr(a)).collect();
for dom_attr in dom_attrs.into_iter(){
comp.comp.borrow_mut().attribute_changed(dom_attr.name, dom_attr.value);
let dom_attrs: Vec<DomAttr> = comp.attrs.iter().map(|a| self.convert_attr(a)).collect();
for dom_attr in dom_attrs.into_iter() {
comp.comp
.borrow_mut()
.attribute_changed(dom_attr.name, dom_attr.value);
}
// the component children is manually appended to the StatefulComponent
// here to allow the conversion of dom nodes with its event
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/vdom/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ impl<MSG> Element<MSG> {

/// return true if this element has a mount callback
pub fn has_mount_callback(&self) -> bool {
self.attributes().iter().any(|a|a.is_mount_callback())
self.attributes().iter().any(|a| a.is_mount_callback())
}
}
1 change: 0 additions & 1 deletion crates/core/src/vdom/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ impl<MSG> Node<MSG> {
pub fn is_template(&self) -> bool {
matches!(self, Self::Leaf(Leaf::TemplatedView(_)))
}

}

/// create a virtual node with tag, attrs and children
Expand Down
1 change: 0 additions & 1 deletion crates/html-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ fn process_node<MSG>(node: &rphtml::parser::Node) -> Result<Option<Node<MSG>>, P
} else {
vec![]
};


match node.node_type {
NodeType::Tag => {
Expand Down
6 changes: 3 additions & 3 deletions examples/experimentals/src/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use sauron::dom::StatefulComponent;
use sauron::vdom::AttributeName;
use sauron::wasm_bindgen::JsCast;
use sauron::{
html::attributes::*, html::events::*, html::*, jss, vdom::Callback,
wasm_bindgen, web_sys, Attribute, Effects, JsValue, Node, *,
html::attributes::*, html::events::*, html::*, jss, vdom::Callback, wasm_bindgen, web_sys,
Attribute, Effects, JsValue, Node, *,
};
use std::fmt::Debug;

Expand Down Expand Up @@ -235,7 +235,7 @@ pub fn time<MSG, V: Into<Value>>(v: V) -> Attribute<MSG> {
attr("time", v)
}

pub fn date_time<MSG:'static>(
pub fn date_time<MSG: 'static>(
attrs: impl IntoIterator<Item = Attribute<MSG>>,
children: impl IntoIterator<Item = Node<MSG>>,
) -> Node<MSG> {
Expand Down
6 changes: 1 addition & 5 deletions examples/fancy-ui/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,7 @@ impl Feature {

impl<XMSG> StatefulComponent for Frame<XMSG> {
/// called when any of the attributes in observed_attributes is changed
fn attribute_changed(
&mut self,
attr_name: &str,
new_value: Vec<DomAttrValue>,
) {
fn attribute_changed(&mut self, attr_name: &str, new_value: Vec<DomAttrValue>) {
log::info!("attribuite changed: {attr_name}: {new_value:?}");
match attr_name {
"theme-primary" => {
Expand Down

0 comments on commit c13ddab

Please sign in to comment.