Commit 3188c97
Ideas
Changed files (1)
Diff
@@ -48,15 +48,90 @@ fn test_getter_and_setter() { assert_eq!(test_attribute_from_getter, "updated-value-in-component"); } +//#[all_html_attributes] #[component("test-component2")] struct TestComponent2 {- attribute_updated: bool,- //#[html_attribute] test_attribute: String,+ //#[html_attribute]+ the_number: i32,+ not_an_attribure: String,+}++struct TestComponent2Componet {+ id: String,+ attribute_values: Rc<RefCell<TestComponent2>>,+}++impl TestComponent2Componet {+ fn set_test_attribute(&mut self, value: String) -> Option<()> {+ let el = get_element_by_id(self.id.as_str())?;++ el.set_attribute("test_attribute", &value.to_string())+ .ok()?;++ Some(())+ }++ fn get_test_attribute(&self) -> Option<String> {+ let el = get_element_by_id(self.id.as_str())?;+ let attr = el.get_attribute("test_attribute")?;+ let n: String = parse_value(&attr)?;+ Some(n)+ }++ fn set_the_number(&mut self, value: i32) -> Option<()> {+ let el = get_element_by_id(self.id.as_str())?;++ el.set_attribute("the_number", &value.to_string()).ok()?;++ Some(())+ }++ fn get_the_number(&self) -> Option<i32> {+ let el = get_element_by_id(self.id.as_str())?;+ let attr = el.get_attribute("the_number")?;+ let n: i32 = parse_value(&attr)?;+ Some(n)+ }++ fn attribute_changed_update_struct(&self, name: &str, _old_value: &str, new_value: &str) {+ log!("Attribute changed internally", name, "to", new_value);+ let component = self.attribute_values.try_borrow_mut();++ if component.is_err() {+ error!(+ "Failed to borrow component for",+ self.id, "in attribute_changed of ", name+ );+ return;+ }++ if name == "test_attribute" {+ component.unwrap().test_attribute = new_value.to_string();+ } else if name == "the_number" {+ component.unwrap().the_number = new_value.parse().unwrap();+ }+ }+}++impl Component for TestComponent2 {+ fn connected(attrib: &mut TestComponent2Componet) {+ attrib.set_test_attribute("SOME TEST".to_string());+ attrib.set_the_number(42);+ }++ fn attribute_changed(id: &str, name: &str, old_value: &str, new_value: &str) {+ Self::attribute_changed_update_struct(id, name, old_value, new_value);+ log!("Attribute changed", name, "to", new_value);+ } } impl TestComponent2 {+ fn connected(id: &str) {+ // might this call set_test_attribute internally because of default attributes?+ }+ fn set_test_attribute(id: &str, value: String) -> Result<()> { let attribute_name = "test_attribute"; let attribute_string = value.clone();@@ -103,10 +178,3 @@ impl TestComponent2 { } } }--impl Component for TestComponent2 {- fn attribute_changed(id: &str, name: &str, old_value: &str, new_value: &str) {- Self::attribute_changed_update_struct(id, name, old_value, new_value);- log!("Attribute changed", name, "to", new_value);- }-}