Feat: push new component API and context API

This commit is contained in:
Jonathan Kelley committed 2021-02-11 23:03:01 -05:00
1 parent 8329268d39
commit 125f5426a4
14 files changed
+432 -264

No files matched your search

+18 -46
View File
@@ -1,4 +1,4 @@
use std::{marker::PhantomData, ops::Deref};
use std::{borrow::Borrow, marker::PhantomData, ops::Deref};
use builder::{button, div};
use dioxus_core::prelude::*;
@@ -7,34 +7,27 @@ fn main() {}
struct SomeContext {
items: Vec<String>,
}
/*
desired behavior:
free to move the context guard around
not free to move contents of context guard into closure
struct Props {
name: String,
}
rules:
can deref in a function
cannot drag the refs into the closure w
*/
#[allow(unused)]
static Example: FC<Props> = |ctx, props| {
let value = ctx.use_context(|c: &SomeContext| c.items.last().unwrap());
static Example: FC<()> = |ctx| {
// let value = use_context(&ctx, |ctx: &SomeContext| ctx.items.last().unwrap());
// let b = *value;
// let v2 = *value;
let cb = move |e| {
// let g = b.as_str();
// let g = (v2).as_str();
// let g = (value).as_str();
// let g = b.as_str();
};
// let r = *value;
// let r2 = *r;
ctx.view(|bump| {
ctx.view(move |bump| {
button(bump)
.listeners([builder::on(bump, "click", cb)])
.on("click", move |_| {
// //
println!("Value is {}", props.name);
println!("Value is {}", value.as_str());
println!("Value is {}", *value);
})
//
.on("click", move |_| {
println!("Value is {}", props.name);
})
.finish()
})
// ctx.view(html! {
@@ -48,24 +41,3 @@ static Example: FC<()> = |ctx| {
// </div>
// })
};
#[derive(Clone, Copy)]
struct ContextGuard<T> {
val: PhantomData<T>,
}
impl<'a, T> Deref for ContextGuard<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
todo!()
}
}
fn use_context<'scope, 'dope, 'a, P: Properties, I, O: 'a>(
ctx: &'scope Context<P>,
s: fn(&'a I) -> O,
) -> &'scope ContextGuard<O> {
// ) -> &'scope ContextGuard<O> {
todo!()
}