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