wip: comment out examples and move lifetime in FC type
This commit is contained in:
1 parent
07341d2c65
commit
62d4ad5878
12 files changed
+300
-175
No files matched your search
@@ -1,11 +1,64 @@
|
||||
// #![allow(unused, non_upper_case_globals)]
|
||||
// use bumpalo::Bump;
|
||||
// use dioxus_core::nodebuilder::*;
|
||||
// use dioxus_core::{nodes::DomTree, prelude::*};
|
||||
// use std::{collections::HashMap, future::Future, marker::PhantomData};
|
||||
#![allow(unused, non_upper_case_globals)]
|
||||
use bumpalo::Bump;
|
||||
use dioxus_core::prelude::VNode;
|
||||
use dioxus_core::prelude::*;
|
||||
use dioxus_core::{nodebuilder::*, virtual_dom::Properties};
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use std::{collections::HashMap, future::Future, marker::PhantomData};
|
||||
|
||||
fn main() {}
|
||||
|
||||
// struct VC<P, F = fn(Context<P>) -> VNode> {
|
||||
// f: F,
|
||||
// _a: std::marker::PhantomData<(P, F)>, // cell: OnceCell<T>,
|
||||
// // init: Cell<Option<F>>
|
||||
// }
|
||||
// impl<P, F> VC<P, F> {
|
||||
// const fn new(init: F) -> VC<P, F> {
|
||||
// Self {
|
||||
// _a: std::marker::PhantomData {},
|
||||
// f: init,
|
||||
// }
|
||||
// }
|
||||
// fn builder() -> P {
|
||||
// // P::new()
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Build a new functional component
|
||||
// static SomeComp: VC<()> = VC::new(|ctx| {
|
||||
// // This is a component, apparently
|
||||
// // still not useful because we can't have bounds
|
||||
|
||||
// ctx.view(html! {
|
||||
// <div>
|
||||
|
||||
// </div>
|
||||
// })
|
||||
// });
|
||||
|
||||
/*
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
static BILL: Lazy<fn(Context<()>) -> String> = Lazy::new(|| {
|
||||
//
|
||||
|c| "BLAH".to_string()
|
||||
});
|
||||
|
||||
// struct FUNC<F = fn() -> T> {}
|
||||
|
||||
struct SomeBuilder {}
|
||||
|
||||
// struct DummyRenderer {
|
||||
// alloc: Bump,
|
||||
// }
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#![allow(unused, non_upper_case_globals)]
|
||||
#![allow(unused, non_upper_case_globals, non_snake_case)]
|
||||
use bumpalo::Bump;
|
||||
use dioxus_core::prelude::*;
|
||||
use dioxus_core::{nodebuilder::*, virtual_dom::DomTree};
|
||||
use std::{collections::HashMap, future::Future, marker::PhantomData};
|
||||
|
||||
fn main() {}
|
||||
struct Props<'a> {
|
||||
use_macro: bool,
|
||||
|
||||
// todo uh not static
|
||||
// incorporate lifetimes into the thing somehow
|
||||
text: &'a str,
|
||||
// ~~~ Text shared between components via props can be done with lifetimes! ~~~
|
||||
// Super duper efficient :)
|
||||
struct Props {
|
||||
blah: bool,
|
||||
text: String,
|
||||
}
|
||||
|
||||
fn Component(ctx: Context<Props>) -> VNode {
|
||||
fn Component<'a>(ctx: &'a Context<Props>) -> VNode<'a> {
|
||||
// Write asynchronous rendering code that immediately returns a "suspended" VNode
|
||||
// The concurrent API will then progress this component when the future finishes
|
||||
// You can suspend the entire component, or just parts of it
|
||||
@@ -25,30 +25,77 @@ fn Component(ctx: Context<Props>) -> VNode {
|
||||
}
|
||||
});
|
||||
|
||||
ctx.view(html! {
|
||||
<div>
|
||||
// <h1> "Products" </h1>
|
||||
// // Subnodes can even be suspended
|
||||
// // When completely rendered, they won't cause the component itself to re-render, just their slot
|
||||
// <p> { product_list } </p>
|
||||
</div>
|
||||
})
|
||||
}
|
||||
|
||||
fn BuilderComp(ctx: Context<Props>) -> VNode {
|
||||
// VNodes can be constructed via a builder or the html! macro
|
||||
// However, both of these are "lazy" - they need to be evaluated (aka, "viewed")
|
||||
// We can "view" them with Context for ultimate speed while inside components
|
||||
if ctx.props.use_macro {
|
||||
ctx.view(|bump| {
|
||||
div(bump)
|
||||
.attr("class", "edit")
|
||||
.child(text("Hello"))
|
||||
.child(text(ctx.props.text))
|
||||
.finish()
|
||||
})
|
||||
} else {
|
||||
// "View" indicates exactly *when* allocations take place, everything is lazy up to this point
|
||||
ctx.view(html! {
|
||||
<div>
|
||||
// TODO!
|
||||
// Get all this working again
|
||||
// <h1>"Products"</h1>
|
||||
// // Subnodes can even be suspended
|
||||
// // When completely rendered, they won't cause the component itself to re-render, just their slot
|
||||
// <p> {product_list} </p>
|
||||
</div>
|
||||
})
|
||||
}
|
||||
ctx.view(|bump| {
|
||||
div(bump)
|
||||
.attr("class", "edit")
|
||||
.child(text("Hello"))
|
||||
.child(text(ctx.props.text.as_str()))
|
||||
.finish()
|
||||
})
|
||||
}
|
||||
|
||||
#[fc]
|
||||
fn EffcComp(ctx: &Context, name: &str) -> VNode {
|
||||
// VNodes can be constructed via a builder or the html! macro
|
||||
// However, both of these are "lazy" - they need to be evaluated (aka, "viewed")
|
||||
// We can "view" them with Context for ultimate speed while inside components
|
||||
// use "phase" style allocation;
|
||||
/*
|
||||
nodes...
|
||||
text...
|
||||
attrs...
|
||||
<div> // node0
|
||||
<div> </div> // node1
|
||||
{// support some expression} // node 2
|
||||
</div>
|
||||
let node0;
|
||||
let node1;
|
||||
let node2 = evaluate{}.into();
|
||||
let g= |bump| {1};
|
||||
g(bump).into()
|
||||
|
||||
*/
|
||||
|
||||
// should we automatically view the output or leave it?
|
||||
ctx.view(html! {
|
||||
<div>
|
||||
// your template goes here
|
||||
// feel free to directly use "name"
|
||||
</div>
|
||||
})
|
||||
}
|
||||
|
||||
fn FullySuspended(ctx: Context<Props>) -> VNode {
|
||||
ctx.suspend(async {
|
||||
let i: i32 = 0;
|
||||
|
||||
// full suspended works great with just returning VNodes!
|
||||
let tex = match i {
|
||||
1 => html! { <div> </div> },
|
||||
2 => html! { <div> </div> },
|
||||
_ => html! { <div> </div> },
|
||||
};
|
||||
|
||||
if ctx.props.blah {
|
||||
html! { <div> </div> }
|
||||
} else {
|
||||
tex
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// An example of a datafetching service
|
||||
|
||||
Reference in new issue
Block a user