Feat: overall API updates

This commit is contained in:
Jonathan Kelley committed 2021-02-12 00:29:46 -05:00
1 parent 125f5426a4
commit f47651b32a
16 files changed
+234 -177

No files matched your search

+22 -12
View File
@@ -37,7 +37,7 @@ mod vnode {
Suspended,
/// A User-defined componen node (node type COMPONENT_NODE)
Component(VComponent),
Component(VComponent<'src>),
}
impl<'a> VNode<'a> {
@@ -174,11 +174,7 @@ mod velement {
}
/// An event listener.
pub struct Listener<'a>
// pub struct Listener<'a, 'b>
// where
// 'b: 'a + 'static,
{
pub struct Listener<'a> {
/// The type of event to listen for.
pub(crate) event: &'a str,
/// The callback to invoke when the event happens.
@@ -249,19 +245,33 @@ mod vtext {
/// Only supports the functional syntax
mod vcomponent {
use crate::prelude::Properties;
use std::{any::TypeId, fmt, future::Future};
use std::{any::TypeId, fmt, future::Future, marker::PhantomData};
use super::VNode;
#[derive(PartialEq)]
pub struct VComponent {
// props_id: TypeId,
pub struct VComponent<'src> {
_p: PhantomData<&'src ()>,
runner: Box<dyn Properties + 'src>,
caller: *const (),
props_type: TypeId,
}
// impl<'src> PartialEq for CallerSource<'src> {
// fn eq(&self, other: &Self) -> bool {
// todo!()
// }
// }
// caller: Box<dyn Fn
// should we box the caller?
// probably, so we can call it again
//
// props_id: TypeId,
// callerIDs are unsafely coerced to function pointers
// This is okay because #1, we store the props_id and verify and 2# the html! macro rejects components not made this way
//
// Manually constructing the VComponent is not possible from 3rd party crates
}
impl VComponent {
impl<'a> VComponent<'a> {
// /// Construct a VComponent directly from a function component
// /// This should be *very* fast - we store the function pointer and props type ID. It should also be small on the stack
// pub fn from_fn<P: Properties>(f: FC<P>, props: P) -> Self {