use crate::*;
pub trait IntoView {
fn into_view(self) -> View;
}
pub trait ApplyToElement {
fn apply_to_element(self, element: &Element, attr_name: &str);
}
impl ApplyToElement for String {
fn apply_to_element(self, element: &Element, attr_name: &str) {
if !self.is_empty() || is_boolean_property(attr_name) {
set_dom_attribute_or_property(element, attr_name, &self);
}
}
}
impl ApplyToElement for &str {
fn apply_to_element(self, element: &Element, attr_name: &str) {
self.to_string().apply_to_element(element, attr_name);
}
}
impl ApplyToElement for Signal<String> {
fn apply_to_element(self, element: &Element, attr_name: &str) {
bind_attr_signal(element, attr_name, self);
}
}
impl ApplyToElement for CssClass {
fn apply_to_element(self, element: &Element, attr_name: &str) {
apply_css_class(element, attr_name, &self);
}
}
impl ApplyToElement for &CssClass {
fn apply_to_element(self, element: &Element, attr_name: &str) {
apply_css_class(element, attr_name, self);
}
}
impl ApplyToElement for bool {
fn apply_to_element(self, element: &Element, attr_name: &str) {
let value: String = self.to_string();
value.apply_to_element(element, attr_name);
}
}
impl ApplyToElement for Signal<bool> {
fn apply_to_element(self, element: &Element, attr_name: &str) {
let string_signal: Signal<String> = Signal::new(self.get_untracked().to_string());
let string_signal_clone: Signal<String> = string_signal;
self.replace_subscribe(move || {
string_signal_clone.set(self.get_untracked().to_string());
});
bind_attr_signal(element, attr_name, string_signal);
}
}
impl ApplyToElement for i32 {
fn apply_to_element(self, element: &Element, attr_name: &str) {
self.to_string().apply_to_element(element, attr_name);
}
}
impl ApplyToElement for usize {
fn apply_to_element(self, element: &Element, attr_name: &str) {
self.to_string().apply_to_element(element, attr_name);
}
}
impl ApplyToElement for f64 {
fn apply_to_element(self, element: &Element, attr_name: &str) {
self.to_string().apply_to_element(element, attr_name);
}
}
impl<T> AttrValueAdapter<T>
where
T: ApplyToElement,
{
pub fn apply_to_element(self, element: &Element, attr_name: &str) {
self.inner.apply_to_element(element, attr_name);
}
}