Props, reconciler fixes, demo fixes

This commit is contained in:
Ryan McGrath 2019-06-05 21:15:46 -07:00
parent 47163c64f9
commit 290b57d336
No known key found for this signature in database
GPG key ID: 811674B62B666830
17 changed files with 284 additions and 190 deletions

View file

@ -3,23 +3,22 @@
//! uses these to build and alter UI; they're typically returned from `render()`
//! methods.
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;
mod props;
pub use props::Props;
use crate::reconciler::key::ComponentKey;
use crate::traits::Component;
/// An enum representing the types of nodes that the
/// system can work with. `None`, `VirtualText`, or `VirtualNode`.
#[derive(Clone)]
pub enum RSX {
None,
VirtualText(VirtualText),
@ -29,15 +28,19 @@ pub enum RSX {
impl RSX {
/// Shorthand method for creating a new `RSX::VirtualNode` instance. Rarely should you call
/// this yourself; the `rsx! {}` macro handles this for you.
pub fn node(
pub fn node<P: Any + 'static>(
tag: &'static str,
styles: StylesList,
create_fn: fn(key: ComponentKey) -> Box<Component>,
props: Props
props: P,
children: Vec<RSX>
) -> RSX {
RSX::VirtualNode(VirtualNode {
tag: tag,
create_component_fn: create_fn,
props: props
styles: styles,
props: Box::new(props),
children: children
})
}