Feat: include the helper
This commit is contained in:
1 parent
f2eec79fd4
commit
07341d2c65
22 files changed
+2990
-1311
No files matched your search
@@ -20,3 +20,76 @@ fn main() {
|
||||
fn example(ctx: &Context, name: String) -> VNode {
|
||||
html! { <div> "Hello, {name}!" </div> }
|
||||
}
|
||||
|
||||
/*
|
||||
TODO
|
||||
|
||||
/// The macro can also be applied to statics in order to make components less verbose
|
||||
/// The FC type automatically adds the inference, and property fields are automatically added as function arguments
|
||||
#[fc]
|
||||
static Example: FC = |ctx, name: String| {
|
||||
html! { <div> "Hello, {name}!" </div> }
|
||||
};
|
||||
*/
|
||||
|
||||
// This trait is not exposed to users directly, though they could manually implement this for struct-style components
|
||||
trait Comp {
|
||||
type Props: Properties;
|
||||
fn render(&self, ctx: &mut Context<Self::Props>) -> VNode;
|
||||
fn builder(&self) -> Self::Props;
|
||||
}
|
||||
trait Properties {
|
||||
fn new() -> Self;
|
||||
}
|
||||
|
||||
impl<T: Properties> Comp for FC<T> {
|
||||
type Props = T;
|
||||
|
||||
fn render(&self, ctx: &mut Context<T>) -> VNode {
|
||||
let g = self(ctx);
|
||||
g
|
||||
}
|
||||
|
||||
fn builder(&self) -> T {
|
||||
T::new()
|
||||
}
|
||||
}
|
||||
|
||||
// impl<T: Properties, F: Fn(&Context<T>) -> VNode> Comp for F {
|
||||
// type Props = T;
|
||||
|
||||
// fn render(&self, ctx: &mut Context<T>) -> VNode {
|
||||
// let g = self(ctx);
|
||||
// g
|
||||
// }
|
||||
|
||||
// fn builder(&self) -> T {
|
||||
// T::new()
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Properties for () {
|
||||
fn new() -> Self {
|
||||
()
|
||||
}
|
||||
}
|
||||
#[allow(unused, non_upper_case_globals)]
|
||||
static MyComp: FC<()> = |ctx| {
|
||||
html! {
|
||||
<div>
|
||||
</div>
|
||||
}
|
||||
};
|
||||
|
||||
fn my_comp(ctx: &Context<()>) -> VNode {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn test() {
|
||||
let mut ctx = Context { props: &() };
|
||||
let f = MyComp.render(&mut ctx);
|
||||
let props = MyComp.builder();
|
||||
|
||||
// let f = my_comp.render(&mut ctx);
|
||||
// let props = my_comp.builder();
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
//! thousands of simultaneous clients on minimal hardware.
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_ssr::TextRenderer;
|
||||
use rand::Rng;
|
||||
use tide::{Request, Response};
|
||||
|
||||
@@ -50,20 +51,17 @@ async fn fibsum(req: Request<()>) -> tide::Result<tide::Response> {
|
||||
// Generate another random number to try
|
||||
let other_fib_to_try = rand::thread_rng().gen_range(1..42);
|
||||
|
||||
let g = html! {
|
||||
<div>
|
||||
</div>
|
||||
};
|
||||
|
||||
let nodes = html! {
|
||||
let text = TextRenderer::<()>::to_text(html! {
|
||||
<html>
|
||||
|
||||
// Header
|
||||
<head>
|
||||
<meta content="text/html;charset=utf-8" />
|
||||
<meta charset="UTF-8" />
|
||||
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
// Body
|
||||
<body>
|
||||
<div class="flex items-center justify-center flex-col">
|
||||
<div class="flex items-center justify-center">
|
||||
@@ -97,11 +95,10 @@ async fn fibsum(req: Request<()>) -> tide::Result<tide::Response> {
|
||||
</body>
|
||||
|
||||
</html>
|
||||
};
|
||||
});
|
||||
|
||||
Ok(Response::builder(203)
|
||||
.body(nodes.to_string())
|
||||
.header("custom-header", "value")
|
||||
.body(text)
|
||||
.content_type(tide::http::mime::HTML)
|
||||
.build())
|
||||
}
|
||||
Reference in new issue
Block a user