document state trait
This commit is contained in:
1 parent
d8da8e4275
commit
fe3ad8ebe9
11 files changed
+58
-55
No files matched your search
@@ -3,7 +3,7 @@ use std::hash::BuildHasherDefault;
|
||||
|
||||
pub use node_ref::NodeMask;
|
||||
pub use passes::AnyMapLike;
|
||||
pub use passes::{Dependancy, Pass, TypeErasedPass};
|
||||
pub use passes::{Dependancy, State, TypeErasedPass};
|
||||
pub use real_dom::{NodeMut, NodeRef, RealDom};
|
||||
use rustc_hash::FxHasher;
|
||||
pub use tree::NodeId;
|
||||
@@ -22,7 +22,7 @@ pub mod utils;
|
||||
pub mod prelude {
|
||||
pub use crate::node::{ElementNode, FromAnyValue, NodeType, OwnedAttributeView, TextNode};
|
||||
pub use crate::node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView};
|
||||
pub use crate::passes::{Dependancy, Pass};
|
||||
pub use crate::passes::{Dependancy, State};
|
||||
pub use crate::real_dom::{NodeImmutable, NodeMut, NodeRef, RealDom};
|
||||
pub use crate::tree::NodeId;
|
||||
pub use crate::SendAnyMap;
|
||||
|
||||
@@ -103,16 +103,18 @@ impl DirtyNodeStates {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Pass<V: FromAnyValue + Send + Sync = ()>: Any + Send + Sync {
|
||||
/// This is a tuple of (T: Any, ..)
|
||||
pub trait State<V: FromAnyValue + Send + Sync = ()>: Any + Send + Sync {
|
||||
/// This is a tuple of (T: Pass, ..) of states read from the parent required to run this pass
|
||||
type ParentDependencies: Dependancy;
|
||||
/// This is a tuple of (T: Any, ..)
|
||||
/// This is a tuple of (T: Pass, ..) of states read from the children required to run this pass
|
||||
type ChildDependencies: Dependancy;
|
||||
/// This is a tuple of (T: Any, ..)
|
||||
/// This is a tuple of (T: Pass, ..) of states read from the node required to run this pass
|
||||
type NodeDependencies: Dependancy;
|
||||
/// This is a mask of what aspects of the node are required to run this pass
|
||||
const NODE_MASK: NodeMaskBuilder<'static>;
|
||||
|
||||
fn pass<'a>(
|
||||
/// Update this state in a node, returns if the state was updated
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
node_view: NodeView<V>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -121,6 +123,7 @@ pub trait Pass<V: FromAnyValue + Send + Sync = ()>: Any + Send + Sync {
|
||||
context: &SendAnyMap,
|
||||
) -> bool;
|
||||
|
||||
/// Create a new instance of this state
|
||||
fn create<'a>(
|
||||
node_view: NodeView<V>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -202,7 +205,7 @@ pub trait Pass<V: FromAnyValue + Send + Sync = ()>: Any + Send + Sync {
|
||||
.value
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.pass(view, node, parent, children, context)
|
||||
.update(view, node, parent, children, context)
|
||||
}
|
||||
},
|
||||
) as PassCallback,
|
||||
|
||||
@@ -4,7 +4,7 @@ use dioxus_native_core::{
|
||||
dioxus::DioxusState,
|
||||
node_ref::{NodeMaskBuilder, NodeView},
|
||||
real_dom::RealDom,
|
||||
Dependancy, Pass, SendAnyMap,
|
||||
Dependancy, SendAnyMap, State,
|
||||
};
|
||||
|
||||
macro_rules! dep {
|
||||
|
||||
@@ -4,7 +4,7 @@ use dioxus_native_core::{
|
||||
dioxus::DioxusState,
|
||||
node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView},
|
||||
real_dom::RealDom,
|
||||
Dependancy, Pass, SendAnyMap,
|
||||
Dependancy, SendAnyMap, State,
|
||||
};
|
||||
use std::cell::Cell;
|
||||
|
||||
@@ -298,7 +298,7 @@ pub struct BlablaState {
|
||||
count: usize,
|
||||
}
|
||||
|
||||
impl Pass for BlablaState {
|
||||
impl State for BlablaState {
|
||||
type ParentDependencies = (Self,);
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -307,7 +307,7 @@ impl Pass for BlablaState {
|
||||
.with_attrs(AttributeMaskBuilder::Some(&["blabla"]))
|
||||
.with_element();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -331,7 +331,7 @@ impl Pass for BlablaState {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use dioxus_native_core::{
|
||||
dioxus::DioxusState,
|
||||
node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView},
|
||||
real_dom::RealDom,
|
||||
Dependancy, Pass, SendAnyMap,
|
||||
Dependancy, SendAnyMap, State,
|
||||
};
|
||||
use tokio::time::sleep;
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct BlablaState {
|
||||
count: usize,
|
||||
}
|
||||
|
||||
impl Pass for BlablaState {
|
||||
impl State for BlablaState {
|
||||
type ParentDependencies = (Self,);
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -21,7 +21,7 @@ impl Pass for BlablaState {
|
||||
.with_attrs(AttributeMaskBuilder::Some(&["blabla"]))
|
||||
.with_element();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -45,7 +45,7 @@ impl Pass for BlablaState {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ fn node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
struct Number(i32);
|
||||
|
||||
impl Pass for Number {
|
||||
impl State for Number {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
type ParentDependencies = ();
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::new();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -42,7 +42,7 @@ fn node_pass() {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -64,13 +64,13 @@ fn dependant_node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
impl Pass for AddNumber {
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = (SubtractNumber,);
|
||||
type ParentDependencies = ();
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::new();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -90,7 +90,7 @@ fn dependant_node_pass() {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -98,13 +98,13 @@ fn dependant_node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
struct SubtractNumber(i32);
|
||||
|
||||
impl Pass for SubtractNumber {
|
||||
impl State for SubtractNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
type ParentDependencies = ();
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::new();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -124,7 +124,7 @@ fn dependant_node_pass() {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -163,14 +163,14 @@ fn independant_node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
impl Pass for AddNumber {
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
type ParentDependencies = ();
|
||||
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::new();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -190,7 +190,7 @@ fn independant_node_pass() {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -198,14 +198,14 @@ fn independant_node_pass() {
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
struct SubtractNumber(i32);
|
||||
|
||||
impl Pass for SubtractNumber {
|
||||
impl State for SubtractNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
type ParentDependencies = ();
|
||||
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::new();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -225,7 +225,7 @@ fn independant_node_pass() {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -272,14 +272,14 @@ fn down_pass() {
|
||||
}
|
||||
}
|
||||
|
||||
impl Pass for AddNumber {
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
type ParentDependencies = (AddNumber,);
|
||||
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::new();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -301,7 +301,7 @@ fn down_pass() {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -360,14 +360,14 @@ fn up_pass() {
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
struct AddNumber(i32);
|
||||
|
||||
impl Pass for AddNumber {
|
||||
impl State for AddNumber {
|
||||
type ChildDependencies = (AddNumber,);
|
||||
type NodeDependencies = ();
|
||||
type ParentDependencies = ();
|
||||
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::new();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
_: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -389,7 +389,7 @@ fn up_pass() {
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self(1);
|
||||
myself.pass(node_view, node, parent, children, context);
|
||||
myself.update(node_view, node, parent, children, context);
|
||||
myself
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use dioxus_native_core::{
|
||||
node_ref::{AttributeMaskBuilder, NodeMaskBuilder},
|
||||
real_dom::NodeImmutable,
|
||||
utils::{ElementProduced, PersistantElementIter},
|
||||
Dependancy, NodeId, Pass, RealDom, SendAnyMap,
|
||||
Dependancy, NodeId, RealDom, SendAnyMap, State,
|
||||
};
|
||||
|
||||
use std::{cmp::Ordering, num::NonZeroU16};
|
||||
@@ -63,7 +63,7 @@ pub(crate) struct Focus {
|
||||
pub level: FocusLevel,
|
||||
}
|
||||
|
||||
impl Pass for Focus {
|
||||
impl State for Focus {
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::new()
|
||||
.with_attrs(AttributeMaskBuilder::Some(FOCUS_ATTRIBUTES))
|
||||
.with_listeners();
|
||||
@@ -72,7 +72,7 @@ impl Pass for Focus {
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
node_view: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -130,7 +130,7 @@ impl Pass for Focus {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use dioxus_native_core::layout_attributes::{
|
||||
};
|
||||
use dioxus_native_core::node::OwnedAttributeView;
|
||||
use dioxus_native_core::node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView};
|
||||
use dioxus_native_core::{Dependancy, Pass, SendAnyMap};
|
||||
use dioxus_native_core::{Dependancy, SendAnyMap, State};
|
||||
use taffy::prelude::*;
|
||||
|
||||
use crate::{screen_to_layout_space, unit_to_layout_space};
|
||||
@@ -42,7 +42,7 @@ pub(crate) struct TaffyLayout {
|
||||
pub node: PossiblyUninitalized<Node>,
|
||||
}
|
||||
|
||||
impl Pass for TaffyLayout {
|
||||
impl State for TaffyLayout {
|
||||
type ChildDependencies = (Self,);
|
||||
type ParentDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -51,7 +51,7 @@ impl Pass for TaffyLayout {
|
||||
.with_attrs(AttributeMaskBuilder::Some(SORTED_LAYOUT_ATTRS))
|
||||
.with_text();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
node_view: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -198,7 +198,7 @@ impl Pass for TaffyLayout {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use crossterm::{
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
};
|
||||
use dioxus_html::EventData;
|
||||
use dioxus_native_core::{node_ref::NodeMaskBuilder, real_dom::NodeImmutable, Pass};
|
||||
use dioxus_native_core::{node_ref::NodeMaskBuilder, real_dom::NodeImmutable, State};
|
||||
use dioxus_native_core::{real_dom::RealDom, FxDashSet, NodeId, SendAnyMap};
|
||||
use focus::FocusState;
|
||||
use futures::{channel::mpsc::UnboundedSender, pin_mut, Future, StreamExt};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus_native_core::{node_ref::NodeView, Dependancy, Pass, SendAnyMap};
|
||||
use dioxus_native_core::{node_ref::NodeView, Dependancy, SendAnyMap, State};
|
||||
|
||||
#[derive(PartialEq, Debug, Clone, Copy)]
|
||||
pub(crate) enum PreventDefault {
|
||||
@@ -25,7 +25,7 @@ impl Default for PreventDefault {
|
||||
}
|
||||
}
|
||||
|
||||
impl Pass for PreventDefault {
|
||||
impl State for PreventDefault {
|
||||
type ParentDependencies = ();
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -37,7 +37,7 @@ impl Pass for PreventDefault {
|
||||
]))
|
||||
.with_listeners();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
node_view: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -82,7 +82,7 @@ impl Pass for PreventDefault {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ use dioxus_native_core::{
|
||||
layout_attributes::parse_value,
|
||||
node::OwnedAttributeView,
|
||||
node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView},
|
||||
Dependancy, Pass, SendAnyMap,
|
||||
Dependancy, SendAnyMap, State,
|
||||
};
|
||||
use taffy::prelude::*;
|
||||
|
||||
@@ -45,7 +45,7 @@ pub struct StyleModifier {
|
||||
pub modifier: TuiModifier,
|
||||
}
|
||||
|
||||
impl Pass for StyleModifier {
|
||||
impl State for StyleModifier {
|
||||
type ParentDependencies = (Self,);
|
||||
type ChildDependencies = ();
|
||||
type NodeDependencies = ();
|
||||
@@ -55,7 +55,7 @@ impl Pass for StyleModifier {
|
||||
.with_attrs(AttributeMaskBuilder::Some(SORTED_STYLE_ATTRS))
|
||||
.with_element();
|
||||
|
||||
fn pass<'a>(
|
||||
fn update<'a>(
|
||||
&mut self,
|
||||
node_view: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
@@ -121,7 +121,7 @@ impl Pass for StyleModifier {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user