diff --git a/crates/core/src/dom/mutations_writer.rs b/crates/core/src/dom/mutations_writer.rs index 4d7a91e24..91c360fe0 100644 --- a/crates/core/src/dom/mutations_writer.rs +++ b/crates/core/src/dom/mutations_writer.rs @@ -121,10 +121,6 @@ impl<'a> MutationsWriter<'a> { } impl<'a> WriteMutations for MutationsWriter<'a> { - // fn register_template(&mut self, template: dioxus_core::prelude::Template) { - // self.native_writer.register_template(template); - // } - fn append_children(&mut self, id: dioxus_core::ElementId, m: usize) { self.native_writer.append_children(id, m); } @@ -141,10 +137,6 @@ impl<'a> WriteMutations for MutationsWriter<'a> { self.native_writer.create_text_node(value, id); } - // fn hydrate_text_node(&mut self, path: &'static [u8], value: &str, id: dioxus_core::ElementId) { - // self.native_writer.hydrate_text_node(path, value, id); - // } - fn load_template(&mut self, template: Template, index: usize, id: dioxus_core::ElementId) { self.native_writer.load_template(template, index, id); } diff --git a/crates/native-core/src/dioxus.rs b/crates/native-core/src/dioxus.rs index d1553b511..384410146 100644 --- a/crates/native-core/src/dioxus.rs +++ b/crates/native-core/src/dioxus.rs @@ -150,20 +150,6 @@ impl WriteMutations for DioxusNativeCoreMutationW self.state.stack.push(node_id); } - // fn hydrate_text_node(&mut self, path: &'static [u8], value: &str, id: ElementId) { - // let node_id = self.state.load_child(self.rdom, path); - // let node = self.rdom.get_mut(node_id).unwrap(); - // self.state.set_element_id(node, id); - // let mut node = self.rdom.get_mut(node_id).unwrap(); - // let node_type_mut = node.node_type_mut(); - // if let NodeTypeMut::Text(mut text) = node_type_mut { - // *text.text_mut() = value.to_string(); - // } else { - // drop(node_type_mut); - // node.set_type(NodeType::Text(value.to_string())); - // } - // } - fn load_template(&mut self, template: Template, index: usize, id: ElementId) { let template_entry = self.state.templates.entry(template).or_insert_with(|| { let template_root_ids: Vec = template @@ -305,9 +291,6 @@ fn create_template_node( } TemplateNode::Text { text } => rdom.create_node(NodeType::Text(text.to_string())).id(), TemplateNode::Dynamic { .. } => rdom.create_node(NodeType::Placeholder).id(), - // TemplateNode::DynamicText { .. } => { - // rdom.create_node(NodeType::Text(String::default())).id() - // } } } diff --git a/crates/renderer/src/app.rs b/crates/renderer/src/app.rs index 89c7e0bb5..daf12646e 100644 --- a/crates/renderer/src/app.rs +++ b/crates/renderer/src/app.rs @@ -275,11 +275,6 @@ impl Application { self.process_events(scale_factor); } - /// Replace a VirtualDOM Template - // pub fn vdom_replace_template(&mut self, template: Template) { - // self.vdom.replace_template(template); - // } - /// Render the App into the Window Canvas pub fn render( &mut self, diff --git a/crates/renderer/src/renderer.rs b/crates/renderer/src/renderer.rs index e87a01132..0cf01a283 100644 --- a/crates/renderer/src/renderer.rs +++ b/crates/renderer/src/renderer.rs @@ -217,10 +217,6 @@ impl<'a, State: Clone> ApplicationHandler for DesktopRenderer<'a, EventMessage::ExitApp => event_loop.exit(), EventMessage::PlatformEvent(platform_event) => self.send_event(platform_event), ev => { - // if let EventMessage::UpdateTemplate(template) = ev { - // app.vdom_replace_template(template); - // } - if matches!(ev, EventMessage::PollVDOM) || matches!(ev, EventMessage::UpdateTemplate(_)) { diff --git a/examples/counter.rs b/examples/counter.rs index 4c18eb79b..6571d5de3 100644 --- a/examples/counter.rs +++ b/examples/counter.rs @@ -1,65 +1,47 @@ -#![allow(non_snake_case)] -use dioxus::prelude::dioxus_core::NoOpMutations; -use freya::prelude::*; - -fn main() -> Result<(), Box> { - fn app() -> Element { - rsx! { - Spammer {} - Spammer {} - Spammer {} - Spammer {} - } - } +#![cfg_attr( + all(not(debug_assertions), target_os = "windows"), + windows_subsystem = "windows" +)] - fn Spammer() -> Element { - let mut count = use_signal(|| 0); +use freya::prelude::*; - use_hook(|| { - spawn(async move { - loop { - tokio::time::sleep(std::time::Duration::from_nanos(1)).await; - let val = *count.peek_unchecked(); - if val == 70 { - count.set(0); - } else { - count.set(val + 1); - } - } - }) - }); +fn main() { + launch_with_props(app, "Counter", (400.0, 350.0)); +} - rsx! { - for el in 0..*count.read() { - // To avoid the leak simply replace this by `div {` - Comp { - key: "{el}", - } +fn app() -> Element { + let mut count = use_signal(|| 0); + + rsx!( + rect { + height: "50%", + width: "100%", + main_align: "center", + cross_align: "center", + background: "rgb(0, 119, 182)", + color: "white", + shadow: "0 4 20 5 rgb(0, 0, 0, 80)", + label { + font_size: "75", + font_weight: "bold", + "{count}" } } - } - - #[component] - fn Comp() -> Element { - rsx!(rect {}) - } - - // create the vdom, the real_dom, and the binding layer between them - let mut vdom = VirtualDom::new(app); - - vdom.rebuild(&mut NoOpMutations); - - // we need to run the vdom in a async runtime - tokio::runtime::Builder::new_current_thread() - .enable_all() - .build()? - .block_on(async { - loop { - // wait for the vdom to update - vdom.wait_for_work().await; - - // get the mutations from the vdom - vdom.render_immediate(&mut NoOpMutations); + rect { + height: "50%", + width: "100%", + main_align: "center", + cross_align: "center", + direction: "horizontal", + spacing: "8", + Button { + onpress: move |_| count += 1, + label { "Increase" } + } + Button { + onpress: move |_| count -= 1, + label { "Decrease" } } - }) + } + ) }