Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extend method to Classes #626

Merged
merged 4 commits into from
Sep 5, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/virtual_dom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub use self::vnode::VNode;
pub use self::vtag::VTag;
pub use self::vtext::VText;
use crate::html::{Component, Scope};
use std::ops::RangeFull;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove


/// `Listener` trait is an universal implementation of an event listener
/// which helps to bind Rust-listener to JS-listener (DOM).
Expand All @@ -41,7 +42,7 @@ type Listeners<COMP> = Vec<Box<dyn Listener<COMP>>>;
type Attributes = HashMap<String, String>;

/// A set of classes.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Classes {
set: IndexSet<String>,
}
Expand All @@ -55,6 +56,8 @@ impl Classes {
}

/// Adds a class to a set.
///
/// Prevents duplication of class names.
pub fn push(&mut self, class: &str) {
self.set.insert(class.into());
}
Expand All @@ -63,6 +66,14 @@ impl Classes {
pub fn contains(&self, class: &str) -> bool {
self.set.contains(class)
}

/// Adds other classes to this set of classes; returning itself.
///
/// 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
}
}

impl ToString for Classes {
Expand Down