diff --git a/crates/core/src/dom/component/stateful_component.rs b/crates/core/src/dom/component/stateful_component.rs index 9722e2c6..59ed2ead 100644 --- a/crates/core/src/dom/component/stateful_component.rs +++ b/crates/core/src/dom/component/stateful_component.rs @@ -147,7 +147,8 @@ where let mount_event = on_component_mount(move |me| { program.mount( &me.target_node.as_node(), - MountProcedure::append_to_shadow(), + //MountProcedure::append_to_shadow(), + MountProcedure::append(), ); let stylesheet = ::stylesheet().join("\n"); log::info!("stylesheet: {}", stylesheet); diff --git a/crates/core/src/dom/dom_attr.rs b/crates/core/src/dom/dom_attr.rs index df93918a..95edb2f2 100644 --- a/crates/core/src/dom/dom_attr.rs +++ b/crates/core/src/dom/dom_attr.rs @@ -329,4 +329,28 @@ impl DomAttrValue { let simple = self.as_simple()?; Some(simple.to_string()) } + + /// return i32 if it can be converted as such + pub fn as_i32(&self) -> Option { + let simple = self.as_simple()?; + simple.as_i32() + } + + /// return i64 if it can be converted as such + pub fn as_i64(&self) -> Option { + let simple = self.as_simple()?; + simple.as_i64() + } + + /// return i32 if it can be converted as such + pub fn as_f32(&self) -> Option { + let simple = self.as_simple()?; + simple.as_f32() + } + + /// return i64 if it can be converted as such + pub fn as_f64(&self) -> Option { + let simple = self.as_simple()?; + simple.as_f64() + } } diff --git a/crates/core/src/vdom/attribute/value.rs b/crates/core/src/vdom/attribute/value.rs index 38d4a782..b87c07fa 100644 --- a/crates/core/src/vdom/attribute/value.rs +++ b/crates/core/src/vdom/attribute/value.rs @@ -62,6 +62,29 @@ impl Value { } } + /// converts to f32 if the variants are numerical representation + pub fn as_f32(&self) -> Option { + match self { + Self::Bool(_) => None, + Self::Cow(_v) => None, + Self::Vec(_v) => None, + Self::U8(v) => Some(f32::from(*v)), + Self::U16(v) => Some(f32::from(*v)), + Self::U32(v) => Some(*v as f32), + Self::U64(v) => Some(*v as f32), + Self::U128(v) => Some(*v as f32), + Self::Usize(v) => Some(*v as f32), + Self::I8(v) => Some(f32::from(*v)), + Self::I16(v) => Some(f32::from(*v)), + Self::I32(v) => Some(*v as f32), + Self::I64(v) => Some(*v as f32), + Self::I128(v) => Some(*v as f32), + Self::Isize(v) => Some(*v as f32), + Self::F32(v) => Some(*v), + Self::F64(v) => Some(*v as f32), + } + } + /// converts to f64 if the variants are numerical representation pub fn as_f64(&self) -> Option { match self { @@ -108,6 +131,29 @@ impl Value { } } + /// converts to i64 if the variants are numerical representation + pub fn as_i64(&self) -> Option { + match self { + Self::Bool(_) => None, + Self::Cow(_v) => None, + Self::Vec(_v) => None, + Self::U8(v) => Some(i64::from(*v)), + Self::U16(v) => Some(i64::from(*v)), + Self::U32(v) => Some(*v as i64), + Self::U64(v) => Some(*v as i64), + Self::U128(v) => Some(*v as i64), + Self::Usize(v) => Some(*v as i64), + Self::I8(v) => Some(i64::from(*v)), + Self::I16(v) => Some(i64::from(*v)), + Self::I32(v) => Some(*v as i64), + Self::I64(v) => Some(*v), + Self::I128(v) => Some(*v as i64), + Self::Isize(v) => Some(*v as i64), + Self::F32(v) => Some(*v as i64), + Self::F64(v) => Some(*v as i64), + } + } + /// If this is Value::Vec variant, append the new value /// otherwise, turn this value into Value::Vec(Vec) variant /// and append the new value.