clippy fix

This commit is contained in:
Evan Almloff committed 2024-01-09 10:09:58 -06:00
1 parent aed29b1dec
commit eb602fc29f
5 files changed
+32 -59

No files matched your search

+6 -15
View File
@@ -1,23 +1,14 @@
use std::{ use std::ops::Deref;
cell::RefMut,
ops::{Deref, DerefMut},
};
use crate::{ use crate::{
any_props::AnyProps, any_props::AnyProps,
arena::ElementId, innerlude::{DirtyScope, ElementRef, VComponent, VNodeMount, WriteMutations},
innerlude::{
DirtyScope, ElementPath, ElementRef, VComponent, VNodeMount, VText, WriteMutations,
},
nodes::RenderReturn, nodes::RenderReturn,
nodes::{DynamicNode, VNode}, nodes::VNode,
scopes::ScopeId, scopes::ScopeId,
virtual_dom::VirtualDom, virtual_dom::VirtualDom,
TemplateNode,
}; };
use DynamicNode::*;
impl VirtualDom { impl VirtualDom {
pub(crate) fn diff_scope( pub(crate) fn diff_scope(
&mut self, &mut self,
@@ -127,8 +118,8 @@ impl VNode {
pub(super) fn create_component_node( pub(super) fn create_component_node(
&self, &self,
mount: &mut VNodeMount, _mount: &mut VNodeMount,
idx: usize, _idx: usize,
component: &VComponent, component: &VComponent,
parent: Option<ElementRef>, parent: Option<ElementRef>,
dom: &mut VirtualDom, dom: &mut VirtualDom,
@@ -140,7 +131,7 @@ impl VNode {
.context() .context()
.id; .id;
let mut new = dom.run_scope(scope); let new = dom.run_scope(scope);
dom.scopes[scope.0].last_rendered_node = Some(new.clone()); dom.scopes[scope.0].last_rendered_node = Some(new.clone());
+10 -13
View File
@@ -55,12 +55,9 @@ impl VirtualDom {
match old.len().cmp(&new.len()) { match old.len().cmp(&new.len()) {
Ordering::Greater => self.remove_nodes(to, &old[new.len()..]), Ordering::Greater => self.remove_nodes(to, &old[new.len()..]),
Ordering::Less => self.create_and_insert_after( Ordering::Less => {
to, self.create_and_insert_after(to, &new[old.len()..], old.last().unwrap(), parent)
&new[old.len()..], }
&mut old.last().unwrap(),
parent,
),
Ordering::Equal => {} Ordering::Equal => {}
} }
@@ -144,16 +141,16 @@ impl VirtualDom {
// we need to find the right "foothold" though - we shouldn't use the "append" at all // we need to find the right "foothold" though - we shouldn't use the "append" at all
if left_offset == 0 { if left_offset == 0 {
// insert at the beginning of the old list // insert at the beginning of the old list
let mut foothold = &old[old.len() - right_offset]; let foothold = &old[old.len() - right_offset];
self.create_and_insert_before(to, new_middle, &mut foothold, parent); self.create_and_insert_before(to, new_middle, foothold, parent);
} else if right_offset == 0 { } else if right_offset == 0 {
// insert at the end the old list // insert at the end the old list
let mut foothold = old.last().unwrap(); let foothold = old.last().unwrap();
self.create_and_insert_after(to, new_middle, &mut foothold, parent); self.create_and_insert_after(to, new_middle, foothold, parent);
} else { } else {
// inserting in the middle // inserting in the middle
let mut foothold = &old[left_offset - 1]; let foothold = &old[left_offset - 1];
self.create_and_insert_after(to, new_middle, &mut foothold, parent); self.create_and_insert_after(to, new_middle, foothold, parent);
} }
} else { } else {
self.diff_keyed_middle(to, old_middle, new_middle, parent); self.diff_keyed_middle(to, old_middle, new_middle, parent);
@@ -186,7 +183,7 @@ impl VirtualDom {
// If that was all of the old children, then create and append the remaining // If that was all of the old children, then create and append the remaining
// new children and we're finished. // new children and we're finished.
if left_offset == old.len() { if left_offset == old.len() {
self.create_and_insert_after(to, &new[left_offset..], &mut old.last().unwrap(), parent); self.create_and_insert_after(to, &new[left_offset..], old.last().unwrap(), parent);
return None; return None;
} }
+3 -14
View File
@@ -1,23 +1,12 @@
use std::{
cell::RefMut,
ops::{Deref, DerefMut},
};
use crate::{ use crate::{
any_props::AnyProps,
arena::ElementId, arena::ElementId,
innerlude::{ innerlude::{ElementRef, VNodeMount, WriteMutations},
DirtyScope, ElementPath, ElementRef, VComponent, VNodeMount, VText, WriteMutations, nodes::VNode,
},
nodes::RenderReturn,
nodes::{DynamicNode, VNode},
scopes::ScopeId, scopes::ScopeId,
virtual_dom::VirtualDom, virtual_dom::VirtualDom,
Template, TemplateNode, Template, TemplateNode,
}; };
use DynamicNode::*;
mod component; mod component;
mod iterator; mod iterator;
mod node; mod node;
@@ -105,7 +94,7 @@ impl VirtualDom {
gen_muts: bool, gen_muts: bool,
) { ) {
// Remove the component from the dom // Remove the component from the dom
if let Some(mut node) = self.scopes[scope.0].last_rendered_node.take() { if let Some(node) = self.scopes[scope.0].last_rendered_node.take() {
node.remove_node(self, to, gen_muts) node.remove_node(self, to, gen_muts)
}; };
+12 -16
View File
@@ -1,16 +1,12 @@
use crate::{Attribute, AttributeValue, DynamicNode::*, VPlaceholder}; use crate::{Attribute, AttributeValue, DynamicNode::*};
use crate::{VNode, VirtualDom, WriteMutations}; use crate::{VNode, VirtualDom, WriteMutations};
use core::iter::Peekable; use core::iter::Peekable;
use std::cell::Ref; use std::cell::Ref;
use std::{ use std::cell::RefMut;
cell::RefMut,
ops::{Deref, DerefMut},
};
use crate::{ use crate::{
any_props::AnyProps,
arena::ElementId, arena::ElementId,
innerlude::{DirtyScope, ElementPath, ElementRef, VComponent, VNodeMount, VText}, innerlude::{ElementPath, ElementRef, VComponent, VNodeMount, VText},
nodes::DynamicNode, nodes::DynamicNode,
nodes::RenderReturn, nodes::RenderReturn,
scopes::ScopeId, scopes::ScopeId,
@@ -168,7 +164,7 @@ impl VNode {
let child = children.first().unwrap(); let child = children.first().unwrap();
child.find_first_element(dom) child.find_first_element(dom)
} }
Component(comp) => { Component(_comp) => {
let scope = ScopeId(mount.mounted_dynamic_nodes[*id]); let scope = ScopeId(mount.mounted_dynamic_nodes[*id]);
match dom.get_scope(scope).unwrap().root_node() { match dom.get_scope(scope).unwrap().root_node() {
RenderReturn::Ready(child) => child.find_first_element(dom), RenderReturn::Ready(child) => child.find_first_element(dom),
@@ -190,7 +186,7 @@ impl VNode {
match &self.dynamic_nodes[*id] { match &self.dynamic_nodes[*id] {
Placeholder(_) | Text(_) => ElementId(mount.mounted_dynamic_nodes[*id]), Placeholder(_) | Text(_) => ElementId(mount.mounted_dynamic_nodes[*id]),
Fragment(t) => t.last().unwrap().find_last_element(dom), Fragment(t) => t.last().unwrap().find_last_element(dom),
Component(comp) => { Component(_comp) => {
let scope = ScopeId(mount.mounted_dynamic_nodes[*id]); let scope = ScopeId(mount.mounted_dynamic_nodes[*id]);
match dom.get_scope(scope).unwrap().root_node() { match dom.get_scope(scope).unwrap().root_node() {
RenderReturn::Ready(node) => node.find_last_element(dom), RenderReturn::Ready(node) => node.find_last_element(dom),
@@ -304,7 +300,7 @@ impl VNode {
gen_muts: bool, gen_muts: bool,
) { ) {
match node { match node {
Component(comp) => { Component(_comp) => {
let scope_id = ScopeId(mount.mounted_dynamic_nodes[idx]); let scope_id = ScopeId(mount.mounted_dynamic_nodes[idx]);
dom.remove_component_node(to, scope_id, gen_muts); dom.remove_component_node(to, scope_id, gen_muts);
} }
@@ -314,7 +310,7 @@ impl VNode {
} }
Fragment(nodes) => nodes Fragment(nodes) => nodes
.iter() .iter()
.for_each(|node| self.remove_node(dom, to, gen_muts)), .for_each(|_node| self.remove_node(dom, to, gen_muts)),
}; };
} }
@@ -341,12 +337,12 @@ impl VNode {
&self, &self,
mount: &VNodeMount, mount: &VNodeMount,
dom: &mut VirtualDom, dom: &mut VirtualDom,
to: &mut impl WriteMutations, _to: &mut impl WriteMutations,
) { ) {
let mut id = None; let id = None;
for (idx, path) in self.template.get().attr_paths.iter().enumerate() { for (idx, path) in self.template.get().attr_paths.iter().enumerate() {
let attr = &self.dynamic_attrs[idx]; let _attr = &self.dynamic_attrs[idx];
// We clean up the roots in the next step, so don't worry about them here // We clean up the roots in the next step, so don't worry about them here
if path.len() <= 1 { if path.len() <= 1 {
@@ -426,7 +422,7 @@ impl VNode {
for (idx, (old_component, new_component)) in components.into_iter().enumerate() { for (idx, (old_component, new_component)) in components.into_iter().enumerate() {
let scope_id = ScopeId(self.assert_mounted().mounted_dynamic_nodes[idx]); let scope_id = ScopeId(self.assert_mounted().mounted_dynamic_nodes[idx]);
self.diff_vcomponent( self.diff_vcomponent(
&mut *mount, &mut mount,
idx, idx,
old_component, old_component,
new_component, new_component,
@@ -736,7 +732,7 @@ impl VNode {
to.create_event_listener(&attribute.name[2..], id); to.create_event_listener(&attribute.name[2..], id);
} }
_ => { _ => {
to.set_attribute(&attribute.name, attribute.namespace, &attribute.value, id); to.set_attribute(attribute.name, attribute.namespace, &attribute.value, id);
} }
} }
} }
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::any_props::{BoxedAnyProps, VProps}; use crate::any_props::{BoxedAnyProps, VProps};
use crate::innerlude::{ElementRef, EventHandler}; use crate::innerlude::{ElementRef, EventHandler};
use crate::Properties; use crate::Properties;
use crate::{arena::ElementId, Element, Event, ScopeId}; use crate::{arena::ElementId, Element, Event};
use std::cell::RefCell; use std::cell::RefCell;
use std::ops::Deref; use std::ops::Deref;
use std::rc::Rc; use std::rc::Rc;