Skip to content

Commit

Permalink
fix: remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanceras committed Mar 5, 2024
1 parent fec3fdd commit 4b1930d
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion crates/sauron-core/src/dom/dom_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ where
event_name: &str,
listener: &Listener<dom::Event, MSG>,
) -> Result<Closure<dyn FnMut(web_sys::Event)>, JsValue> {
let program = Program::downgrade(&self);
let program = Program::downgrade(self);
let listener = listener.clone();

let closure: Closure<dyn FnMut(web_sys::Event)> =
Expand Down
4 changes: 2 additions & 2 deletions crates/sauron-core/src/dom/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ impl InputEvent {
} else if let Some(select) = target.dyn_ref::<HtmlSelectElement>() {
select.value()
} else if let Some(html_elm) = target.dyn_ref::<HtmlElement>() {
let content = html_elm.get_attribute("content").expect("get content");
content

html_elm.get_attribute("content").expect("get content")
} else {
panic!("fail in mapping event into input event");
}
Expand Down
16 changes: 8 additions & 8 deletions crates/sauron-core/src/dom/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::dom::{util::body, AnimationFrameHandle, Application, DomPatch, IdleCa
use crate::html::{self, attributes::class, text};
use crate::vdom;
use crate::vdom::diff;
use crate::vdom::KEY;

use app_context::AppContext;
use crate::vdom::{diff_recursive, TreePath};
use std::collections::hash_map::DefaultHasher;
Expand Down Expand Up @@ -609,27 +609,27 @@ where
log::debug!("new_node: {new_node:#?}");
log::debug!("old_node: {old_node:#?}");
diff_recursive(
&old_node,
&new_node,
old_node,
new_node,
&path,
)
})
.collect::<Vec<_>>();
log::info!("patches: {patches:#?}");
patches
} else {
let patches = diff(&current_vdom, &new_vdom);
let patches = diff(&current_vdom, new_vdom);
patches
};
#[cfg(all(feature = "with-debug", feature = "log-patches"))]
{
log::debug!("There are {} patches", patches.len());
log::debug!("patches: {patches:#?}");
}
let dom_patches = self

self
.convert_patches(&patches)
.expect("must convert patches");
dom_patches
.expect("must convert patches")
}

#[cfg(feature = "with-raf")]
Expand Down Expand Up @@ -693,7 +693,7 @@ where

