use std::any::Any;
use std::fmt::{Debug, Display};
use alchemy_styles::StylesList;
mod virtual_node;
pub use virtual_node::VirtualNode;
mod virtual_text;
pub use virtual_text::VirtualText;
use crate::reconciler::key::ComponentKey;
use crate::traits::Component;
pub enum RSX {
None,
VirtualText(VirtualText),
VirtualNode(VirtualNode)
}
impl RSX {
pub fn node<P: Any + 'static>(
tag: &'static str,
styles: StylesList,
create_fn: fn(key: ComponentKey) -> Box<Component>,
props: P,
children: Vec<RSX>
) -> RSX {
RSX::VirtualNode(VirtualNode {
tag: tag,
create_component_fn: create_fn,
styles: styles,
props: Box::new(props),
children: children
})
}
pub fn text(s: String) -> RSX {
RSX::VirtualText(VirtualText(s))
}
}
impl IntoIterator for RSX {
type Item = RSX;
type IntoIter = std::vec::IntoIter<RSX>;
fn into_iter(self) -> Self::IntoIter {
vec![self].into_iter()
}
}
impl Display for RSX {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match self {
RSX::VirtualNode(node) => { std::fmt::Display::fmt(&node, f) },
RSX::VirtualText(text) => { std::fmt::Display::fmt(&text, f) }
RSX::None => { Ok(()) }
}
}
}
impl Debug for RSX {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
RSX::VirtualNode(node) => { std::fmt::Debug::fmt(&node, f) },
RSX::VirtualText(text) => { std::fmt::Debug::fmt(&text, f) }
RSX::None => { Ok(()) }
}
}
}