document state trait

This commit is contained in:
Evan Almloff committed 2023-02-11 17:43:08 -06:00
1 parent d8da8e4275
commit fe3ad8ebe9
11 files changed
+58 -55

No files matched your search

+2 -2
View File
@@ -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;
+9 -6
View File
@@ -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,