diff --git a/packages/core/src/lib.rs b/packages/core/src/lib.rs index 79ba4e0d1..72d89fc45 100644 --- a/packages/core/src/lib.rs +++ b/packages/core/src/lib.rs @@ -43,6 +43,7 @@ pub(crate) mod innerlude { pub use crate::hooks::*; pub use crate::nodebuilder::*; pub use crate::nodes::*; + pub use crate::util::*; pub use crate::virtual_dom::*; pub type FC

= fn(Context

) -> VNode; diff --git a/packages/core/src/util.rs b/packages/core/src/util.rs index 73e75e7b4..e2600150c 100644 --- a/packages/core/src/util.rs +++ b/packages/core/src/util.rs @@ -1,5 +1,44 @@ +use std::{cell::RefCell, rc::Rc}; + use crate::innerlude::*; +// We actually allocate the properties for components in their parent's properties +// We then expose a handle to use those props for render in the form of "OpaqueComponent" +pub type OpaqueComponent = dyn for<'b> Fn(&'b Scope) -> VNode<'b>; + +#[derive(PartialEq, Debug, Clone, Default)] +pub struct EventQueue(pub Rc>>); + +impl EventQueue { + pub fn new_channel(&self, height: u32, idx: ScopeIdx) -> Rc { + let inner = self.clone(); + let marker = HeightMarker { height, idx }; + Rc::new(move || { + log::debug!("channel updated {:#?}", marker); + inner.0.as_ref().borrow_mut().push(marker) + }) + } +} + +/// A helper type that lets scopes be ordered by their height +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct HeightMarker { + pub idx: ScopeIdx, + pub height: u32, +} + +impl Ord for HeightMarker { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.height.cmp(&other.height) + } +} + +impl PartialOrd for HeightMarker { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + pub struct DebugDom { counter: u64, } diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 65e409710..348cb27bc 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -586,56 +586,3 @@ impl Scope { &self.frames.cur_frame().head_node } } - -// ================================================================================== -// Supporting structs for the above abstractions -// ================================================================================== - -// We actually allocate the properties for components in their parent's properties -// We then expose a handle to use those props for render in the form of "OpaqueComponent" -pub type OpaqueComponent = dyn for<'b> Fn(&'b Scope) -> VNode<'b>; - -#[derive(PartialEq, Debug, Clone, Default)] -pub struct EventQueue(pub Rc>>); - -impl EventQueue { - pub fn new_channel(&self, height: u32, idx: ScopeIdx) -> Rc { - let inner = self.clone(); - let marker = HeightMarker { height, idx }; - Rc::new(move || { - log::debug!("channel updated {:#?}", marker); - inner.0.as_ref().borrow_mut().push(marker) - }) - } -} - -/// A helper type that lets scopes be ordered by their height -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct HeightMarker { - pub idx: ScopeIdx, - pub height: u32, -} - -impl Ord for HeightMarker { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.height.cmp(&other.height) - } -} - -impl PartialOrd for HeightMarker { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct ContextId { - // Which component is the scope in - original: ScopeIdx, - - // What's the height of the scope - height: u32, - - // Which scope is it (in order) - id: u32, -}