diff --git a/Cargo.toml b/Cargo.toml index 9d6e286..5b81b5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,3 +23,9 @@ version = "0.4.6" #git = "https://github.com/koute/stdweb" #path = "../stdweb" features = ["experimental_features_which_may_break_on_minor_version_bumps"] + +[profile.release] +debug-assertions = true + +[profile.bench] +debug-assertions = true diff --git a/src/dom_operations.rs b/src/dom_operations.rs index 05b16c8..71c6377 100644 --- a/src/dom_operations.rs +++ b/src/dom_operations.rs @@ -58,34 +58,38 @@ pub fn set_text(element: &TextNode, value: &str) { } } + +#[inline] +fn set_style_raw>(element: &A, name: &str, value: &str, important: bool) { + js! { @(no_return) + @{element.as_ref()}.style.setProperty(@{name}, @{value}, (@{important} ? "important" : "")); + } +} + // TODO this should be in stdweb // TODO handle browser prefixes #[cfg(debug_assertions)] pub fn set_style>(element: &A, name: &str, value: &str, important: bool) { - let is_correct: bool = js!( - var element = @{element.as_ref()}; - var name = @{name}; - var value = @{value}; - var old_value = element.style.getPropertyValue(name); + #[inline] + fn get_style>(element: &A, name: &str) -> String { + js!( return @{element.as_ref()}.style.getPropertyValue(@{name}); ).try_into().unwrap() + } - if (old_value !== value) { - element.style.setProperty(name, value, (@{important} ? "important" : "")); - return element.style.getPropertyValue(name) !== old_value; + let old_value = get_style(element, name); - } else { - return true; + if old_value != value { + set_style_raw(element, name, value, important); + + if get_style(element, name) == old_value { + panic!("style is incorrect:\n name: {}\n old value: {}\n new value: {}", name, old_value, value); } - ).try_into().unwrap(); - - assert!(is_correct, "style is incorrect: {} = {}", name, value); + } } #[cfg(not(debug_assertions))] #[inline] pub fn set_style>(element: &A, name: &str, value: &str, important: bool) { - js! { @(no_return) - @{element.as_ref()}.style.setProperty(@{name}, @{value}, (@{important} ? "important" : "")); - } + set_style_raw(element, name, value, important); } // TODO this should be in stdweb diff --git a/src/traits.rs b/src/traits.rs index 27cac99..e79bcbf 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -17,6 +17,7 @@ impl Mixin for F where F: Fn(A) -> A { // TODO figure out a way to implement this for all of AsRef / Borrow / etc. +// TODO implementations for &String and &mut String pub trait IntoStr { type Output: Deref;