handle rsx!{cx, ...}
This commit is contained in:
1 parent
586e29d815
commit
2a6d9ed075
3 files changed
+15
-5
No files matched your search
@@ -189,8 +189,8 @@ pub fn rsx(s: TokenStream) -> TokenStream {
|
|||||||
use dioxus_rsx_interpreter::captuered_context::CapturedContextBuilder;
|
use dioxus_rsx_interpreter::captuered_context::CapturedContextBuilder;
|
||||||
|
|
||||||
match CapturedContextBuilder::from_call_body(body) {
|
match CapturedContextBuilder::from_call_body(body) {
|
||||||
Ok(captured) => quote::quote! {
|
Ok(captured) => {
|
||||||
{
|
let lazy = quote::quote! {
|
||||||
LazyNodes::new(move |__cx|{
|
LazyNodes::new(move |__cx|{
|
||||||
let captured = #captured;
|
let captured = #captured;
|
||||||
let line_num = get_line_num();
|
let line_num = get_line_num();
|
||||||
@@ -198,9 +198,16 @@ pub fn rsx(s: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
resolve_scope(line_num, text, captured, __cx)
|
resolve_scope(line_num, text, captured, __cx)
|
||||||
})
|
})
|
||||||
|
};
|
||||||
|
if let Some(cx) = captured.custom_context {
|
||||||
|
quote::quote! {
|
||||||
|
#cx.render(#lazy)
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
lazy.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.into(),
|
|
||||||
Err(err) => err.into_compile_error().into(),
|
Err(err) => err.into_compile_error().into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
|
|||||||
syn = { version = "1.0", features = ["extra-traits"] }
|
syn = { version = "1.0", features = ["extra-traits"] }
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = { vesion = "1.0" }
|
serde_json = "1.0"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
|
||||||
dioxus-rsx = { path = "../rsx", default-features = false }
|
dioxus-rsx = { path = "../rsx", default-features = false }
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use dioxus_rsx::{
|
|||||||
};
|
};
|
||||||
use quote::{quote, ToTokens, TokenStreamExt};
|
use quote::{quote, ToTokens, TokenStreamExt};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use syn::{Expr, Result};
|
use syn::{Expr, Ident, Result};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CapturedContextBuilder {
|
pub struct CapturedContextBuilder {
|
||||||
@@ -14,6 +14,7 @@ pub struct CapturedContextBuilder {
|
|||||||
pub iterators: Vec<BodyNode>,
|
pub iterators: Vec<BodyNode>,
|
||||||
pub captured_expressions: Vec<Expr>,
|
pub captured_expressions: Vec<Expr>,
|
||||||
pub listeners: Vec<ElementAttrNamed>,
|
pub listeners: Vec<ElementAttrNamed>,
|
||||||
|
pub custom_context: Option<Ident>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CapturedContextBuilder {
|
impl CapturedContextBuilder {
|
||||||
@@ -28,6 +29,7 @@ impl CapturedContextBuilder {
|
|||||||
|
|
||||||
pub fn from_call_body(body: CallBody) -> Result<Self> {
|
pub fn from_call_body(body: CallBody) -> Result<Self> {
|
||||||
let mut new = Self::default();
|
let mut new = Self::default();
|
||||||
|
new.custom_context = body.custom_context;
|
||||||
for node in body.roots {
|
for node in body.roots {
|
||||||
new.extend(Self::find_captured(node)?);
|
new.extend(Self::find_captured(node)?);
|
||||||
}
|
}
|
||||||
@@ -86,6 +88,7 @@ impl ToTokens for CapturedContextBuilder {
|
|||||||
iterators,
|
iterators,
|
||||||
captured_expressions,
|
captured_expressions,
|
||||||
listeners,
|
listeners,
|
||||||
|
custom_context: _,
|
||||||
} = self;
|
} = self;
|
||||||
let listeners_str = listeners
|
let listeners_str = listeners
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
Reference in new issue
Block a user