all native-core tests passing
This commit is contained in:
1 parent
ec3e02e4bb
commit
865c5aa957
11 files changed
+350
-324
No files matched your search
@@ -6,22 +6,25 @@ use dioxus_native_core::{
|
||||
real_dom::RealDom,
|
||||
Dependancy, SendAnyMap, State,
|
||||
};
|
||||
use dioxus_native_core_macro::partial_derive_state;
|
||||
use shipyard::Component;
|
||||
|
||||
macro_rules! dep {
|
||||
( child( $name:ty, $dep:ty ) ) => {
|
||||
impl Pass for $name {
|
||||
#[partial_derive_state]
|
||||
impl State for $name {
|
||||
type ParentDependencies = ();
|
||||
type ChildDependencies = $dep;
|
||||
type NodeDependencies = ();
|
||||
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::ALL;
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 += 1;
|
||||
@@ -32,30 +35,31 @@ macro_rules! dep {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
myself.pass(node_view, node, parent, children, context);
|
||||
myself.update(node_view, node, parent, children, context);
|
||||
myself
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
( parent( $name:ty, $dep:ty ) ) => {
|
||||
impl Pass for $name {
|
||||
#[partial_derive_state]
|
||||
impl State for $name {
|
||||
type ParentDependencies = $dep;
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::ALL;
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 += 1;
|
||||
@@ -66,30 +70,31 @@ macro_rules! dep {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
myself.pass(node_view, node, parent, children, context);
|
||||
myself.update(node_view, node, parent, children, context);
|
||||
myself
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
( node( $name:ty, $dep:ty ) ) => {
|
||||
impl Pass for $name {
|
||||
#[partial_derive_state]
|
||||
impl State for $name {
|
||||
type ParentDependencies = $dep;
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::ALL;
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 += 1;
|
||||
@@ -100,11 +105,11 @@ macro_rules! dep {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
myself.pass(node_view, node, parent, children, context);
|
||||
myself.update(node_view, node, parent, children, context);
|
||||
myself
|
||||
}
|
||||
}
|
||||
@@ -145,7 +150,7 @@ macro_rules! test_state{
|
||||
let mut dioxus_state = DioxusState::create(&mut dom);
|
||||
|
||||
dioxus_state.apply_mutations(&mut dom, mutations);
|
||||
dom.update_state(SendAnyMap::new(), false);
|
||||
dom.update_state(SendAnyMap::new());
|
||||
|
||||
dom.traverse_depth_first(|n| {
|
||||
$(
|
||||
@@ -158,15 +163,15 @@ macro_rules! test_state{
|
||||
|
||||
mod node_depends_on_child_and_parent {
|
||||
use super::*;
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Node(i32);
|
||||
dep!(node(Node, (Child, Parent)));
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Child(i32);
|
||||
dep!(child(Child, (Child,)));
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Parent(i32);
|
||||
dep!(parent(Parent, (Parent,)));
|
||||
|
||||
@@ -175,15 +180,15 @@ mod node_depends_on_child_and_parent {
|
||||
|
||||
mod child_depends_on_node_that_depends_on_parent {
|
||||
use super::*;
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Node(i32);
|
||||
dep!(node(Node, (Parent,)));
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Child(i32);
|
||||
dep!(child(Child, (Node,)));
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Parent(i32);
|
||||
dep!(parent(Parent, (Parent,)));
|
||||
|
||||
@@ -192,15 +197,15 @@ mod child_depends_on_node_that_depends_on_parent {
|
||||
|
||||
mod parent_depends_on_node_that_depends_on_child {
|
||||
use super::*;
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Node(i32);
|
||||
dep!(node(Node, (Child,)));
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Child(i32);
|
||||
dep!(child(Child, (Child,)));
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Parent(i32);
|
||||
dep!(parent(Parent, (Node,)));
|
||||
|
||||
@@ -209,11 +214,11 @@ mod parent_depends_on_node_that_depends_on_child {
|
||||
|
||||
mod node_depends_on_other_node_state {
|
||||
use super::*;
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Node1(i32);
|
||||
dep!(node(Node1, (Node2,)));
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Node2(i32);
|
||||
dep!(node(Node2, ()));
|
||||
|
||||
@@ -222,15 +227,15 @@ mod node_depends_on_other_node_state {
|
||||
|
||||
mod node_child_and_parent_state_depends_on_self {
|
||||
use super::*;
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Node(i32);
|
||||
dep!(node(Node, ()));
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Child(i32);
|
||||
dep!(child(Child, (Child,)));
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Component)]
|
||||
struct Parent(i32);
|
||||
dep!(parent(Parent, (Parent,)));
|
||||
|
||||
|
||||
@@ -3,9 +3,12 @@ use dioxus_core::*;
|
||||
use dioxus_native_core::{
|
||||
dioxus::DioxusState,
|
||||
node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView},
|
||||
prelude::*,
|
||||
real_dom::RealDom,
|
||||
Dependancy, SendAnyMap, State,
|
||||
};
|
||||
use dioxus_native_core_macro::partial_derive_state;
|
||||
use shipyard::Component;
|
||||
use std::cell::Cell;
|
||||
|
||||
fn random_ns() -> Option<&'static str> {
|
||||
@@ -231,7 +234,7 @@ fn create_random_dynamic_attr(cx: &ScopeState) -> Attribute {
|
||||
|
||||
static mut TEMPLATE_COUNT: usize = 0;
|
||||
|
||||
#[derive(PartialEq, Props)]
|
||||
#[derive(PartialEq, Props, Component)]
|
||||
struct DepthProps {
|
||||
depth: usize,
|
||||
root: bool,
|
||||
@@ -293,11 +296,12 @@ fn create_random_element(cx: Scope<DepthProps>) -> Element {
|
||||
node
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default, Component)]
|
||||
pub struct BlablaState {
|
||||
count: usize,
|
||||
}
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for BlablaState {
|
||||
type ParentDependencies = (Self,);
|
||||
type ChildDependencies = ();
|
||||
@@ -312,7 +316,7 @@ impl State for BlablaState {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
if let Some((parent,)) = parent {
|
||||
@@ -327,7 +331,7 @@ impl State for BlablaState {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -353,7 +357,7 @@ fn create() {
|
||||
dioxus_state.apply_mutations(&mut rdom, mutations);
|
||||
|
||||
let ctx = SendAnyMap::new();
|
||||
rdom.update_state(ctx, false);
|
||||
rdom.update_state(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,13 +379,13 @@ fn diff() {
|
||||
dioxus_state.apply_mutations(&mut rdom, mutations);
|
||||
|
||||
let ctx = SendAnyMap::new();
|
||||
rdom.update_state(ctx, false);
|
||||
rdom.update_state(ctx);
|
||||
for _ in 0..10 {
|
||||
let mutations = vdom.render_immediate();
|
||||
dioxus_state.apply_mutations(&mut rdom, mutations);
|
||||
|
||||
let ctx = SendAnyMap::new();
|
||||
rdom.update_state(ctx, false);
|
||||
rdom.update_state(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,20 @@ use dioxus::prelude::*;
|
||||
use dioxus_native_core::{
|
||||
dioxus::DioxusState,
|
||||
node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView},
|
||||
prelude::*,
|
||||
real_dom::RealDom,
|
||||
Dependancy, SendAnyMap, State,
|
||||
};
|
||||
use dioxus_native_core_macro::partial_derive_state;
|
||||
use shipyard::Component;
|
||||
use tokio::time::sleep;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default, Component)]
|
||||
pub struct BlablaState {
|
||||
count: usize,
|
||||
}
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for BlablaState {
|
||||
type ParentDependencies = (Self,);
|
||||
type ChildDependencies = ();
|
||||
@@ -26,7 +30,7 @@ impl State for BlablaState {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
if let Some((parent,)) = parent {
|
||||
@@ -41,7 +45,7 @@ impl State for BlablaState {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -143,7 +147,7 @@ fn native_core_is_okay() {
|
||||
dioxus_state.apply_mutations(&mut *rdom.lock().unwrap(), mutations);
|
||||
|
||||
let ctx = SendAnyMap::new();
|
||||
rdom.lock().unwrap().update_state(ctx, false);
|
||||
rdom.lock().unwrap().update_state(ctx);
|
||||
|
||||
for _ in 0..10 {
|
||||
dom.wait_for_work().await;
|
||||
@@ -152,7 +156,7 @@ fn native_core_is_okay() {
|
||||
dioxus_state.apply_mutations(&mut *rdom.lock().unwrap(), mutations);
|
||||
|
||||
let ctx = SendAnyMap::new();
|
||||
rdom.lock().unwrap().update_state(ctx, false);
|
||||
rdom.lock().unwrap().update_state(ctx);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
use dioxus_native_core::node::NodeType;
|
||||
use dioxus_native_core::prelude::*;
|
||||
use dioxus_native_core_macro::partial_derive_state;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use shipyard::Component;
|
||||
|
||||
fn create_blank_element() -> NodeType {
|
||||
NodeType::Element(ElementNode {
|
||||
@@ -13,9 +15,10 @@ fn create_blank_element() -> NodeType {
|
||||
|
||||
#[test]
|
||||
fn node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Component)]
|
||||
struct Number(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for Number {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -27,7 +30,7 @@ fn node_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 += 1;
|
||||
@@ -38,7 +41,7 @@ fn node_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -48,22 +51,29 @@ fn node_pass() {
|
||||
}
|
||||
|
||||
let mut tree: RealDom = RealDom::new(Box::new([Number::to_type_erased()]));
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
assert_eq!(tree.get(tree.root_id()).unwrap().get(), Some(&Number(1)));
|
||||
assert_eq!(
|
||||
tree.get(tree.root_id()).unwrap().get().as_deref(),
|
||||
Some(&Number(1))
|
||||
);
|
||||
|
||||
// mark the node as dirty
|
||||
tree.get_mut(tree.root_id()).unwrap().get_mut::<Number>();
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
assert_eq!(tree.get(tree.root_id()).unwrap().get(), Some(&Number(2)));
|
||||
tree.update_state(SendAnyMap::new());
|
||||
assert_eq!(
|
||||
tree.get(tree.root_id()).unwrap().get().as_deref(),
|
||||
Some(&Number(2))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dependant_node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Component)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = (SubtractNumber,);
|
||||
@@ -75,7 +85,7 @@ fn dependant_node_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 += 1;
|
||||
@@ -86,7 +96,7 @@ fn dependant_node_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -95,9 +105,10 @@ fn dependant_node_pass() {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Component)]
|
||||
struct SubtractNumber(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for SubtractNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -109,7 +120,7 @@ fn dependant_node_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 -= 1;
|
||||
@@ -120,7 +131,7 @@ fn dependant_node_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -133,36 +144,37 @@ fn dependant_node_pass() {
|
||||
AddNumber::to_type_erased(),
|
||||
SubtractNumber::to_type_erased(),
|
||||
]));
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-1)));
|
||||
|
||||
// mark the subtract state as dirty, it should update the add state
|
||||
tree.get_mut(tree.root_id())
|
||||
.unwrap()
|
||||
.get_mut::<SubtractNumber>();
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-2)));
|
||||
|
||||
// mark the add state as dirty, it should ~not~ update the subtract state
|
||||
tree.get_mut(tree.root_id()).unwrap().get_mut::<AddNumber>();
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(3)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(3)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn independant_node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Component)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -175,7 +187,7 @@ fn independant_node_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 += 1;
|
||||
@@ -186,7 +198,7 @@ fn independant_node_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -195,9 +207,10 @@ fn independant_node_pass() {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Component)]
|
||||
struct SubtractNumber(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for SubtractNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -210,7 +223,7 @@ fn independant_node_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
self.0 -= 1;
|
||||
@@ -221,7 +234,7 @@ fn independant_node_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -234,36 +247,36 @@ fn independant_node_pass() {
|
||||
AddNumber::to_type_erased(),
|
||||
SubtractNumber::to_type_erased(),
|
||||
]));
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-1)));
|
||||
|
||||
// mark the subtract state as dirty, it should ~not~ update the add state
|
||||
tree.get_mut(tree.root_id())
|
||||
.unwrap()
|
||||
.get_mut::<SubtractNumber>();
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-2)));
|
||||
|
||||
// mark the add state as dirty, it should ~not~ update the subtract state
|
||||
tree.get_mut(tree.root_id()).unwrap().get_mut::<AddNumber>();
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(root.get(), Some(&SubtractNumber(-2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(2)));
|
||||
assert_eq!(root.get().as_deref(), Some(&SubtractNumber(-2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn down_pass() {
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Component)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
impl Default for AddNumber {
|
||||
@@ -272,6 +285,7 @@ fn down_pass() {
|
||||
}
|
||||
}
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -284,7 +298,7 @@ fn down_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
if let Some((parent,)) = parent {
|
||||
@@ -297,7 +311,7 @@ fn down_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
@@ -321,25 +335,24 @@ fn down_pass() {
|
||||
parent.add_child(child1);
|
||||
parent.add_child(child2);
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
dbg!(root.id());
|
||||
assert_eq!(root.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(1)));
|
||||
|
||||
let child1 = tree.get(child1).unwrap();
|
||||
dbg!(child1.id());
|
||||
dbg!(child1.parent().unwrap().get::<AddNumber>());
|
||||
assert_eq!(child1.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(child1.get().as_deref(), Some(&AddNumber(2)));
|
||||
|
||||
let grandchild1 = tree.get(grandchild1).unwrap();
|
||||
assert_eq!(grandchild1.get(), Some(&AddNumber(3)));
|
||||
assert_eq!(grandchild1.get().as_deref(), Some(&AddNumber(3)));
|
||||
|
||||
let child2 = tree.get(child2).unwrap();
|
||||
assert_eq!(child2.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(child2.get().as_deref(), Some(&AddNumber(2)));
|
||||
|
||||
let grandchild2 = tree.get(grandchild2).unwrap();
|
||||
assert_eq!(grandchild2.get(), Some(&AddNumber(3)));
|
||||
assert_eq!(grandchild2.get().as_deref(), Some(&AddNumber(3)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -357,9 +370,10 @@ fn up_pass() {
|
||||
// 2=\
|
||||
// 1
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Component)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = (AddNumber,);
|
||||
type NodeDependencies = ();
|
||||
@@ -372,12 +386,10 @@ fn up_pass() {
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
if let Some(children) = children {
|
||||
self.0 += children.iter().map(|(i,)| i.0).sum::<i32>();
|
||||
}
|
||||
self.0 += children.iter().map(|(i,)| i.0).sum::<i32>();
|
||||
true
|
||||
}
|
||||
|
||||
@@ -385,7 +397,7 @@ fn up_pass() {
|
||||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self(1);
|
||||
@@ -409,20 +421,20 @@ fn up_pass() {
|
||||
parent.add_child(child1);
|
||||
parent.add_child(child2);
|
||||
|
||||
tree.update_state(SendAnyMap::new(), false);
|
||||
tree.update_state(SendAnyMap::new());
|
||||
|
||||
let root = tree.get(tree.root_id()).unwrap();
|
||||
assert_eq!(root.get(), Some(&AddNumber(5)));
|
||||
assert_eq!(root.get().as_deref(), Some(&AddNumber(5)));
|
||||
|
||||
let child1 = tree.get(child1).unwrap();
|
||||
assert_eq!(child1.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(child1.get().as_deref(), Some(&AddNumber(2)));
|
||||
|
||||
let grandchild1 = tree.get(grandchild1).unwrap();
|
||||
assert_eq!(grandchild1.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(grandchild1.get().as_deref(), Some(&AddNumber(1)));
|
||||
|
||||
let child2 = tree.get(child2).unwrap();
|
||||
assert_eq!(child2.get(), Some(&AddNumber(2)));
|
||||
assert_eq!(child2.get().as_deref(), Some(&AddNumber(2)));
|
||||
|
||||
let grandchild2 = tree.get(grandchild2).unwrap();
|
||||
assert_eq!(grandchild2.get(), Some(&AddNumber(1)));
|
||||
assert_eq!(grandchild2.get().as_deref(), Some(&AddNumber(1)));
|
||||
}
|
||||
Reference in new issue
Block a user