update native core tests
This commit is contained in:
1 parent
6cf0274a5b
commit
c8eb5c7dd7
2 files changed
+180
-143
No files matched your search
@@ -1,12 +1,10 @@
|
||||
use dioxus::prelude::Props;
|
||||
use dioxus_core::*;
|
||||
use dioxus_native_core::{
|
||||
node_ref::{AttributeMask, NodeView},
|
||||
node_ref::{AttributeMask, AttributeMaskBuilder, NodeMaskBuilder, NodeView},
|
||||
real_dom::RealDom,
|
||||
state::{ParentDepState, State},
|
||||
NodeMask, SendAnyMap,
|
||||
Dependancy, NodeMask, Pass, SendAnyMap,
|
||||
};
|
||||
use dioxus_native_core_macro::{sorted_str_slice, State};
|
||||
use std::cell::Cell;
|
||||
|
||||
fn random_ns() -> Option<&'static str> {
|
||||
@@ -295,25 +293,46 @@ fn create_random_element(cx: Scope<DepthProps>) -> Element {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct BlablaState {}
|
||||
|
||||
/// Font style are inherited by default if not specified otherwise by some of the supported attributes.
|
||||
impl ParentDepState for BlablaState {
|
||||
type Ctx = ();
|
||||
type DepState = (Self,);
|
||||
|
||||
const NODE_MASK: NodeMask =
|
||||
NodeMask::new_with_attrs(AttributeMask::Static(&sorted_str_slice!(["blabla",])));
|
||||
|
||||
fn reduce(&mut self, _node: NodeView, _parent: Option<(&Self,)>, _ctx: &Self::Ctx) -> bool {
|
||||
false
|
||||
}
|
||||
pub struct BlablaState {
|
||||
count: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, State, Default, Debug)]
|
||||
pub struct NodeState {
|
||||
#[parent_dep_state(blabla)]
|
||||
blabla: BlablaState,
|
||||
impl Pass for BlablaState {
|
||||
type ParentDependencies = (Self,);
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
|
||||
const NODE_MASK: NodeMaskBuilder = NodeMaskBuilder::new()
|
||||
.with_attrs(AttributeMaskBuilder::Some(&["blabla"]))
|
||||
.with_element();
|
||||
|
||||
fn pass<'a>(
|
||||
&mut self,
|
||||
node_view: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
if let Some((parent,)) = parent {
|
||||
if parent.count != 0 {
|
||||
self.count += 1;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn create<'a>(
|
||||
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>>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
myself.pass(node_view, node, parent, children, context);
|
||||
myself
|
||||
}
|
||||
}
|
||||
|
||||
// test for panics when creating random nodes and templates
|
||||
@@ -328,11 +347,11 @@ fn create() {
|
||||
},
|
||||
);
|
||||
let mutations = vdom.rebuild();
|
||||
let mut rdom: RealDom<NodeState> = RealDom::new();
|
||||
let (to_update, _diff) = rdom.apply_mutations(mutations);
|
||||
let mut rdom: RealDom = RealDom::new(Box::new([BlablaState::to_type_erased()]));
|
||||
rdom.apply_mutations(mutations);
|
||||
|
||||
let ctx = SendAnyMap::new();
|
||||
rdom.update_state(to_update, ctx);
|
||||
rdom.update_state(ctx, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,17 +368,17 @@ fn diff() {
|
||||
},
|
||||
);
|
||||
let mutations = vdom.rebuild();
|
||||
let mut rdom: RealDom<NodeState> = RealDom::new();
|
||||
let (to_update, _diff) = rdom.apply_mutations(mutations);
|
||||
let mut rdom: RealDom = RealDom::new(Box::new([BlablaState::to_type_erased()]));
|
||||
rdom.apply_mutations(mutations);
|
||||
|
||||
let ctx = SendAnyMap::new();
|
||||
rdom.update_state(to_update, ctx);
|
||||
rdom.update_state(ctx, false);
|
||||
for _ in 0..10 {
|
||||
let mutations = vdom.render_immediate();
|
||||
let (to_update, _diff) = rdom.apply_mutations(mutations);
|
||||
rdom.apply_mutations(mutations);
|
||||
|
||||
let ctx = SendAnyMap::new();
|
||||
rdom.update_state(to_update, ctx);
|
||||
rdom.update_state(ctx, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user