Feat: WIP ctx

This commit is contained in:
Jonathan Kelley committed 2021-02-20 21:59:16 -05:00
1 parent b3e6886351
commit 7a6aabe4f3
18 files changed
+430 -99

No files matched your search

+57 -5
View File
@@ -3,17 +3,69 @@
use std::marker::PhantomData;
use dioxus_core::prelude::VNode;
use bumpalo::Bump;
use dioxus_core::prelude::{DomTree, VNode};
fn main() {}
struct Context2<'a> {
_p: PhantomData<&'a ()>,
struct Context2<'a, P> {
props: &'a P, // _p: PhantomData<&'a ()>,
}
impl<'a, P> Context2<'a, P> {
fn view(&self, f: impl FnOnce(&'a Bump) -> VNode<'a>) -> DTree {
DTree {}
}
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!()
}
}
type FC2<'a, 'b, 'c: 'a + 'b, P> = fn(Context2<'a>, &'b P) -> VNode<'c>;
struct DTree;
type FC2<'a, T: 'a> = fn(&'a Context2<T>) -> DTree;
static Example: FC2<()> = |ctx, props| {
struct Props {
c: String,
}
static Example: FC2<Props> = |ctx| {
let val = use_state(&ctx, || String::from("asd"));
ctx.view(move |b| {
let g: VNode<'_> = virtual_child(b, Props2 { a: val }, alt_child);
//
dioxus_core::nodebuilder::div(b)
.child(dioxus_core::nodebuilder::text(ctx.props.c.as_str()))
.child(g)
.finish()
})
};
fn virtual_child<'a, T: 'a>(bump: &'a Bump, props: T, f: FC2<T>) -> VNode<'a> {
todo!()
}
struct Props2<'a> {
a: &'a String,
}
fn alt_child<'a>(ctx: &Context2<'a, Props2<'_>>) -> DomTree {
todo!()
}
static CHILD: FC2<Props2> = |ctx| {
//
todo!()
};
fn use_state<'a, 'c, P, T: 'static, F: FnOnce() -> T>(
ctx: &'a Context2<'a, P>,
initial_state_fn: F,
) -> (&'a T) {
todo!()
}
+32
View File
@@ -0,0 +1,32 @@
use std::marker::PhantomData;
fn main() {}
trait Props<'parent> {}
struct SomeProps<'p> {
text: &'p str,
}
impl<'p> Props<'p> for SomeProps<'p> {}
struct OutputNode<'a> {
_p: PhantomData<&'a ()>,
}
// combine reference to self (borrowed from self) and referenfce to parent (borrowed from parent)
// borrow chain looks like 'p + 's -> 'p + 's -> 'p + 's
// always adding new lifetimes from self into the mix
// what does a "self" lifetime mean?
// a "god" gives us our data
// the god's lifetime is tied to Context, and the borrowed props object
// for the sake of simplicity, we just clobber lifetimes.
// user functions are just lies and we abuse lifetimes.
// everything is managed at runtime because that's how we make something ergonomc
// lifetime management in dioxus is just cheating around the rules
// our kind god manages lifetimes for us so we don't have to, thanks god
fn something<'s>(props: &'s SomeProps<'s>) -> OutputNode<'s> {
todo!()
}
// type BC<'p, P: Props<'p>> = for<'a, 'b, 'c> fn(&'a P<'b>) -> OutputNode<'c>;
+8 -6
View File
@@ -16,16 +16,18 @@ fn main() -> Result<(), ()> {
Ok(())
}
#[derive(Debug)]
struct Props {
name: String,
}
impl Properties for Props {
fn call(&self, ptr: *const ()) {}
// fn new() -> Self {
// todo!()
// }
}
// impl Properties for Props {
// fn call(&self, ptr: *const ()) {}
// // fn new() -> Self {
// // todo!()
// // }
// }
static Example: FC<Props> = |ctx, props| {
ctx.view(html! {