fix: readme and examples syntax

This commit is contained in:
Jonathan Kelley committed 2021-12-28 23:48:25 -05:00
1 parent f24aae8787
commit 3dc0e59876
102 files changed
+213 -1222

No files matched your search

-337
View File
@@ -1,337 +0,0 @@
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use syn::{
parse::{Parse, ParseStream},
Signature,
};
use syn::{Attribute, Block, FnArg, Ident, Item, ItemFn, ReturnType, Type, Visibility};
/// A parsed version of the user's input
pub struct FunctionComponent {
// The actual contents of the function
block: Box<Block>,
// // The user's props type
// props_type: Box<Type>,
arg: FnArg,
vis: Visibility,
attrs: Vec<Attribute>,
name: Ident,
return_type: Box<Type>,
}
impl Parse for FunctionComponent {
fn parse(input: ParseStream) -> syn::Result<Self> {
let parsed: Item = input.parse()?;
// Convert the parsed input into the Function block
let ItemFn {
attrs,
vis,
sig,
block,
} = ensure_fn_block(parsed)?;
// Validate the user's signature
let sig = validate_signature(sig)?;
// Validate the return type is actually something
let return_type = ensure_return_type(sig.output)?;
// Get all the function args
let mut inputs = sig.inputs.into_iter();
// Collect the first arg
let first_arg: FnArg = inputs
.next()
.unwrap_or_else(|| syn::parse_quote! { _: &() });
// Extract the "context" object
// let props_type = validate_context_arg(&first_arg)?;
/*
Extract the rest of the function arguments into a struct body
We require all inputs are strongly typed with names so we can destructure into the function body when expanded
*/
// let rest = inputs
// .map(|f| {
// //
// match f {
// FnArg::Typed(pat) => {
// match *pat.pat {
// syn::Pat::Type(asd) => {}
// _ => {}
// };
// //
// }
// FnArg::Receiver(_) => {}
// }
// // let name = f
// let stream = f.into_token_stream();
// (stream)
// })
// .collect::<Vec<_>>();
// Collect the rest of the args into a list of definitions to be used by the inline struct
// Checking after param parsing may make it a little inefficient
// but that's a requirement for better error messages in case of receivers
// `>0` because first one is already consumed.
// if inputs.len() > 0 {
// let params: TokenStream = inputs.map(|it| it.to_token_stream()).collect();
// return Err(syn::Error::new_spanned(
// params,
// "function components can accept at most one parameter for the props",
// ));
// }
let name = sig.ident;
Ok(Self {
// props_type,
block,
arg: first_arg,
vis,
attrs,
name,
return_type,
})
}
}
impl ToTokens for FunctionComponent {
fn to_tokens(&self, tokens: &mut TokenStream) {
// let FunctionComponentName { component_name } = name;
let FunctionComponent {
block,
// props_type,
arg: _,
vis: _,
attrs: _,
name: function_name,
return_type: _,
} = self;
// if function_name == component_name {
// return Err(syn::Error::new_spanned(
// component_name,
// "the component must not have the same name as the function",
// ));
// }
let quoted = quote! {
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[derive(PartialEq)]
pub struct #function_name<'a> {
// and some other attrs
___p: std::marker::PhantomData<&'a ()>
}
impl<'a> FC for #function_name<'a> {
fn render(cx: Context<'_>, props: &#function_name<'a>) -> VNode {
let #function_name {
..
} = props;
#block
}
}
// mod __component_blah {
// use super::*;
// #[derive(PartialEq)]
// pub struct Props<'a> {
// name: &'a str
// }
// pub fn component<'a>(cx: &'a Context<'a, Props>) -> VNode<'a> {
// // Destructure the props into the parent scope
// // todo: handle expansion of lifetimes
// let Props {
// name
// } = cx.props;
// #block
// }
// }
// #[allow(non_snake_case)]
// pub use __component_blah::component as #function_name;
};
quoted.to_tokens(tokens);
// let quoted = quote! {
// #[doc(hidden)]
// #[allow(non_camel_case_types)]
// #vis struct #function_name;
// impl ::yew_functional::FunctionProvider for #function_name {
// type TProps = #props_type;
// fn run(#arg) -> #ret_type {
// #block
// }
// }
// #(#attrs)*
// #vis type #component_name = ::yew_functional::FunctionComponent<#function_name>;
// };
}
}
/// Ensure the user's input is actually a functional component
pub fn ensure_fn_block(item: Item) -> syn::Result<ItemFn> {
match item {
Item::Fn(it) => Ok(it),
Item::Static(it) => {
let syn::ItemStatic {
attrs: _,
vis: _,
static_token: _,
mutability: _,
ident: _,
colon_token: _,
ty,
eq_token: _,
expr: _,
semi_token: _,
} = &it;
match ty.as_ref() {
Type::BareFn(_bare) => {}
// Type::Array(_)
// | Type::Group(_)
// | Type::ImplTrait(_)
// | Type::Infer(_)
// | Type::Macro(_)
// | Type::Never(_)
// | Type::Paren(_)
// | Type::Path(_)
// | Type::Ptr(_)
// | Type::Reference(_)
// | Type::Slice(_)
// | Type::TraitObject(_)
// | Type::Tuple(_)
// | Type::Verbatim(_)
_ => {}
};
// TODO: Add support for static block
// Ensure that the contents of the static block can be extracted to a function
// TODO: @Jon
// Decide if statics should be converted to functions (under the hood) or stay as statics
// They _do_ get promoted, but also have a &'static ref
Err(syn::Error::new_spanned(
it,
"`function_component` attribute not ready for statics",
))
}
other => Err(syn::Error::new_spanned(
other,
"`function_component` attribute can only be applied to functions",
)),
}
}
/// Ensure the user's function actually returns a VNode
pub fn ensure_return_type(output: ReturnType) -> syn::Result<Box<Type>> {
match output {
ReturnType::Default => Err(syn::Error::new_spanned(
output,
"function components must return a `VNode`",
)),
ReturnType::Type(_, ty) => Ok(ty),
}
}
/// Validate the users's input signature for the function component.
/// Returns an error if any of the conditions prove to be wrong;
pub fn validate_signature(sig: Signature) -> syn::Result<Signature> {
if !sig.generics.params.is_empty() {
return Err(syn::Error::new_spanned(
sig.generics,
"function components can't contain generics",
));
}
if sig.asyncness.is_some() {
return Err(syn::Error::new_spanned(
sig.asyncness,
"function components can't be async",
));
}
if sig.constness.is_some() {
return Err(syn::Error::new_spanned(
sig.constness,
"const functions can't be function components",
));
}
if sig.abi.is_some() {
return Err(syn::Error::new_spanned(
sig.abi,
"extern functions can't be function components",
));
}
Ok(sig)
}
// pub fn validate_context_arg(first_arg: &FnArg) -> syn::Result<Box<Type>> {
// if let FnArg::Typed(arg) = first_arg {
// // if let Type::R
// // Input arg is a reference to an &mut Context
// // if let Type::Reference(ty) = &*arg.ty {
// // if ty.lifetime.is_some() {
// // return Err(syn::Error::new_spanned(
// // &ty.lifetime,
// // "reference must not have a lifetime",
// // ));
// // }
// // if ty.mutability.is_some() {
// // return Err(syn::Error::new_spanned(
// // &ty.mutability,
// // "reference must not be mutable",
// // ));
// // }
// // Ok(ty.elem.clone())
// // } else {
// // let msg = format!(
// // "expected a reference to a `Context` object (try: `&mut {}`)",
// // arg.ty.to_token_stream()
// // );
// // return Err(syn::Error::new_spanned(arg.ty.clone(), msg));
// // }
// } else {
// return Err(syn::Error::new_spanned(
// first_arg,
// "function components can't accept a receiver",
// ));
// }
// }
pub fn collect_inline_args() {}
/// The named specified in the macro usage.
pub struct FunctionComponentName {
component_name: Ident,
}
impl Parse for FunctionComponentName {
fn parse(input: ParseStream) -> syn::Result<Self> {
if input.is_empty() {
return Err(input.error("expected identifier for the component"));
}
let component_name = input.parse()?;
Ok(Self { component_name })
}
}
+3 -3
View File
@@ -30,7 +30,7 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token
///
/// ## Complete Reference Guide:
/// ```
/// const Example: Component<()> = |cx, props|{
/// const Example: Component = |cx| {
/// let formatting = "formatting!";
/// let formatting_tuple = ("a", "b");
/// let lazy_fmt = format_args!("lazily formatted text");
@@ -161,7 +161,7 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token
/// pub struct BallerProps {}
///
/// /// This component totally balls
/// pub fn Baller(cx: Context<()>) -> DomTree {
/// pub fn Baller(cx: Scope<()>) -> DomTree {
/// todo!()
/// }
/// }
@@ -172,7 +172,7 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token
/// }
///
/// /// This component is taller than most :)
/// pub fn Taller(cx: Context<TallerProps>) -> DomTree {
/// pub fn Taller(cx: Scope<TallerProps>) -> DomTree {
/// let b = true;
/// todo!()
/// }
+1 -1
View File
@@ -72,7 +72,7 @@ impl ToTokens for RsxTemplate {
// // create a lazy tree that accepts a bump allocator
// let final_tokens = quote! {
// dioxus::prelude::LazyNodes::new(move |cx, props|{
// dioxus::prelude::LazyNodes::new(move |cx| {
// let bump = &cx.bump();
// #new_toks
+1 -1
View File
@@ -23,7 +23,7 @@ criterion_group!(mbenches, create_rows);
criterion_main!(mbenches);
fn create_rows(c: &mut Criterion) {
static App: Component<()> = |cx| {
static App: Component = |cx| {
let mut rng = SmallRng::from_entropy();
let rows = (0..10_000_usize).map(|f| {
let label = Label::new(&mut rng);
+1 -1
View File
@@ -20,7 +20,7 @@ use dioxus_html as dioxus_elements;
use rand::prelude::*;
fn main() {
static App: Component<()> = |cx| {
static App: Component = |cx| {
let mut rng = SmallRng::from_entropy();
let rows = (0..10_000_usize).map(|f| {
let label = Label::new(&mut rng);
+6 -6
View File
@@ -467,7 +467,7 @@ impl ScopeState {
/// # Example
///
/// ```rust, ignore
/// let mut dom = VirtualDom::new(|cx, props|cx.render(rsx!{ div {} }));
/// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} }));
/// dom.rebuild();
///
/// let base = dom.base_scope();
@@ -511,7 +511,7 @@ impl ScopeState {
/// # Example
///
/// ```rust, ignore
/// let mut dom = VirtualDom::new(|cx, props| cx.render(rsx!{ div {} }));
/// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} }));
/// dom.rebuild();
///
/// let base = dom.base_scope();
@@ -531,7 +531,7 @@ impl ScopeState {
/// # Example
///
/// ```rust, ignore
/// let mut dom = VirtualDom::new(|cx, props| cx.render(rsx!{ div {} }));
/// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} }));
/// dom.rebuild();
///
/// let base = dom.base_scope();
@@ -550,7 +550,7 @@ impl ScopeState {
/// # Example
///
/// ```rust, ignore
/// let mut dom = VirtualDom::new(|cx, props| cx.render(rsx!{ div {} }));
/// let mut dom = VirtualDom::new(|cx| cx.render(rsx!{ div {} }));
/// dom.rebuild();
/// let base = dom.base_scope();
///
@@ -619,12 +619,12 @@ impl ScopeState {
/// ```rust, ignore
/// struct SharedState(&'static str);
///
/// static App: Component<()> = |cx, props|{
/// static App: Component = |cx| {
/// cx.use_hook(|_| cx.provide_context(SharedState("world")), |_| {}, |_| {});
/// rsx!(cx, Child {})
/// }
///
/// static Child: Component<()> = |cx| {
/// static Child: Component = |cx| {
/// let state = cx.consume_state::<SharedState>();
/// rsx!(cx, div { "hello {state.0}" })
/// }
+3 -3
View File
@@ -135,7 +135,7 @@ impl VirtualDom {
/// ```
///
/// Note: the VirtualDom is not progressed, you must either "run_with_deadline" or use "rebuild" to progress it.
pub fn new(root: Component<()>) -> Self {
pub fn new(root: Component) -> Self {
Self::new_with_props(root, ())
}
@@ -468,7 +468,7 @@ impl VirtualDom {
///
/// # Example
/// ```rust, ignore
/// static App: Component<()> = |cx, props| cx.render(rsx!{ "hello world" });
/// static App: Component = |cx| cx.render(rsx!{ "hello world" });
/// let mut dom = VirtualDom::new();
/// let edits = dom.rebuild();
///
@@ -505,7 +505,7 @@ impl VirtualDom {
/// value: Shared<&'static str>,
/// }
///
/// static App: Component<AppProps> = |cx, props|{
/// static App: Component<AppProps> = |cx| {
/// let val = cx.value.borrow();
/// cx.render(rsx! { div { "{val}" } })
/// };
+1 -1
View File
@@ -24,7 +24,7 @@ fn new_dom<P: 'static + Send>(app: Component<P>, props: P) -> VirtualDom {
/// In debug, this should also toss a warning.
#[test]
fn test_early_abort() {
const app: Component<()> = |cx| {
const app: Component = |cx| {
let val = cx.use_hook(|_| 0, |f| f);
*val += 1;
+8 -8
View File
@@ -45,7 +45,7 @@ fn manual_diffing() {
#[test]
fn events_generate() {
static App: Component<()> = |cx| {
static App: Component = |cx| {
let count = cx.use_hook(|_| 0, |f| f);
let inner = match *count {
@@ -104,7 +104,7 @@ fn events_generate() {
#[test]
fn components_generate() {
static App: Component<()> = |cx| {
static App: Component = |cx| {
let render_phase = cx.use_hook(|_| 0, |f| f);
*render_phase += 1;
@@ -121,7 +121,7 @@ fn components_generate() {
})
};
static Child: Component<()> = |cx| {
static Child: Component = |cx| {
cx.render(rsx! {
h1 {}
})
@@ -220,7 +220,7 @@ fn components_generate() {
#[test]
fn component_swap() {
static App: Component<()> = |cx| {
static App: Component = |cx| {
let render_phase = cx.use_hook(|_| 0, |f| f);
*render_phase += 1;
@@ -259,7 +259,7 @@ fn component_swap() {
})
};
static NavBar: Component<()> = |cx| {
static NavBar: Component = |cx| {
println!("running navbar");
cx.render(rsx! {
h1 {
@@ -269,7 +269,7 @@ fn component_swap() {
})
};
static NavLink: Component<()> = |cx| {
static NavLink: Component = |cx| {
println!("running navlink");
cx.render(rsx! {
h1 {
@@ -278,7 +278,7 @@ fn component_swap() {
})
};
static Dashboard: Component<()> = |cx| {
static Dashboard: Component = |cx| {
println!("running dashboard");
cx.render(rsx! {
div {
@@ -287,7 +287,7 @@ fn component_swap() {
})
};
static Results: Component<()> = |cx| {
static Results: Component = |cx| {
println!("running results");
cx.render(rsx! {
div {
+2 -2
View File
@@ -13,12 +13,12 @@ mod test_logging;
fn shared_state_test() {
struct MySharedState(&'static str);
static App: Component<()> = |cx| {
static App: Component = |cx| {
cx.provide_context(MySharedState("world!"));
cx.render(rsx!(Child {}))
};
static Child: Component<()> = |cx| {
static Child: Component = |cx| {
let shared = cx.consume_context::<MySharedState>()?;
cx.render(rsx!("Hello, {shared.0}"))
};
+6 -6
View File
@@ -19,7 +19,7 @@ use DomEdit::*;
#[test]
fn app_runs() {
static App: Component<()> = |cx| rsx!(cx, div{"hello"} );
static App: Component = |cx| rsx!(cx, div{"hello"} );
let mut vdom = VirtualDom::new(App);
let edits = vdom.rebuild();
@@ -27,7 +27,7 @@ fn app_runs() {
#[test]
fn fragments_work() {
static App: Component<()> = |cx| {
static App: Component = |cx| {
cx.render(rsx!(
div{"hello"}
div{"goodbye"}
@@ -41,7 +41,7 @@ fn fragments_work() {
#[test]
fn lists_work() {
static App: Component<()> = |cx| {
static App: Component = |cx| {
cx.render(rsx!(
h1 {"hello"}
{(0..6).map(|f| rsx!(span{ "{f}" }))}
@@ -54,7 +54,7 @@ fn lists_work() {
#[test]
fn conditional_rendering() {
static App: Component<()> = |cx| {
static App: Component = |cx| {
cx.render(rsx!(
h1 {"hello"}
{true.then(|| rsx!(span{ "a" }))}
@@ -87,13 +87,13 @@ fn conditional_rendering() {
#[test]
fn child_components() {
static App: Component<()> = |cx| {
static App: Component = |cx| {
cx.render(rsx!(
{true.then(|| rsx!(Child { }))}
{false.then(|| rsx!(Child { }))}
))
};
static Child: Component<()> = |cx| {
static Child: Component = |cx| {
cx.render(rsx!(
h1 {"hello"}
h1 {"goodbye"}
-11
View File
@@ -1,11 +0,0 @@
[package]
name = "dioxus-coroutines"
version = "0.0.0"
edition = "2018"
repository = "https://github.com/DioxusLabs/dioxus/"
homepage = "https://dioxuslabs.com"
documentation = "https://dioxuslabs.com"
keywords = ["dom", "ui", "gui", "react", "wasm"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-8
View File
@@ -1,8 +0,0 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
+7 -7
View File
@@ -7,7 +7,7 @@ fn main() {
dioxus::desktop::launch(App)
}
static App: Component<()> = |cx| {
static App: Component = |cx| {
let (count, set_count) = use_state(&cx, || 0);
cx.render(rsx!(
@@ -34,7 +34,7 @@ Window management, system trays, notifications, and other desktop-related functi
Managing windows is done by simply rendering content into a `WebviewWindow` component.
```rust
static App: Component<()> = |cx| {
static App: Component = |cx| {
rsx!(cx, WebviewWindow { "hello world" } )
}
```
@@ -46,7 +46,7 @@ Notifications also use a declarative approach. Sending a notification has never
The api has been somewhat modeled after https://github.com/mikaelbr/node-notifier
```rust
static Notifications: Component<()> = |cx| {
static Notifications: Component = |cx| {
cx.render(rsx!(
Notification {
title: "title"
@@ -78,7 +78,7 @@ static Notifications: Component<()> = |cx| {
Dioxus Desktop supports app trays, which can be built with native menu groups or with a custom window.
```rust
static Tray: Component<()> = |cx| {
static Tray: Component = |cx| {
cx.render(rsx!(
GlobalTray {
MenuGroup {
@@ -90,7 +90,7 @@ static Tray: Component<()> = |cx| {
};
// using a builder
static Tray: Component<()> = |cx| {
static Tray: Component = |cx| {
let menu = MenuGroup::builder(cx)
.with_items([
MenuGroupItem::builder()
@@ -107,7 +107,7 @@ static Tray: Component<()> = |cx| {
}
// or with a custom window
static Tray: Component<()> = |cx| {
static Tray: Component = |cx| {
rsx!(cx, GlobalTray { div { "custom buttons here" } })
};
```
@@ -116,7 +116,7 @@ static Tray: Component<()> = |cx| {
Declaring menus is convenient and cross-platform.
```rust
static Menu: Component<()> = |cx| {
static Menu: Component = |cx| {
cx.render(rsx!(
MenuBarMajorItem { title: "File"
MenuGroup {
+3 -3
View File
@@ -56,7 +56,7 @@ pub struct WebviewWindowProps<'a> {
///
///
///
pub fn WebviewWindow(cx: Context, props: &WebviewWindowProps) -> Element {
pub fn WebviewWindow(cx: Scope<WebviewWindowProps>) -> Element {
let dtcx = cx.consume_state::<RefCell<DesktopContext>>()?;
cx.use_hook(
@@ -78,7 +78,7 @@ pub fn WebviewWindow(cx: Context, props: &WebviewWindowProps) -> Element {
pub struct WindowHandle {}
/// Get a handle to the current window from inside a component
pub fn use_current_window(cx: Context) -> Option<WindowHandle> {
pub fn use_current_window(cx: Scope) -> Option<WindowHandle> {
todo!()
}
@@ -90,7 +90,7 @@ fn syntax_works() {
use dioxus_hooks::*;
use dioxus_html as dioxus_elements;
static App: Component<()> = |cx| {
static App: Component = |cx| {
cx.render(rsx! {
// left window
WebviewWindow {
+2 -2
View File
@@ -28,11 +28,11 @@ use wry::{
webview::{WebView, WebViewBuilder},
};
pub fn launch(root: Component<()>) {
pub fn launch(root: Component) {
launch_with_props(root, (), |c| c)
}
pub fn launch_cfg(
root: Component<()>,
root: Component,
config_builder: impl for<'a, 'b> FnOnce(&'b mut DesktopConfig<'a>) -> &'b mut DesktopConfig<'a>,
) {
launch_with_props(root, (), config_builder)
+1 -1
View File
@@ -36,7 +36,7 @@ uses the same memoization on top of the use_context API.
Here's a fully-functional todo app using the use_map API:
```rust
static TodoList: Component<()> = |cx, props|{
static TodoList: Component = |cx| {
let todos = use_map(cx, || HashMap::new());
let input = use_ref(|| None);
+1 -1
View File
@@ -46,7 +46,7 @@ impl<'a, P, T> UseStateA<'a, T> for Scope<'a, P> {
/// Usage:
///
/// ```ignore
/// const Example: Component<()> = |cx| {
/// const Example: Component = |cx| {
/// let counter = use_state(&cx, || 0);
///
/// cx.render(rsx! {
+1 -1
View File
@@ -39,7 +39,7 @@ async fn order_shoes(mut req: WebsocketRequest) -> Response {
dioxus::liveview::launch(App, stream).await;
}
fn App(cx: Context, props: &()) -> Element {
fn App(cx: Scope<()>) -> Element {
let mut count = use_state(&cx, || 0);
cx.render(rsx!(
button { onclick: move |_| count += 1, "Incr" }
+1 -4
View File
@@ -26,10 +26,7 @@ fn init_logging() {
static HTML_CONTENT: &'static str = include_str!("../../desktop/src/index.html");
pub fn launch(
root: Component<()>,
builder: fn(WindowBuilder) -> WindowBuilder,
) -> anyhow::Result<()> {
pub fn launch(root: Component, builder: fn(WindowBuilder) -> WindowBuilder) -> anyhow::Result<()> {
launch_with_props(root, (), builder)
}
pub fn launch_with_props<P: 'static + Send>(
+2 -2
View File
@@ -16,7 +16,7 @@ enum AppRoute {
NotFound
}
static App: Component<()> = |cx| {
static App: Component = |cx| {
let route = use_router(cx, AppRoute::parse);
match route {
@@ -30,7 +30,7 @@ static App: Component<()> = |cx| {
Adding links into your app:
```rust
static Leaf: Component<()> = |cx| {
static Leaf: Component = |cx| {
rsx!(cx, div {
Link { to: AppRoute::Home }
})
+1 -1
View File
@@ -10,7 +10,7 @@ fn main() {
dioxus_web::launch(APP);
}
static APP: Component<()> = |cx| {
static APP: Component = |cx| {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
enum Route {
Home,
+1 -1
View File
@@ -5,7 +5,7 @@ Render a Dioxus VirtualDOM to a string.
```rust
// Our app:
const App: Component<()> = |cx, props| rsx!(cx, div {"hello world!"});
const App: Component = |cx| rsx!(cx, div {"hello world!"});
// Build the virtualdom from our app
let mut vdom = VirtualDOM::new(App);
+9 -9
View File
@@ -31,7 +31,7 @@ impl SsrRenderer {
}
}
pub fn render_lazy<'a>(&'a mut self, f: Option<LazyNodes<'a, '_>>) -> String {
pub fn render_lazy<'a>(&'a mut self, f: LazyNodes<'a, '_>) -> String {
let bump = &mut self.inner as *mut _;
let s = self.render_inner(f);
// reuse the bump's memory
@@ -39,7 +39,7 @@ impl SsrRenderer {
s
}
fn render_inner<'a>(&'a self, f: Option<LazyNodes<'a, '_>>) -> String {
fn render_inner<'a>(&'a self, f: LazyNodes<'a, '_>) -> String {
let factory = NodeFactory::new(&self.inner);
let root = f.into_vnode(factory);
format!(
@@ -53,7 +53,7 @@ impl SsrRenderer {
}
}
pub fn render_lazy<'a>(f: Option<LazyNodes<'a, '_>>) -> String {
pub fn render_lazy<'a>(f: LazyNodes<'a, '_>) -> String {
let bump = bumpalo::Bump::new();
let borrowed = &bump;
@@ -113,7 +113,7 @@ pub fn render_vdom_scope(vdom: &VirtualDom, scope: ScopeId) -> Option<String> {
///
/// ## Example
/// ```ignore
/// static App: Component<()> = |cx, props|cx.render(rsx!(div { "hello world" }));
/// static App: Component = |cx| cx.render(rsx!(div { "hello world" }));
/// let mut vdom = VirtualDom::new(App);
/// vdom.rebuild();
///
@@ -301,13 +301,13 @@ mod tests {
use dioxus_core_macro::*;
use dioxus_html as dioxus_elements;
static SIMPLE_APP: Component<()> = |cx| {
static SIMPLE_APP: Component = |cx| {
cx.render(rsx!(div {
"hello world!"
}))
};
static SLIGHTLY_MORE_COMPLEX: Component<()> = |cx| {
static SLIGHTLY_MORE_COMPLEX: Component = |cx| {
cx.render(rsx! {
div {
title: "About W3Schools"
@@ -326,14 +326,14 @@ mod tests {
})
};
static NESTED_APP: Component<()> = |cx| {
static NESTED_APP: Component = |cx| {
cx.render(rsx!(
div {
SIMPLE_APP {}
}
))
};
static FRAGMENT_APP: Component<()> = |cx| {
static FRAGMENT_APP: Component = |cx| {
cx.render(rsx!(
div { "f1" }
div { "f2" }
@@ -389,7 +389,7 @@ mod tests {
#[test]
fn styles() {
static STLYE_APP: Component<()> = |cx| {
static STLYE_APP: Component = |cx| {
cx.render(rsx! {
div { color: "blue", font_size: "46px" }
})
+1 -1
View File
@@ -14,7 +14,7 @@ fn main() {
dioxus_web::launch(App);
}
static App: Component<()> = |cx| {
static App: Component = |cx| {
let mut count = use_state(&cx, || 0);
cx.push_future(|| async move {
+1 -22
View File
@@ -106,7 +106,7 @@ impl Label {
}
}
static App: Component<()> = |cx| {
static App: Component = |cx| {
let mut items = use_ref(&cx, || vec![]);
let mut selected = use_state(&cx, || None);
@@ -219,24 +219,3 @@ static NOUNS: &[&str] = &[
"table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger",
"pizza", "mouse", "keyboard",
];
// #[derive(PartialEq, Props)]
// struct RowProps<'a> {
// row_id: usize,
// label: &'a Label,
// }
// fn Row(cx: Context, props: &RowProps) -> Element {
// rsx!(cx, tr {
// td { class:"col-md-1", "{cx.props.row_id}" }
// td { class:"col-md-1", onclick: move |_| { /* run onselect */ }
// a { class: "lbl", {cx.props.label.labels} }
// }
// td { class: "col-md-1"
// a { class: "remove", onclick: move |_| {/* remove */}
// span { class: "glyphicon glyphicon-remove remove" aria_hidden: "true" }
// }
// }
// td { class: "col-md-6" }
// })
// }
+1 -1
View File
@@ -13,7 +13,7 @@ fn main() {
dioxus_web::launch(App);
}
static App: Component<()> = |cx| {
static App: Component = |cx| {
let show = use_state(&cx, || true);
let inner = match *show {
+1 -1
View File
@@ -14,7 +14,7 @@ fn main() {
dioxus_web::launch(App);
}
static App: Component<()> = |cx| {
static App: Component = |cx| {
todo!("suspense is broken")
// let doggo = suspend(|| async move {
// #[derive(serde::Deserialize)]
+2 -2
View File
@@ -84,11 +84,11 @@ mod ric_raf;
/// dioxus_web::launch(App);
/// }
///
/// static App: Component<()> = |cx| {
/// static App: Component = |cx| {
/// rsx!(cx, div {"hello world"})
/// }
/// ```
pub fn launch(root_component: Component<()>) {
pub fn launch(root_component: Component) {
launch_with_props(root_component, (), |c| c);
}