fix: advance dynamic root
This commit is contained in:
1 parent
81dc134323
commit
e0390ff608
3 files changed
+27
-22
No files matched your search
+14
-15
@@ -7,7 +7,6 @@ fn main() {
|
|||||||
|
|
||||||
let cfg = Config::new().with_window(
|
let cfg = Config::new().with_window(
|
||||||
WindowBuilder::new()
|
WindowBuilder::new()
|
||||||
.with_title("Spinsense Client")
|
|
||||||
.with_inner_size(LogicalSize::new(600, 1000))
|
.with_inner_size(LogicalSize::new(600, 1000))
|
||||||
.with_resizable(false),
|
.with_resizable(false),
|
||||||
);
|
);
|
||||||
@@ -17,21 +16,21 @@ fn main() {
|
|||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
Router {
|
div {
|
||||||
Route { to: "/", "Home" }
|
Router {
|
||||||
Route { to: "/games", "Games" }
|
Route { to: "/", "Home" }
|
||||||
Route { to: "/play", "Play" }
|
Route { to: "/games", "Games" }
|
||||||
Route { to: "/settings", "Settings" }
|
Route { to: "/play", "Play" }
|
||||||
|
Route { to: "/settings", "Settings" }
|
||||||
|
|
||||||
p {
|
p { "----" }
|
||||||
"----"
|
nav {
|
||||||
}
|
ul {
|
||||||
nav {
|
Link { to: "/", li { "Home" } }
|
||||||
ul {
|
Link { to: "/games", li { "Games" } }
|
||||||
Link { to: "/", li { "Home" } }
|
Link { to: "/play", li { "Play" } }
|
||||||
Link { to: "/games", li { "Games" } }
|
Link { to: "/settings", li { "Settings" } }
|
||||||
Link { to: "/play", li { "Play" } }
|
}
|
||||||
Link { to: "/settings", li { "Settings" } }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ impl<'b> VirtualDom {
|
|||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, root)| match root {
|
.map(|(idx, root)| match root {
|
||||||
DynamicText { id } | Dynamic { id } => self.write_dynamic_root(node, *id),
|
DynamicText { id } | Dynamic { id } => {
|
||||||
|
nodes.next().unwrap();
|
||||||
|
self.write_dynamic_root(node, *id)
|
||||||
|
}
|
||||||
Element { .. } => self.write_element_root(node, idx, &mut attrs, &mut nodes),
|
Element { .. } => self.write_element_root(node, idx, &mut attrs, &mut nodes),
|
||||||
Text { .. } => self.write_static_text_root(node, idx),
|
Text { .. } => self.write_static_text_root(node, idx),
|
||||||
})
|
})
|
||||||
@@ -63,7 +66,7 @@ impl<'b> VirtualDom {
|
|||||||
use DynamicNode::*;
|
use DynamicNode::*;
|
||||||
match &template.dynamic_nodes[idx] {
|
match &template.dynamic_nodes[idx] {
|
||||||
node @ Fragment(_) => self.create_dynamic_node(template, node, idx),
|
node @ Fragment(_) => self.create_dynamic_node(template, node, idx),
|
||||||
node @ Component { .. } => self.create_dynamic_node(template, node, idx),
|
node @ Component { .. } => dbg!(self.create_dynamic_node(template, node, idx)),
|
||||||
Placeholder(VPlaceholder { id }) => {
|
Placeholder(VPlaceholder { id }) => {
|
||||||
let id = self.set_slot(template, id, idx);
|
let id = self.set_slot(template, id, idx);
|
||||||
self.mutations.push(CreatePlaceholder { id });
|
self.mutations.push(CreatePlaceholder { id });
|
||||||
@@ -131,7 +134,10 @@ impl<'b> VirtualDom {
|
|||||||
) {
|
) {
|
||||||
let (start, end) = match collect_dyn_node_range(dynamic_nodes, root_idx) {
|
let (start, end) = match collect_dyn_node_range(dynamic_nodes, root_idx) {
|
||||||
Some((a, b)) => (a, b),
|
Some((a, b)) => (a, b),
|
||||||
None => return,
|
None => {
|
||||||
|
println!("No dynamic nodes found for root {}", root_idx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for idx in (start..=end).rev() {
|
for idx in (start..=end).rev() {
|
||||||
|
|||||||
@@ -711,8 +711,11 @@ impl<'b> VirtualDom {
|
|||||||
|
|
||||||
fn replace(&mut self, left: &'b VNode<'b>, right: impl IntoIterator<Item = &'b VNode<'b>>) {
|
fn replace(&mut self, left: &'b VNode<'b>, right: impl IntoIterator<Item = &'b VNode<'b>>) {
|
||||||
let m = self.create_children(right);
|
let m = self.create_children(right);
|
||||||
|
|
||||||
let id = self.find_last_element(left);
|
let id = self.find_last_element(left);
|
||||||
|
|
||||||
self.mutations.push(Mutation::InsertAfter { id, m });
|
self.mutations.push(Mutation::InsertAfter { id, m });
|
||||||
|
|
||||||
self.remove_node(left, true);
|
self.remove_node(left, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -735,10 +738,7 @@ impl<'b> VirtualDom {
|
|||||||
/// Remove these nodes from the dom
|
/// Remove these nodes from the dom
|
||||||
/// Wont generate mutations for the inner nodes
|
/// Wont generate mutations for the inner nodes
|
||||||
fn remove_nodes(&mut self, nodes: &'b [VNode<'b>]) {
|
fn remove_nodes(&mut self, nodes: &'b [VNode<'b>]) {
|
||||||
nodes
|
nodes.iter().for_each(|node| self.remove_node(node, true));
|
||||||
.iter()
|
|
||||||
.rev()
|
|
||||||
.for_each(|node| self.remove_node(node, true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_node(&mut self, node: &'b VNode<'b>, gen_muts: bool) {
|
fn remove_node(&mut self, node: &'b VNode<'b>, gen_muts: bool) {
|
||||||
|
|||||||
Reference in new issue
Block a user