Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jan 21, 2025
1 parent 489a6a8 commit f72802e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 92 deletions.
8 changes: 0 additions & 8 deletions crates/core/src/dom/mutations_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
17 changes: 0 additions & 17 deletions crates/native-core/src/dioxus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,6 @@ impl<V: FromAnyValue + Send + Sync> 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<NodeId> = template
Expand Down Expand Up @@ -305,9 +291,6 @@ fn create_template_node<V: FromAnyValue + Send + Sync>(
}
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()
// }
}
}

Expand Down
5 changes: 0 additions & 5 deletions crates/renderer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions crates/renderer/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ impl<'a, State: Clone> ApplicationHandler<EventMessage> 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(_))
{
Expand Down
98 changes: 40 additions & 58 deletions examples/counter.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,47 @@
#![allow(non_snake_case)]
use dioxus::prelude::dioxus_core::NoOpMutations;
use freya::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
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" }
}
})
}
)
}

0 comments on commit f72802e

Please sign in to comment.