Feat: listeners now have scope information

This commit is contained in:
Jonathan Kelley committed 2021-03-03 11:13:46 -05:00
1 parent cb74d70f83
commit fcd68e61d2
17 files changed
+897 -906

No files matched your search

+75 -75
View File
@@ -1,93 +1,93 @@
//! An alternative function syntax
//!
// //! An alternative function syntax
// //!
use bumpalo::Bump;
use dioxus_core::prelude::VNode;
// use bumpalo::Bump;
// use dioxus_core::prelude::VNode;
fn main() {}
struct Context2<'a, P> {
_props: &'a P, // _p: PhantomData<&'a ()>,
rops: &'a P, // _p: PhantomData<&'a ()>,
}
impl<'a, P> Context2<'a, P> {
fn render(self, _f: impl FnOnce(&'a Bump) -> VNode<'a>) -> DTree {
DTree {}
}
// struct Context2<'a, P> {
// _props: &'a P, // _p: PhantomData<&'a ()>,
// rops: &'a P, // _p: PhantomData<&'a ()>,
// }
// impl<'a, P> Context2<'a, P> {
// fn render(self, _f: impl FnOnce(&'a Bump) -> VNode<'a>) -> DTree {
// DTree {}
// }
fn props(&self) -> &'a P {
todo!()
}
// fn props(&self) -> &'a P {
// todo!()
// }
pub fn use_hook<'scope, InternalHookState: 'static, Output: 'a>(
&'scope self,
_initializer: impl FnOnce() -> InternalHookState,
_runner: impl FnOnce(&'a mut InternalHookState) -> Output,
_cleanup: impl FnOnce(InternalHookState),
) -> Output {
todo!()
}
}
// pub fn use_hook<'scope, InternalHookState: 'static, Output: 'a>(
// &'scope self,
// _initializer: impl FnOnce() -> InternalHookState,
// _runner: impl FnOnce(&'a mut InternalHookState) -> Output,
// _cleanup: impl FnOnce(InternalHookState),
// ) -> Output {
// todo!()
// }
// }
trait Properties {}
// trait Properties {}
struct DTree;
// type FC2<'a, T: 'a> = fn(Context2<T>) -> DTree;
fn virtual_child<'a, T: 'a>(_bump: &'a Bump, _props: T, _f: FC2<T>) -> VNode<'a> {
todo!()
}
// struct DTree;
// // type FC2<'a, T: 'a> = fn(Context2<T>) -> DTree;
// fn virtual_child<'a, T: 'a>(_bump: &'a Bump, _props: T, _f: FC2<T>) -> VNode<'a> {
// todo!()
// }
struct Props {
c: String,
}
// struct Props {
// c: String,
// }
fn Example(ctx: Context2<Props>) -> DTree {
let val = use_state(&ctx, || String::from("asd"));
let props = ctx.props();
// fn Example(ctx: Context2<Props>) -> DTree {
// let val = use_state(&ctx, || String::from("asd"));
// let props = ctx.props();
ctx.render(move |b| {
dioxus_core::nodebuilder::div(b)
.child(dioxus_core::nodebuilder::text(props.c.as_str()))
.child(virtual_child(b, Props2 { a: val }, AltChild))
.finish()
})
}
// ctx.render(move |b| {
// dioxus_core::nodebuilder::div(b)
// .child(dioxus_core::nodebuilder::text(props.c.as_str()))
// .child(virtual_child(b, Props2 { a: val }, AltChild))
// .finish()
// })
// }
// #[fc]
fn Example2(ctx: Context2<()>, name: &str, _blah: &str) -> DTree {
let val = use_state(&ctx, || String::from("asd"));
// // #[fc]
// fn Example2(ctx: Context2<()>, name: &str, _blah: &str) -> DTree {
// let val = use_state(&ctx, || String::from("asd"));
ctx.render(move |b| {
dioxus_core::nodebuilder::div(b)
.child(dioxus_core::nodebuilder::text(name))
.child(virtual_child(b, Props2 { a: val }, AltChild))
.finish()
})
}
// ctx.render(move |ctx| {
// dioxus_core::builder::ElementBuilder::new(b, "div")
// .child(dioxus_core::nodebuilder::text(name))
// .child(virtual_child(b, Props2 { a: val }, AltChild))
// .finish()
// })
// }
type FC2<'a, T> = fn(Context2<T>) -> DTree;
// type FC2<'a, T> = fn(Context2<T>) -> DTree;
// still works if you don't take any references in your props (ie, something copy or cloneable)
static CHILD: FC2<Props2> = |_ctx: Context2<Props2>| {
//
todo!()
};
// // still works if you don't take any references in your props (ie, something copy or cloneable)
// static CHILD: FC2<Props2> = |_ctx: Context2<Props2>| {
// //
// todo!()
// };
struct Props2<'a> {
a: &'a String,
}
impl Properties for Props2<'_> {}
// struct Props2<'a> {
// a: &'a String,
// }
// impl Properties for Props2<'_> {}
fn AltChild(ctx: Context2<Props2>) -> DTree {
ctx.render(|_b| {
//
todo!()
})
}
// fn AltChild(ctx: Context2<Props2>) -> DTree {
// ctx.render(|_b| {
// //
// todo!()
// })
// }
fn use_state<'a, 'c, P, T: 'static, F: FnOnce() -> T>(
_ctx: &'_ Context2<'a, P>,
_initial_state_fn: F,
) -> &'a T {
todo!()
}
// fn use_state<'a, 'c, P, T: 'static, F: FnOnce() -> T>(
// _ctx: &'_ Context2<'a, P>,
// _initial_state_fn: F,
// ) -> &'a T {
// todo!()
// }
+2 -2
View File
@@ -22,12 +22,12 @@ fn app(ctx: Context, props: &Props) -> DomTree {
let (f, setter) = use_state(&ctx, || 0);
ctx.render(move |b| {
let mut root = builder::div(b);
let mut root = builder::ElementBuilder::new(b, "div");
for child in &props.items {
// notice that the child directly borrows from our vec
// this makes lists very fast (simply views reusing lifetimes)
root = root.child(builder::virtual_child(
b,
b.bump,
ChildProps {
item: child,
item_handler: setter,
+1 -2
View File
@@ -1,4 +1,3 @@
use builder::button;
use dioxus_core::prelude::*;
fn main() {}
@@ -15,7 +14,7 @@ static Example: FC<Props> = |ctx, props| {
let value = ctx.use_context(|c: &SomeContext| c.items.last().unwrap());
ctx.render(move |bump| {
button(bump)
builder::ElementBuilder::new(bump, "button")
.on("click", move |_| {
println!("Value is {}", props.name);
println!("Value is {}", value.as_str());
+1 -1
View File
@@ -13,7 +13,7 @@ static Header: FC<()> = |ctx, props| {
let handler1 = move || println!("Value is {}", inner.current());
ctx.render(|bump| {
builder::div(bump)
builder::ElementBuilder::new(bump, "div")
.child(VNode::Component(VComponent::new(
Bottom,
//