mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
fix clippy
This commit is contained in:
parent
3827378f68
commit
2e3a730ed5
6 changed files with 139 additions and 143 deletions
|
@ -2,7 +2,7 @@ use std::ops::{Deref, DerefMut};
|
|||
|
||||
use crate::{
|
||||
any_props::AnyProps,
|
||||
innerlude::{DirtyScopes, ElementRef, MountId, ScopeOrder, VComponent, WriteMutations},
|
||||
innerlude::{ElementRef, MountId, ScopeOrder, VComponent, WriteMutations},
|
||||
nodes::RenderReturn,
|
||||
nodes::VNode,
|
||||
scopes::ScopeId,
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
//!
|
||||
//! #[component]
|
||||
//! fn Child(vec: Signal<Vec<usize>>, idx: usize) -> Element {
|
||||
//! use_hook(|| {
|
||||
//! spawn(async {
|
||||
//! use_hook(move || {
|
||||
//! spawn(async move {
|
||||
//! // If we let this task run after the child is dropped, it will panic.
|
||||
//! println!("Task {}", vec.read()[idx]);
|
||||
//! });
|
||||
|
@ -30,7 +30,6 @@
|
|||
use crate::ScopeId;
|
||||
use crate::Task;
|
||||
use std::borrow::Borrow;
|
||||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeSet;
|
||||
use std::hash::Hash;
|
||||
|
@ -83,7 +82,7 @@ impl DirtyScopes {
|
|||
match self.tasks.get(&order) {
|
||||
Some(scope) => scope.queue_task(task),
|
||||
None => {
|
||||
let mut scope = DirtyTasks::from(order);
|
||||
let scope = DirtyTasks::from(order);
|
||||
scope.queue_task(task);
|
||||
self.tasks.insert(scope);
|
||||
}
|
||||
|
@ -105,11 +104,6 @@ impl DirtyScopes {
|
|||
self.tasks.pop_first()
|
||||
}
|
||||
|
||||
/// Take the highest scope that needs to be rerendered
|
||||
pub fn pop_scope(&mut self) -> Option<ScopeOrder> {
|
||||
self.scopes.pop_first()
|
||||
}
|
||||
|
||||
/// Take any work from the highest scope. This may include rerunning the scope and/or running tasks
|
||||
pub fn pop_work(&mut self) -> Option<Work> {
|
||||
let dirty_scope = self.scopes.first();
|
||||
|
@ -121,7 +115,7 @@ impl DirtyScopes {
|
|||
std::cmp::Ordering::Less => {
|
||||
let scope = self.scopes.pop_first().unwrap();
|
||||
Some(Work {
|
||||
scope: scope,
|
||||
scope,
|
||||
rerun_scope: true,
|
||||
tasks: Vec::new(),
|
||||
})
|
||||
|
@ -138,22 +132,22 @@ impl DirtyScopes {
|
|||
let scope = self.scopes.pop_first().unwrap();
|
||||
let task = self.tasks.pop_first().unwrap();
|
||||
Some(Work {
|
||||
scope: scope,
|
||||
scope,
|
||||
rerun_scope: true,
|
||||
tasks: task.tasks_queued.into_inner(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
(Some(scope), None) => {
|
||||
(Some(_), None) => {
|
||||
let scope = self.scopes.pop_first().unwrap();
|
||||
Some(Work {
|
||||
scope: scope,
|
||||
scope,
|
||||
rerun_scope: true,
|
||||
tasks: Vec::new(),
|
||||
})
|
||||
}
|
||||
(None, Some(task)) => {
|
||||
(None, Some(_)) => {
|
||||
let task = self.tasks.pop_first().unwrap();
|
||||
Some(Work {
|
||||
scope: task.order,
|
||||
|
|
|
@ -34,8 +34,7 @@ impl RenderSignal {
|
|||
waker: None,
|
||||
}));
|
||||
self.wakers.borrow_mut().push(inner.clone());
|
||||
let waker = RenderSignalFuture { inner };
|
||||
waker
|
||||
RenderSignalFuture { inner }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use crate::{
|
|||
use futures_util::StreamExt;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use slab::Slab;
|
||||
use std::{any::Any, collections::BTreeSet, rc::Rc};
|
||||
use std::{any::Any, rc::Rc};
|
||||
use tracing::instrument;
|
||||
|
||||
/// A virtual node system that progresses user events and diffs UI trees.
|
||||
|
@ -468,7 +468,7 @@ impl VirtualDom {
|
|||
// Make sure we set the runtime since we're running user code
|
||||
let _runtime = RuntimeGuard::new(self.runtime.clone());
|
||||
|
||||
/// There isn't any more work we can do synchronously. Wait for any new work to be ready
|
||||
// There isn't any more work we can do synchronously. Wait for any new work to be ready
|
||||
match self.rx.next().await.expect("channel should never close") {
|
||||
SchedulerMsg::Immediate(id) => self.mark_dirty(id),
|
||||
SchedulerMsg::TaskNotified(id) => {
|
||||
|
|
|
@ -16,6 +16,7 @@ async fn child_futures_drop_first() {
|
|||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Child() -> Element {
|
||||
// Spawn a task that will increment POLL_COUNT every 10 milliseconds
|
||||
// This should be dropped after the second time the parent is run
|
||||
|
|
|
@ -1,146 +1,148 @@
|
|||
#![allow(unused, non_upper_case_globals, non_snake_case)]
|
||||
use dioxus_core::NoOpMutations;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
// TODO: fix #1935
|
||||
|
||||
use dioxus::html::p;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::ElementId;
|
||||
use dioxus_signals::*;
|
||||
use std::cell::RefCell;
|
||||
// #![allow(unused, non_upper_case_globals, non_snake_case)]
|
||||
// use dioxus_core::NoOpMutations;
|
||||
// use std::collections::HashMap;
|
||||
// use std::rc::Rc;
|
||||
|
||||
#[test]
|
||||
fn memos_rerun() {
|
||||
let _ = simple_logger::SimpleLogger::new().init();
|
||||
// use dioxus::html::p;
|
||||
// use dioxus::prelude::*;
|
||||
// use dioxus_core::ElementId;
|
||||
// use dioxus_signals::*;
|
||||
// use std::cell::RefCell;
|
||||
|
||||
#[derive(Default)]
|
||||
struct RunCounter {
|
||||
component: usize,
|
||||
effect: usize,
|
||||
}
|
||||
// #[test]
|
||||
// fn memos_rerun() {
|
||||
// let _ = simple_logger::SimpleLogger::new().init();
|
||||
|
||||
let counter = Rc::new(RefCell::new(RunCounter::default()));
|
||||
let mut dom = VirtualDom::new_with_props(
|
||||
|counter: Rc<RefCell<RunCounter>>| {
|
||||
counter.borrow_mut().component += 1;
|
||||
// #[derive(Default)]
|
||||
// struct RunCounter {
|
||||
// component: usize,
|
||||
// effect: usize,
|
||||
// }
|
||||
|
||||
let mut signal = use_signal(|| 0);
|
||||
let memo = use_memo({
|
||||
to_owned![counter];
|
||||
move || {
|
||||
counter.borrow_mut().effect += 1;
|
||||
println!("Signal: {:?}", signal);
|
||||
signal()
|
||||
}
|
||||
});
|
||||
assert_eq!(memo(), 0);
|
||||
signal += 1;
|
||||
assert_eq!(memo(), 1);
|
||||
// let counter = Rc::new(RefCell::new(RunCounter::default()));
|
||||
// let mut dom = VirtualDom::new_with_props(
|
||||
// |counter: Rc<RefCell<RunCounter>>| {
|
||||
// counter.borrow_mut().component += 1;
|
||||
|
||||
rsx! {
|
||||
div {}
|
||||
}
|
||||
},
|
||||
counter.clone(),
|
||||
);
|
||||
// let mut signal = use_signal(|| 0);
|
||||
// let memo = use_memo({
|
||||
// to_owned![counter];
|
||||
// move || {
|
||||
// counter.borrow_mut().effect += 1;
|
||||
// println!("Signal: {:?}", signal);
|
||||
// signal()
|
||||
// }
|
||||
// });
|
||||
// assert_eq!(memo(), 0);
|
||||
// signal += 1;
|
||||
// assert_eq!(memo(), 1);
|
||||
|
||||
dom.rebuild_in_place();
|
||||
// rsx! {
|
||||
// div {}
|
||||
// }
|
||||
// },
|
||||
// counter.clone(),
|
||||
// );
|
||||
|
||||
let current_counter = counter.borrow();
|
||||
assert_eq!(current_counter.component, 1);
|
||||
assert_eq!(current_counter.effect, 2);
|
||||
}
|
||||
// dom.rebuild_in_place();
|
||||
|
||||
#[test]
|
||||
fn memos_prevents_component_rerun() {
|
||||
let _ = simple_logger::SimpleLogger::new().init();
|
||||
// let current_counter = counter.borrow();
|
||||
// assert_eq!(current_counter.component, 1);
|
||||
// assert_eq!(current_counter.effect, 2);
|
||||
// }
|
||||
|
||||
#[derive(Default)]
|
||||
struct RunCounter {
|
||||
component: usize,
|
||||
memo: usize,
|
||||
}
|
||||
// #[test]
|
||||
// fn memos_prevents_component_rerun() {
|
||||
// let _ = simple_logger::SimpleLogger::new().init();
|
||||
|
||||
let counter = Rc::new(RefCell::new(RunCounter::default()));
|
||||
let mut dom = VirtualDom::new_with_props(
|
||||
|props: Rc<RefCell<RunCounter>>| {
|
||||
let mut signal = use_signal(|| 0);
|
||||
// #[derive(Default)]
|
||||
// struct RunCounter {
|
||||
// component: usize,
|
||||
// memo: usize,
|
||||
// }
|
||||
|
||||
if generation() == 1 {
|
||||
*signal.write() = 0;
|
||||
}
|
||||
if generation() == 2 {
|
||||
println!("Writing to signal");
|
||||
*signal.write() = 1;
|
||||
}
|
||||
// let counter = Rc::new(RefCell::new(RunCounter::default()));
|
||||
// let mut dom = VirtualDom::new_with_props(
|
||||
// |props: Rc<RefCell<RunCounter>>| {
|
||||
// let mut signal = use_signal(|| 0);
|
||||
|
||||
rsx! {
|
||||
Child {
|
||||
signal: signal,
|
||||
counter: props.clone(),
|
||||
}
|
||||
}
|
||||
},
|
||||
counter.clone(),
|
||||
);
|
||||
// if generation() == 1 {
|
||||
// *signal.write() = 0;
|
||||
// }
|
||||
// if generation() == 2 {
|
||||
// println!("Writing to signal");
|
||||
// *signal.write() = 1;
|
||||
// }
|
||||
|
||||
#[derive(Default, Props, Clone)]
|
||||
struct ChildProps {
|
||||
signal: Signal<usize>,
|
||||
counter: Rc<RefCell<RunCounter>>,
|
||||
}
|
||||
// rsx! {
|
||||
// Child {
|
||||
// signal: signal,
|
||||
// counter: props.clone(),
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// counter.clone(),
|
||||
// );
|
||||
|
||||
impl PartialEq for ChildProps {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.signal == other.signal
|
||||
}
|
||||
}
|
||||
// #[derive(Default, Props, Clone)]
|
||||
// struct ChildProps {
|
||||
// signal: Signal<usize>,
|
||||
// counter: Rc<RefCell<RunCounter>>,
|
||||
// }
|
||||
|
||||
fn Child(props: ChildProps) -> Element {
|
||||
let counter = &props.counter;
|
||||
let signal = props.signal;
|
||||
counter.borrow_mut().component += 1;
|
||||
// impl PartialEq for ChildProps {
|
||||
// fn eq(&self, other: &Self) -> bool {
|
||||
// self.signal == other.signal
|
||||
// }
|
||||
// }
|
||||
|
||||
let memo = use_memo({
|
||||
to_owned![counter];
|
||||
move || {
|
||||
counter.borrow_mut().memo += 1;
|
||||
println!("Signal: {:?}", signal);
|
||||
signal()
|
||||
}
|
||||
});
|
||||
match generation() {
|
||||
0 => {
|
||||
assert_eq!(memo(), 0);
|
||||
}
|
||||
1 => {
|
||||
assert_eq!(memo(), 1);
|
||||
}
|
||||
_ => panic!("Unexpected generation"),
|
||||
}
|
||||
// fn Child(props: ChildProps) -> Element {
|
||||
// let counter = &props.counter;
|
||||
// let signal = props.signal;
|
||||
// counter.borrow_mut().component += 1;
|
||||
|
||||
rsx! {
|
||||
div {}
|
||||
}
|
||||
}
|
||||
// let memo = use_memo({
|
||||
// to_owned![counter];
|
||||
// move || {
|
||||
// counter.borrow_mut().memo += 1;
|
||||
// println!("Signal: {:?}", signal);
|
||||
// signal()
|
||||
// }
|
||||
// });
|
||||
// match generation() {
|
||||
// 0 => {
|
||||
// assert_eq!(memo(), 0);
|
||||
// }
|
||||
// 1 => {
|
||||
// assert_eq!(memo(), 1);
|
||||
// }
|
||||
// _ => panic!("Unexpected generation"),
|
||||
// }
|
||||
|
||||
dom.rebuild_in_place();
|
||||
dom.mark_dirty(ScopeId::ROOT);
|
||||
dom.render_immediate(&mut NoOpMutations);
|
||||
// rsx! {
|
||||
// div {}
|
||||
// }
|
||||
// }
|
||||
|
||||
{
|
||||
let current_counter = counter.borrow();
|
||||
assert_eq!(current_counter.component, 1);
|
||||
assert_eq!(current_counter.memo, 2);
|
||||
}
|
||||
// dom.rebuild_in_place();
|
||||
// dom.mark_dirty(ScopeId::ROOT);
|
||||
// dom.render_immediate(&mut NoOpMutations);
|
||||
|
||||
dom.mark_dirty(ScopeId::ROOT);
|
||||
dom.render_immediate(&mut NoOpMutations);
|
||||
dom.render_immediate(&mut NoOpMutations);
|
||||
// {
|
||||
// let current_counter = counter.borrow();
|
||||
// assert_eq!(current_counter.component, 1);
|
||||
// assert_eq!(current_counter.memo, 2);
|
||||
// }
|
||||
|
||||
{
|
||||
let current_counter = counter.borrow();
|
||||
assert_eq!(current_counter.component, 2);
|
||||
assert_eq!(current_counter.memo, 3);
|
||||
}
|
||||
}
|
||||
// dom.mark_dirty(ScopeId::ROOT);
|
||||
// dom.render_immediate(&mut NoOpMutations);
|
||||
// dom.render_immediate(&mut NoOpMutations);
|
||||
|
||||
// {
|
||||
// let current_counter = counter.borrow();
|
||||
// assert_eq!(current_counter.component, 2);
|
||||
// assert_eq!(current_counter.memo, 3);
|
||||
// }
|
||||
// }
|
||||
|
|
Loading…
Reference in a new issue