Skip to content

Commit

Permalink
Filter empty string classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Dec 3, 2019
1 parent f1459a8 commit 141828c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/virtual_dom/mod.rs
Expand Up @@ -57,7 +57,9 @@ impl Classes {
///
/// Prevents duplication of class names.
pub fn push(&mut self, class: &str) {
self.set.insert(class.into());
if !class.is_empty() {
self.set.insert(class.into());
}
}

/// Check the set contains a class.
Expand All @@ -69,7 +71,7 @@ impl Classes {
///
/// Takes the logical union of both `Classes`.
pub fn extend<T: Into<Classes>>(mut self, other: T) -> Self {
self.set.extend(other.into().set.into_iter());
self.set.extend(other.into().set.into_iter().filter(|c| !c.is_empty()));
self
}
}
Expand All @@ -88,28 +90,28 @@ impl ToString for Classes {

impl From<&str> for Classes {
fn from(t: &str) -> Self {
let set = t.split_whitespace().map(String::from).collect();
let set = t.split_whitespace().map(String::from).filter(|c| !c.is_empty()).collect();
Self { set }
}
}

impl From<String> for Classes {
fn from(t: String) -> Self {
let set = t.split_whitespace().map(String::from).collect();
let set = t.split_whitespace().map(String::from).filter(|c| !c.is_empty()).collect();
Self { set }
}
}

impl From<&String> for Classes {
fn from(t: &String) -> Self {
let set = t.split_whitespace().map(String::from).collect();
let set = t.split_whitespace().map(String::from).filter(|c| !c.is_empty()).collect();
Self { set }
}
}

impl<T: AsRef<str>> From<Vec<T>> for Classes {
fn from(t: Vec<T>) -> Self {
let set = t.iter().map(|x| x.as_ref().to_string()).collect();
let set = t.iter().map(|x| x.as_ref().to_string()).filter(|c| !c.is_empty()).collect();
Self { set }
}
}
Expand Down

0 comments on commit 141828c

Please sign in to comment.