Feat: move the rsx macro around
This commit is contained in:
1 parent
1919f88f03
commit
50c8b93aad
23 files changed
+886
-617
No files matched your search
@@ -9,7 +9,7 @@ use crate::innerlude::FC;
|
||||
|
||||
pub type ScopeIdx = generational_arena::Index;
|
||||
|
||||
pub trait Properties: PartialEq + 'static {
|
||||
pub trait Properties: PartialEq {
|
||||
type Builder;
|
||||
fn builder() -> Self::Builder;
|
||||
}
|
||||
|
||||
@@ -194,6 +194,12 @@ impl<'a> DiffMachine<'a> {
|
||||
(VNode::Suspended, _) | (_, VNode::Suspended) => {
|
||||
todo!("Suspended components not currently available")
|
||||
}
|
||||
|
||||
(VNode::Fragment(_), VNode::Fragment(_)) => {
|
||||
todo!("Fragments not currently supported in diffing")
|
||||
}
|
||||
(_, VNode::Fragment(_)) => todo!("Fragments not currently supported in diffing"),
|
||||
(VNode::Fragment(_), _) => todo!("Fragments not currently supported in diffing"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,6 +282,10 @@ impl<'a> DiffMachine<'a> {
|
||||
VNode::Suspended => {
|
||||
todo!("Creation of VNode::Suspended not yet supported")
|
||||
}
|
||||
VNode::Fragment(frag) => {
|
||||
//
|
||||
todo!("Cannot current create fragments")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -20,12 +20,6 @@ mod use_state_def {
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
struct UseState<T: 'static> {
|
||||
new_val: Rc<RefCell<Option<T>>>,
|
||||
current_val: T,
|
||||
caller: Rc<dyn Fn(T) + 'static>,
|
||||
}
|
||||
|
||||
/// Store state between component renders!
|
||||
/// When called, this hook retrives a stored value and provides a setter to update that value.
|
||||
/// When the setter is called, the component is re-ran with the new value.
|
||||
@@ -48,10 +42,16 @@ mod use_state_def {
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T, P: 'static>(
|
||||
ctx: &'c Context<'a, P>,
|
||||
pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T, P: 'a>(
|
||||
ctx: Context<'a, P>,
|
||||
initial_state_fn: F,
|
||||
) -> (&'a T, &'a Rc<dyn Fn(T)>) {
|
||||
struct UseState<T: 'static> {
|
||||
new_val: Rc<RefCell<Option<T>>>,
|
||||
current_val: T,
|
||||
caller: Rc<dyn Fn(T) + 'static>,
|
||||
}
|
||||
|
||||
ctx.use_hook(
|
||||
move || UseState {
|
||||
new_val: Rc::new(RefCell::new(None)),
|
||||
@@ -170,7 +170,7 @@ mod new_use_state_def {
|
||||
/// }
|
||||
/// ```
|
||||
pub fn use_state_new<'a, 'c, T: 'static, F: FnOnce() -> T, P: 'static>(
|
||||
ctx: &'c Context<'a, P>,
|
||||
ctx: Context<'a, P>,
|
||||
initial_state_fn: F,
|
||||
) -> &'a UseState<T> {
|
||||
ctx.use_hook(
|
||||
@@ -271,7 +271,7 @@ mod use_reducer_def {
|
||||
/// This is behaves almost exactly the same way as React's "use_state".
|
||||
///
|
||||
pub fn use_reducer<'a, 'c, State: 'static, Action: 'static, P: 'static>(
|
||||
ctx: &'c Context<'a, P>,
|
||||
ctx: Context<'a, P>,
|
||||
initial_state_fn: impl FnOnce() -> State,
|
||||
_reducer: impl Fn(&mut State, Action),
|
||||
) -> (&'a State, &'a Box<dyn Fn(Action)>) {
|
||||
|
||||
@@ -580,6 +580,7 @@ where
|
||||
std::iter::once(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoVNode<'a> for () {
|
||||
fn into_vnode(self, ctx: &NodeCtx<'a>) -> VNode<'a> {
|
||||
VNode::Suspended
|
||||
|
||||
@@ -8,7 +8,13 @@ use crate::{
|
||||
innerlude::{Context, Properties, Scope, ScopeIdx, FC},
|
||||
};
|
||||
use bumpalo::Bump;
|
||||
use std::{any::Any, cell::RefCell, fmt::Debug, marker::PhantomData, rc::Rc};
|
||||
use std::{
|
||||
any::Any,
|
||||
cell::RefCell,
|
||||
fmt::{Arguments, Debug},
|
||||
marker::PhantomData,
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
/// Tools for the base unit of the virtual dom - the VNode
|
||||
/// VNodes are intended to be quickly-allocated, lightweight enum values.
|
||||
@@ -22,6 +28,8 @@ pub enum VNode<'src> {
|
||||
/// A text node (node type `TEXT_NODE`).
|
||||
Text(VText<'src>),
|
||||
|
||||
Fragment(&'src VFragment<'src>),
|
||||
|
||||
/// A "suspended component"
|
||||
/// This is a masqeurade over an underlying future that needs to complete
|
||||
/// When the future is completed, the VNode will then trigger a render
|
||||
@@ -37,6 +45,7 @@ impl<'a> Clone for VNode<'a> {
|
||||
match self {
|
||||
VNode::Element(el) => VNode::Element(el),
|
||||
VNode::Text(origi) => VNode::Text(VText { text: origi.text }),
|
||||
VNode::Fragment(frag) => VNode::Fragment(frag),
|
||||
VNode::Suspended => VNode::Suspended,
|
||||
VNode::Component(c) => VNode::Component(c),
|
||||
}
|
||||
@@ -77,6 +86,10 @@ impl<'a> VNode<'a> {
|
||||
VNode::Text(VText { text })
|
||||
}
|
||||
|
||||
pub fn text_args(b: &'a Bump, f: Arguments) -> VNode<'a> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn key(&self) -> NodeKey {
|
||||
match &self {
|
||||
@@ -85,9 +98,7 @@ impl<'a> VNode<'a> {
|
||||
VNode::Suspended => {
|
||||
todo!()
|
||||
}
|
||||
// Self::PhantomChild { id } => {
|
||||
// todo!()
|
||||
// }
|
||||
VNode::Fragment(frag) => frag.key,
|
||||
VNode::Component(c) => c.key,
|
||||
}
|
||||
}
|
||||
@@ -315,3 +326,8 @@ impl<'a> VComponent<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VFragment<'src> {
|
||||
pub key: NodeKey<'src>,
|
||||
pub children: &'src [VNode<'src>],
|
||||
}
|
||||
@@ -725,8 +725,10 @@ impl<'src, T> Context<'src, T> {
|
||||
}
|
||||
|
||||
/// Create a subscription that schedules a future render for the reference component
|
||||
pub fn schedule_update(&self) -> impl Fn() -> () + 'static {
|
||||
self.scope.event_queue.schedule_update(&self.scope)
|
||||
pub fn schedule_update(&self) -> Rc<dyn Fn() + 'static> {
|
||||
todo!()
|
||||
// pub fn schedule_update(self) -> impl Fn() + 'static {
|
||||
// self.scope.event_queue.schedule_update(&self.scope)
|
||||
}
|
||||
|
||||
// /// Create a suspended component from a future.
|
||||
@@ -765,6 +767,7 @@ impl<'src, T> Context<'src, T> {
|
||||
self,
|
||||
// &'a/ self,
|
||||
lazy_nodes: LazyNodes<'src, F>,
|
||||
// lazy_nodes: LazyNodes<'src, F>,
|
||||
) -> VNode<'src> {
|
||||
let ctx = NodeCtx {
|
||||
scope_ref: self.scope,
|
||||
@@ -961,6 +964,10 @@ impl<'src, P> Context<'src, P> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OpaqueScope {
|
||||
fn get_scope(&self) -> &Scope;
|
||||
}
|
||||
|
||||
// ==================================================================================
|
||||
// Supporting structs for the above abstractions
|
||||
// ==================================================================================
|
||||
|
||||
Reference in new issue
Block a user