mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-02 23:13:25 +00:00
polish: listen to clippy
This commit is contained in:
parent
a1afb9809a
commit
f49244344c
9 changed files with 23 additions and 137 deletions
|
@ -46,9 +46,9 @@ impl<'a> Iterator for RealChildIterator<'a> {
|
|||
VNode::Fragment(frag) => {
|
||||
let subcount = *count as usize;
|
||||
|
||||
if frag.children.len() == 0 {
|
||||
if frag.children.is_empty() {
|
||||
should_pop = true;
|
||||
returned_node = Some(&*node);
|
||||
returned_node = Some(node);
|
||||
}
|
||||
|
||||
if subcount >= frag.children.len() {
|
||||
|
|
|
@ -105,6 +105,8 @@ pub trait Properties: Sized {
|
|||
fn builder() -> Self::Builder;
|
||||
|
||||
/// Memoization can only happen if the props are valid for the 'static lifetime
|
||||
///
|
||||
/// # Safety
|
||||
/// The user must know if their props are static, but if they make a mistake, UB happens
|
||||
/// Therefore it's unsafe to memeoize.
|
||||
unsafe fn memoize(&self, other: &Self) -> bool;
|
||||
|
|
|
@ -312,8 +312,7 @@ impl<'bump> DiffMachine<'bump> {
|
|||
listeners.iter().for_each(|listener| {
|
||||
self.attach_listener_to_scope(listener, scope);
|
||||
listener.mounted_node.set(Some(real_id));
|
||||
self.mutations
|
||||
.new_event_listener(listener, cur_scope_id.clone());
|
||||
self.mutations.new_event_listener(listener, cur_scope_id);
|
||||
});
|
||||
} else {
|
||||
log::warn!("create element called with no scope on the stack - this is an error for a live dom");
|
||||
|
@ -470,9 +469,7 @@ impl<'bump> DiffMachine<'bump> {
|
|||
// TODO: take a more efficient path than this
|
||||
if old.attributes.len() == new.attributes.len() {
|
||||
for (old_attr, new_attr) in old.attributes.iter().zip(new.attributes.iter()) {
|
||||
if old_attr.value != new_attr.value {
|
||||
self.mutations.set_attribute(new_attr, root.as_u64());
|
||||
} else if new_attr.is_volatile {
|
||||
if old_attr.value != new_attr.value || new_attr.is_volatile {
|
||||
self.mutations.set_attribute(new_attr, root.as_u64());
|
||||
}
|
||||
}
|
||||
|
@ -519,7 +516,7 @@ impl<'bump> DiffMachine<'bump> {
|
|||
}
|
||||
}
|
||||
|
||||
if old.children.len() == 0 && new.children.len() != 0 {
|
||||
if old.children.is_empty() && !new.children.is_empty() {
|
||||
self.mutations.edits.push(PushRoot {
|
||||
root: root.as_u64(),
|
||||
});
|
||||
|
@ -578,8 +575,8 @@ impl<'bump> DiffMachine<'bump> {
|
|||
return;
|
||||
}
|
||||
|
||||
debug_assert!(old.children.len() != 0);
|
||||
debug_assert!(new.children.len() != 0);
|
||||
debug_assert!(!old.children.is_empty());
|
||||
debug_assert!(!new.children.is_empty());
|
||||
|
||||
self.diff_children(old.children, new.children);
|
||||
}
|
||||
|
@ -748,13 +745,13 @@ impl<'bump> DiffMachine<'bump> {
|
|||
let new_middle = &new[left_offset..(new.len() - right_offset)];
|
||||
|
||||
debug_assert!(
|
||||
!((old_middle.len() == new_middle.len()) && old_middle.len() == 0),
|
||||
!((old_middle.len() == new_middle.len()) && old_middle.is_empty()),
|
||||
"keyed children must have the same number of children"
|
||||
);
|
||||
if new_middle.len() == 0 {
|
||||
if new_middle.is_empty() {
|
||||
// remove the old elements
|
||||
self.remove_nodes(old_middle);
|
||||
} else if old_middle.len() == 0 {
|
||||
} else if old_middle.is_empty() {
|
||||
// there were no old elements, so just create the new elements
|
||||
// we need to find the right "foothold" though - we shouldnt use the "append" at all
|
||||
if left_offset == 0 {
|
||||
|
|
|
@ -12,7 +12,6 @@ use std::{
|
|||
any::Any,
|
||||
cell::{Cell, RefCell},
|
||||
fmt::Debug,
|
||||
ops::Deref,
|
||||
};
|
||||
|
||||
pub use on::*;
|
||||
|
@ -34,31 +33,6 @@ pub struct UserEvent {
|
|||
pub event: Box<dyn Any + Send>,
|
||||
}
|
||||
|
||||
struct EventInner {}
|
||||
|
||||
// trait SyntheticEvent: Send + Debug {
|
||||
// fn downcast(self: Box<Self>) -> Option<Box<dyn Any>>;
|
||||
// }
|
||||
|
||||
// #[derive(Debug)]
|
||||
// pub enum SyntheticEvent {
|
||||
// AnimationEvent(on::AnimationEvent),
|
||||
// ClipboardEvent(on::ClipboardEvent),
|
||||
// CompositionEvent(on::CompositionEvent),
|
||||
// FocusEvent(on::FocusEvent),
|
||||
// FormEvent(on::FormEvent),
|
||||
// KeyboardEvent(on::KeyboardEvent),
|
||||
// GenericEvent(DioxusEvent<()>),
|
||||
// TouchEvent(on::TouchEvent),
|
||||
// ToggleEvent(on::ToggleEvent),
|
||||
// MediaEvent(on::MediaEvent),
|
||||
// MouseEvent(on::MouseEvent),
|
||||
// WheelEvent(on::WheelEvent),
|
||||
// SelectionEvent(on::SelectionEvent),
|
||||
// TransitionEvent(on::TransitionEvent),
|
||||
// PointerEvent(on::PointerEvent),
|
||||
// }
|
||||
|
||||
/// Priority of Event Triggers.
|
||||
///
|
||||
/// Internally, Dioxus will abort work that's taking too long if new, more important, work arrives. Unlike React, Dioxus
|
||||
|
@ -111,85 +85,6 @@ pub enum EventPriority {
|
|||
Low = 0,
|
||||
}
|
||||
|
||||
impl EventInner {
|
||||
/*
|
||||
Not implemented!
|
||||
|
||||
These methods come from the original web-based event system but are not implemented in Dioxus.
|
||||
|
||||
Currently, event bubbling doesn't exactly match dom-based event bubbling - IE there is no bubbling at all.
|
||||
|
||||
When bubbling is implemented, we'll make these methods public and possible to do things like cancel bubbling.
|
||||
*/
|
||||
|
||||
/// Returns whether or not a specific event is a bubbling event
|
||||
fn _bubbles(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
/// Sets or returns whether the event should propagate up the hierarchy or not
|
||||
fn _cancel_bubble(&self) {
|
||||
todo!()
|
||||
}
|
||||
/// Returns whether or not an event can have its default action prevented
|
||||
fn _cancelable(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
/// Returns whether the event is composed or not
|
||||
fn _composed(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
|
||||
// Currently not supported because those no way we could possibly support it
|
||||
// just cast the event to the right platform-specific type and return it
|
||||
/// Returns the event's path
|
||||
fn _composed_path(&self) -> String {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Returns the element whose event listeners triggered the event
|
||||
fn _current_target(&self) {
|
||||
todo!()
|
||||
}
|
||||
/// Returns whether or not the preventDefault method was called for the event
|
||||
fn _default_prevented(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
/// Returns which phase of the event flow is currently being evaluated
|
||||
fn _event_phase(&self) -> u16 {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Returns whether or not an event is trusted
|
||||
fn _is_trusted(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Cancels the event if it is cancelable, meaning that the default action that belongs to the event will
|
||||
fn _prevent_default(&self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Prevents other listeners of the same event from being called
|
||||
fn _stop_immediate_propagation(&self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Prevents further propagation of an event during event flow
|
||||
fn _stop_propagation(&self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Returns the element that triggered the event
|
||||
fn _target(&self) -> Option<Box<dyn Any>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Returns the time (in milliseconds relative to the epoch) at which the event was created
|
||||
fn _time_stamp(&self) -> f64 {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod on {
|
||||
use super::*;
|
||||
macro_rules! event_directory {
|
||||
|
|
|
@ -3,6 +3,9 @@ use std::{
|
|||
cell::{Cell, RefCell, UnsafeCell},
|
||||
};
|
||||
|
||||
type UnsafeInnerHookState = UnsafeCell<Box<dyn Any>>;
|
||||
type HookCleanup = Box<dyn FnOnce(Box<dyn Any>)>;
|
||||
|
||||
/// An abstraction over internally stored data using a hook-based memory layout.
|
||||
///
|
||||
/// Hooks are allocated using Boxes and then our stored references are given out.
|
||||
|
@ -12,7 +15,7 @@ use std::{
|
|||
/// Todo: this could use its very own bump arena, but that might be a tad overkill
|
||||
#[derive(Default)]
|
||||
pub(crate) struct HookList {
|
||||
vals: RefCell<Vec<(UnsafeCell<Box<dyn Any>>, Box<dyn FnOnce(Box<dyn Any>)>)>>,
|
||||
vals: RefCell<Vec<(UnsafeInnerHookState, HookCleanup)>>,
|
||||
idx: Cell<usize>,
|
||||
}
|
||||
|
||||
|
@ -35,7 +38,7 @@ impl HookList {
|
|||
self.idx.set(0);
|
||||
}
|
||||
|
||||
pub(crate) fn push_hook<T: 'static>(&self, new: T, cleanup: Box<dyn FnOnce(Box<dyn Any>)>) {
|
||||
pub(crate) fn push_hook<T: 'static>(&self, new: T, cleanup: HookCleanup) {
|
||||
self.vals
|
||||
.borrow_mut()
|
||||
.push((UnsafeCell::new(Box::new(new)), cleanup))
|
||||
|
@ -57,11 +60,6 @@ impl HookList {
|
|||
self.vals
|
||||
.borrow_mut()
|
||||
.drain(..)
|
||||
.for_each(|(mut state, cleanup)| {
|
||||
//
|
||||
let s: Box<dyn Any> = state.into_inner();
|
||||
cleanup(s)
|
||||
//
|
||||
});
|
||||
.for_each(|(state, cleanup)| cleanup(state.into_inner()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,10 +26,6 @@ impl<'a> Mutations<'a> {
|
|||
self.edits.push(PushRoot { root: id });
|
||||
}
|
||||
|
||||
pub(crate) fn pop(&mut self) {
|
||||
self.edits.push(PopRoot {});
|
||||
}
|
||||
|
||||
pub(crate) fn replace_with(&mut self, root: ElementId, m: u32) {
|
||||
let root = root.as_u64();
|
||||
self.edits.push(ReplaceWith { m, root });
|
||||
|
|
|
@ -269,6 +269,7 @@ pub struct Listener<'bump> {
|
|||
/// IE "click" - whatever the renderer needs to attach the listener by name.
|
||||
pub event: &'static str,
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
/// The actual callback that the user specified
|
||||
pub(crate) callback:
|
||||
RefCell<Option<BumpBox<'bump, dyn FnMut(Box<dyn std::any::Any + Send>) + 'bump>>>,
|
||||
|
@ -303,6 +304,8 @@ pub struct VComponent<'src> {
|
|||
pub struct VSuspended<'a> {
|
||||
pub task_id: u64,
|
||||
pub dom_id: Cell<Option<ElementId>>,
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub callback: RefCell<Option<BumpBox<'a, dyn FnMut(SuspendedContext<'a>) -> DomTree<'a>>>>,
|
||||
}
|
||||
|
||||
|
@ -486,10 +489,7 @@ impl<'a> NodeFactory<'a> {
|
|||
|
||||
// It's only okay to memoize if there are no children and the props can be memoized
|
||||
// Implementing memoize is unsafe and done automatically with the props trait
|
||||
match (props_memoized, children.is_empty()) {
|
||||
(true, true) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!((props_memoized, children.is_empty()), (true, true))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -74,6 +74,4 @@ impl ResourcePool {
|
|||
entry.insert(f(id));
|
||||
id
|
||||
}
|
||||
|
||||
pub fn borrow_bumpframe(&self) {}
|
||||
}
|
||||
|
|
|
@ -399,7 +399,7 @@ impl<'a> ScopeRenderer<'a> {
|
|||
}
|
||||
VNode::Element(el) => {
|
||||
write_indent(f, il);
|
||||
write!(f, "{} {{\n", el.tag_name)?;
|
||||
writeln!(f, "{} {{", el.tag_name)?;
|
||||
// write!(f, "element: {}", el.tag_name)?;
|
||||
let mut attr_iter = el.attributes.iter().peekable();
|
||||
|
||||
|
|
Loading…
Reference in a new issue