#[cfg(not(feature = "with-raf"))]
{
let program = Program::downgrade(&self);
let program = Program::downgrade(self);
wasm_bindgen_futures::spawn_local(async move {
if let Some(mut program) = program.upgrade() {
program.dispatch_inner(None);
Expand Down
2 changes: 1 addition & 1 deletion crates/sauron-core/src/dom/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ where
where
F: FnMut(String) -> MSG + 'static,
{
let program = Program::downgrade(&self);
let program = Program::downgrade(self);
let closure: Closure<dyn FnMut(web_sys::Event)> = Closure::new(move |_| {
let hash = util::get_location_hash();
let msg = cb(hash);
Expand Down
2 changes: 1 addition & 1 deletion crates/sauron-core/src/html/attributes/attribute_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
html::attributes::{Style, Value},
vdom::Listener,
};
use std::fmt::{self, Debug};

use derive_where::derive_where;

/// Values of an attribute can be in these variants
Expand Down
6 changes: 4 additions & 2 deletions crates/sauron-core/src/html/attributes/special.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ use crate::vdom::AttributeName;
/// such as key and skip which both greatly affects the diffing algorithm
impl<MSG> Node<MSG> {
/// get the first value of the attribute which has the name `att_name` of this node
pub fn get_value(&self, att_name: &AttributeName) -> Option<&Value> {
self.attribute_value(&att_name)
self.attribute_value(att_name)
.and_then(|att_values| att_values.first().and_then(|v| v.get_simple()))
}
}

impl<MSG> Element<MSG> {
/// get the first value of the attribute which has the name `att_name` of this element
pub fn get_value(&self, att_name: &AttributeName) -> Option<&Value> {
self.attribute_value(&att_name)
self.attribute_value(att_name)
.and_then(|att_values| att_values.first().and_then(|v| v.get_simple()))
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sauron-core/src/html/attributes/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Style {
/// create a style with name and value
pub fn new(name: impl Into<Cow<'static, str>>, value: impl Into<Value>) -> Self {
Style {
name: Cow::from(name.into()),
name: name.into(),
value: value.into(),
}
}
Expand Down
2 changes: 0 additions & 2 deletions crates/sauron-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*
#![deny(
warnings,
missing_docs,
Expand All @@ -10,7 +9,6 @@
)]
#![deny(unsafe_code)]
#![deny(clippy::all)]
*/
//! The core components of sauron
#[macro_use]
extern crate doc_comment;
Expand Down
2 changes: 1 addition & 1 deletion crates/sauron-core/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<MSG> Render for Element<MSG> {
}

let children = self.children();
let first_child = children.get(0);
let first_child = children.first();
let is_first_child_text_node = first_child.map(|node| node.is_text()).unwrap_or(false);

let is_lone_child_text_node = children.len() == 1 && is_first_child_text_node;
Expand Down
4 changes: 2 additions & 2 deletions crates/sauron-core/src/vdom/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use super::{
diff_lis,
};
use std::{cmp, mem};
use crate::vdom::attributes::Value;
use crate::vdom::AttributeValue;



/// Return the patches needed for `old_node` to have the same DOM as `new_node`
///
Expand Down
2 changes: 1 addition & 1 deletion crates/sauron-core/src/vdom/leaf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Leaf node for html dom tree
use std::fmt;
use std::borrow::Cow;

/// A leaf node value of html dom tree
Expand Down
3 changes: 3 additions & 0 deletions crates/sauron-core/src/vdom/map_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{

impl<MSG> Node<MSG>
{
/// map the msg of this node such that Node<MSG> becomes Node<MSG2>
pub fn map_msg<F, MSG2>(self, cb: F) -> Node<MSG2>
where
F: Fn(MSG) -> MSG2 + Clone + 'static,
Expand Down Expand Up @@ -46,6 +47,7 @@ impl<MSG> Node<MSG>

impl<MSG> Element<MSG>
{
/// map the msg of this element such that `Element<MSG>` becomes `Element<MSG2>`
pub fn map_msg<F, MSG2>(self, cb: F) -> Element<MSG2>
where
F: Fn(MSG) -> MSG2 + Clone + 'static,
Expand All @@ -72,6 +74,7 @@ impl<MSG> Element<MSG>

impl<MSG> Attribute<MSG>
{
/// map the msg of this attribute such that `Attribute<MSG>` becomes `Attribute<MSG2>`
pub fn map_msg<F, MSG2>(self, cb: F) -> Attribute<MSG2>
where
F: Fn(MSG) -> MSG2 + Clone + 'static,
Expand Down
4 changes: 2 additions & 2 deletions crates/sauron-core/src/vdom/node/attribute.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::type_complexity)]
use std::fmt::Debug;

use indexmap::IndexMap;
use std::fmt;

use crate::vdom::AttributeValue;
use derive_where::derive_where;

Expand Down
6 changes: 3 additions & 3 deletions crates/sauron-core/src/vdom/node/element.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::attribute::{AttributeName, Namespace, Tag};
use super::{Attribute, Node};
use std::fmt::Debug;
use std::fmt;


use crate::vdom::AttributeValue;
use derive_where::derive_where;

Expand Down Expand Up @@ -70,7 +70,7 @@ impl<MSG> Element<MSG> {

/// add children virtual node to this element
pub fn add_children(&mut self, children: impl IntoIterator<Item = Node<MSG>>) {
self.children.extend(children.into_iter());
self.children.extend(children);
}

/// returns a refernce to the children of this node
Expand Down
4 changes: 2 additions & 2 deletions crates/sauron-core/src/vdom/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use super::Tag;
use super::{Attribute, Node};
use std::fmt::Debug;
use std::fmt;


use derive_where::derive_where;

pub use tree_path::TreePath;
Expand Down
4 changes: 2 additions & 2 deletions crates/sauron-core/src/vdom/patch/tree_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ fn traverse_node_by_path<'a, MSG>(
#[cfg(test)]
mod tests {
use super::*;
use crate::*;

use crate::vdom::*;
use crate::render::Render;


#[test]
fn test_traverse() {
Expand Down

0 comments on commit 4b1930d

Please sign in to comment.