mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-26 22:20:19 +00:00
update native core tests
This commit is contained in:
parent
6cf0274a5b
commit
c8eb5c7dd7
2 changed files with 180 additions and 143 deletions
|
@ -1,12 +1,10 @@
|
||||||
use dioxus::prelude::Props;
|
use dioxus::prelude::Props;
|
||||||
use dioxus_core::*;
|
use dioxus_core::*;
|
||||||
use dioxus_native_core::{
|
use dioxus_native_core::{
|
||||||
node_ref::{AttributeMask, NodeView},
|
node_ref::{AttributeMask, AttributeMaskBuilder, NodeMaskBuilder, NodeView},
|
||||||
real_dom::RealDom,
|
real_dom::RealDom,
|
||||||
state::{ParentDepState, State},
|
Dependancy, NodeMask, Pass, SendAnyMap,
|
||||||
NodeMask, SendAnyMap,
|
|
||||||
};
|
};
|
||||||
use dioxus_native_core_macro::{sorted_str_slice, State};
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
fn random_ns() -> Option<&'static str> {
|
fn random_ns() -> Option<&'static str> {
|
||||||
|
@ -295,25 +293,46 @@ fn create_random_element(cx: Scope<DepthProps>) -> Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||||
pub struct BlablaState {}
|
pub struct BlablaState {
|
||||||
|
count: usize,
|
||||||
/// 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, State, Default, Debug)]
|
impl Pass for BlablaState {
|
||||||
pub struct NodeState {
|
type ParentDependencies = (Self,);
|
||||||
#[parent_dep_state(blabla)]
|
type ChildDependencies = ();
|
||||||
blabla: BlablaState,
|
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
|
// test for panics when creating random nodes and templates
|
||||||
|
@ -328,11 +347,11 @@ fn create() {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
let mutations = vdom.rebuild();
|
let mutations = vdom.rebuild();
|
||||||
let mut rdom: RealDom<NodeState> = RealDom::new();
|
let mut rdom: RealDom = RealDom::new(Box::new([BlablaState::to_type_erased()]));
|
||||||
let (to_update, _diff) = rdom.apply_mutations(mutations);
|
rdom.apply_mutations(mutations);
|
||||||
|
|
||||||
let ctx = SendAnyMap::new();
|
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 mutations = vdom.rebuild();
|
||||||
let mut rdom: RealDom<NodeState> = RealDom::new();
|
let mut rdom: RealDom = RealDom::new(Box::new([BlablaState::to_type_erased()]));
|
||||||
let (to_update, _diff) = rdom.apply_mutations(mutations);
|
rdom.apply_mutations(mutations);
|
||||||
|
|
||||||
let ctx = SendAnyMap::new();
|
let ctx = SendAnyMap::new();
|
||||||
rdom.update_state(to_update, ctx);
|
rdom.update_state(ctx, false);
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
let mutations = vdom.render_immediate();
|
let mutations = vdom.render_immediate();
|
||||||
let (to_update, _diff) = rdom.apply_mutations(mutations);
|
rdom.apply_mutations(mutations);
|
||||||
|
|
||||||
let ctx = SendAnyMap::new();
|
let ctx = SendAnyMap::new();
|
||||||
rdom.update_state(to_update, ctx);
|
rdom.update_state(ctx, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,140 +1,158 @@
|
||||||
// use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
// use dioxus_native_core::{
|
use dioxus_core::*;
|
||||||
// node_ref::{AttributeMask, NodeView},
|
use dioxus_native_core::{
|
||||||
// real_dom::RealDom,
|
node_ref::{AttributeMask, AttributeMaskBuilder, NodeMaskBuilder, NodeView},
|
||||||
// state::{ParentDepState, State},
|
real_dom::RealDom,
|
||||||
// NodeMask, SendAnyMap,
|
Dependancy, NodeMask, Pass, SendAnyMap,
|
||||||
// };
|
};
|
||||||
// use dioxus_native_core_macro::{sorted_str_slice, State};
|
use std::cell::Cell;
|
||||||
// use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
// use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
// #[derive(Debug, Clone, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||||
// pub struct BlablaState {}
|
pub struct BlablaState {
|
||||||
|
count: usize,
|
||||||
|
}
|
||||||
|
|
||||||
// /// Font style are inherited by default if not specified otherwise by some of the supported attributes.
|
impl Pass for BlablaState {
|
||||||
// impl ParentDepState for BlablaState {
|
type ParentDependencies = (Self,);
|
||||||
// type Ctx = ();
|
type ChildDependencies = ();
|
||||||
// type DepState = (Self,);
|
type NodeDependencies = ();
|
||||||
|
|
||||||
// const NODE_MASK: NodeMask =
|
const NODE_MASK: NodeMaskBuilder = NodeMaskBuilder::new()
|
||||||
// NodeMask::new_with_attrs(AttributeMask::Static(&sorted_str_slice!(["blabla",])));
|
.with_attrs(AttributeMaskBuilder::Some(&["blabla"]))
|
||||||
|
.with_element();
|
||||||
|
|
||||||
// fn reduce<'a>(
|
fn pass<'a>(
|
||||||
// &mut self,
|
&mut self,
|
||||||
// _node: NodeView,
|
node_view: NodeView,
|
||||||
// _parent: Option<(&'a Self,)>,
|
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||||
// _ctx: &Self::Ctx,
|
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||||
// ) -> bool {
|
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||||
// false
|
_: &SendAnyMap,
|
||||||
// }
|
) -> bool {
|
||||||
// }
|
if let Some((parent,)) = parent {
|
||||||
|
if parent.count != 0 {
|
||||||
|
self.count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
// #[derive(Clone, State, Default, Debug)]
|
fn create<'a>(
|
||||||
// pub struct NodeState {
|
node_view: NodeView<()>,
|
||||||
// #[parent_dep_state(blabla)]
|
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||||
// blabla: BlablaState,
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// mod dioxus_elements {
|
mod dioxus_elements {
|
||||||
// macro_rules! builder_constructors {
|
macro_rules! builder_constructors {
|
||||||
// (
|
(
|
||||||
// $(
|
$(
|
||||||
// $(#[$attr:meta])*
|
$(#[$attr:meta])*
|
||||||
// $name:ident {
|
$name:ident {
|
||||||
// $(
|
$(
|
||||||
// $(#[$attr_method:meta])*
|
$(#[$attr_method:meta])*
|
||||||
// $fil:ident: $vil:ident,
|
$fil:ident: $vil:ident,
|
||||||
// )*
|
)*
|
||||||
// };
|
};
|
||||||
// )*
|
)*
|
||||||
// ) => {
|
) => {
|
||||||
// $(
|
$(
|
||||||
// #[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
// $(#[$attr])*
|
$(#[$attr])*
|
||||||
// pub struct $name;
|
pub struct $name;
|
||||||
|
|
||||||
// impl $name {
|
impl $name {
|
||||||
// pub const TAG_NAME: &'static str = stringify!($name);
|
pub const TAG_NAME: &'static str = stringify!($name);
|
||||||
// pub const NAME_SPACE: Option<&'static str> = None;
|
pub const NAME_SPACE: Option<&'static str> = None;
|
||||||
|
|
||||||
// $(
|
$(
|
||||||
// pub const $fil: (&'static str, Option<&'static str>, bool) = (stringify!($fil), None, false);
|
pub const $fil: (&'static str, Option<&'static str>, bool) = (stringify!($fil), None, false);
|
||||||
// )*
|
)*
|
||||||
// }
|
}
|
||||||
|
|
||||||
// impl GlobalAttributes for $name {}
|
impl GlobalAttributes for $name {}
|
||||||
// )*
|
)*
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// pub trait GlobalAttributes {}
|
pub trait GlobalAttributes {}
|
||||||
|
|
||||||
// pub trait SvgAttributes {}
|
pub trait SvgAttributes {}
|
||||||
|
|
||||||
// builder_constructors! {
|
builder_constructors! {
|
||||||
// blabla {
|
blabla {
|
||||||
|
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn native_core_is_okay() {
|
fn native_core_is_okay() {
|
||||||
// use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
// fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
// let colors = use_state(cx, || vec!["green", "blue", "red"]);
|
let colors = use_state(cx, || vec!["green", "blue", "red"]);
|
||||||
// let padding = use_state(cx, || 10);
|
let padding = use_state(cx, || 10);
|
||||||
|
|
||||||
// use_effect(cx, colors, |colors| async move {
|
use_effect(cx, colors, |colors| async move {
|
||||||
// sleep(Duration::from_millis(1000)).await;
|
sleep(Duration::from_millis(1000)).await;
|
||||||
// colors.with_mut(|colors| colors.reverse());
|
colors.with_mut(|colors| colors.reverse());
|
||||||
// });
|
});
|
||||||
|
|
||||||
// use_effect(cx, padding, |padding| async move {
|
use_effect(cx, padding, |padding| async move {
|
||||||
// sleep(Duration::from_millis(10)).await;
|
sleep(Duration::from_millis(10)).await;
|
||||||
// padding.with_mut(|padding| {
|
padding.with_mut(|padding| {
|
||||||
// if *padding < 65 {
|
if *padding < 65 {
|
||||||
// *padding += 1;
|
*padding += 1;
|
||||||
// } else {
|
} else {
|
||||||
// *padding = 5;
|
*padding = 5;
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// let _big = colors[0];
|
let _big = colors[0];
|
||||||
// let _mid = colors[1];
|
let _mid = colors[1];
|
||||||
// let _small = colors[2];
|
let _small = colors[2];
|
||||||
|
|
||||||
// cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
// blabla {}
|
blabla {}
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
|
|
||||||
// let rt = tokio::runtime::Builder::new_current_thread()
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
// .enable_time()
|
.enable_time()
|
||||||
// .build()
|
.build()
|
||||||
// .unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// rt.block_on(async {
|
rt.block_on(async {
|
||||||
// let rdom = Arc::new(Mutex::new(RealDom::<NodeState>::new()));
|
let rdom = Arc::new(Mutex::new(RealDom::new(Box::new([
|
||||||
// let mut dom = VirtualDom::new(app);
|
BlablaState::to_type_erased(),
|
||||||
|
]))));
|
||||||
|
let mut dom = VirtualDom::new(app);
|
||||||
|
|
||||||
// let muts = dom.rebuild();
|
let muts = dom.rebuild();
|
||||||
// let (to_update, _diff) = rdom.lock().unwrap().apply_mutations(muts);
|
rdom.lock().unwrap().apply_mutations(muts);
|
||||||
|
|
||||||
// let ctx = SendAnyMap::new();
|
let ctx = SendAnyMap::new();
|
||||||
// rdom.lock().unwrap().update_state(to_update, ctx);
|
rdom.lock().unwrap().update_state(ctx, false);
|
||||||
|
|
||||||
// for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
// dom.wait_for_work().await;
|
dom.wait_for_work().await;
|
||||||
|
|
||||||
// let mutations = dom.render_immediate();
|
let mutations = dom.render_immediate();
|
||||||
// let (to_update, _diff) = rdom.lock().unwrap().apply_mutations(mutations);
|
rdom.lock().unwrap().apply_mutations(mutations);
|
||||||
|
|
||||||
// let ctx = SendAnyMap::new();
|
let ctx = SendAnyMap::new();
|
||||||
// rdom.lock().unwrap().update_state(to_update, ctx);
|
rdom.lock().unwrap().update_state(ctx, false);
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
Loading…
Reference in a new issue