It compiles
This commit is contained in:
1 parent
f8143a5fc1
commit
871f51f91b
6 files changed
+33
-16
No files matched your search
@@ -191,15 +191,20 @@ pub fn rsx(s: TokenStream) -> TokenStream {
|
|||||||
quote! {
|
quote! {
|
||||||
{
|
{
|
||||||
let line_num = get_line_num();
|
let line_num = get_line_num();
|
||||||
LazyNodes::new(|factory|{
|
LazyNodes::new(move |factory|{
|
||||||
let rsx_text_index: RsxTextIndex = cx.consume_context().unwrap();
|
let rsx_text_index: RsxTextIndex = cx.consume_context().unwrap();
|
||||||
let read = rsx_text_index.read();
|
let read = rsx_text_index.read();
|
||||||
let text = read.get(line_num).unwrap();
|
if let Some(text) = read.get(line_num){
|
||||||
interpert_rsx(
|
interpert_rsx(
|
||||||
factory,
|
factory,
|
||||||
&text,
|
&text,
|
||||||
#captured
|
#captured
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
println!("rsx: line number {} not found", line_num);
|
||||||
|
factory.static_text("")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,4 +48,4 @@ backtrace = "0.3"
|
|||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
serialize = ["serde"]
|
serialize = ["serde"]
|
||||||
debug_vdom = []
|
debug_vdom = []
|
||||||
@@ -10,3 +10,4 @@ dioxus-rsx = { path = "../rsx" }
|
|||||||
dioxus-ssr = { path = "../ssr" }
|
dioxus-ssr = { path = "../ssr" }
|
||||||
dioxus-core = { path = "../core" }
|
dioxus-core = { path = "../core" }
|
||||||
dioxus-html = { path = "../html" }
|
dioxus-html = { path = "../html" }
|
||||||
|
dioxus-hooks = { path = "../hooks"}
|
||||||
@@ -17,6 +17,7 @@ impl CapturedContextBuilder {
|
|||||||
self.attributes.extend(other.attributes);
|
self.attributes.extend(other.attributes);
|
||||||
self.text.extend(other.text);
|
self.text.extend(other.text);
|
||||||
self.components.extend(other.components);
|
self.components.extend(other.components);
|
||||||
|
self.iterators.extend(other.iterators);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_call_body(body: CallBody) -> Self {
|
pub fn from_call_body(body: CallBody) -> Self {
|
||||||
@@ -84,12 +85,12 @@ impl ToTokens for CapturedContextBuilder {
|
|||||||
.chain(text.iter().map(|fmt| fmt.named_args.iter()))
|
.chain(text.iter().map(|fmt| fmt.named_args.iter()))
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect();
|
.collect();
|
||||||
let captured_names = captured.iter().map(|(n, _)| n);
|
let captured_names = captured.iter().map(|(n, _)| n.to_string());
|
||||||
let captured_expr = captured.iter().map(|(_, e)| e);
|
let captured_expr = captured.iter().map(|(_, e)| e);
|
||||||
tokens.append_all(quote! {
|
tokens.append_all(quote! {
|
||||||
CapturedContext {
|
CapturedContext {
|
||||||
captured: IfmtArgs{
|
captured: IfmtArgs{
|
||||||
named_args: &[#((#captured_names, #captured_expr)),*]
|
named_args: vec![#((#captured_names, #captured_expr.to_string())),*]
|
||||||
},
|
},
|
||||||
components: vec![#(#components),*],
|
components: vec![#(#components),*],
|
||||||
iterators: vec![#(#iterators),*],
|
iterators: vec![#(#iterators),*],
|
||||||
@@ -114,7 +115,7 @@ pub struct CapturedContext<'a> {
|
|||||||
|
|
||||||
pub struct IfmtArgs {
|
pub struct IfmtArgs {
|
||||||
// live reload only supports named arguments
|
// live reload only supports named arguments
|
||||||
pub named_args: &'static [(&'static str, String)],
|
pub named_args: Vec<(&'static str, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum IfmtSegment<'a> {
|
enum IfmtSegment<'a> {
|
||||||
|
|||||||
@@ -1,17 +1,27 @@
|
|||||||
use crate::interperter::build;
|
use dioxus_core::{Component, Element, LazyNodes, Scope, VNode};
|
||||||
use dioxus_core::{LazyNodes, VNode};
|
use dioxus_hooks::*;
|
||||||
use dioxus_rsx::CallBody;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::panic::Location;
|
use std::panic::Location;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::{RwLock, RwLockReadGuard};
|
use std::sync::{RwLock, RwLockReadGuard};
|
||||||
use syn::{parse_str, Result};
|
use syn::parse_str;
|
||||||
|
|
||||||
mod attributes;
|
mod attributes;
|
||||||
pub mod captuered_context;
|
pub mod captuered_context;
|
||||||
mod elements;
|
mod elements;
|
||||||
mod interperter;
|
mod interperter;
|
||||||
|
|
||||||
|
pub fn with_hot_reload(cx: Scope<Component>) -> Element {
|
||||||
|
use_state(&cx, || {
|
||||||
|
if cx.consume_context::<RsxTextIndex>().is_none() {
|
||||||
|
cx.provide_context(RsxTextIndex::default());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
cx.render(LazyNodes::new(|node_factory| {
|
||||||
|
node_factory.component(*cx.props, (), None, "app")
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn interpert_rsx<'a, 'b>(
|
pub fn interpert_rsx<'a, 'b>(
|
||||||
factory: dioxus_core::NodeFactory<'a>,
|
factory: dioxus_core::NodeFactory<'a>,
|
||||||
text: &str,
|
text: &str,
|
||||||
|
|||||||
+1
-1
@@ -57,6 +57,6 @@ pub mod prelude {
|
|||||||
#[cfg(feature = "hot_reload")]
|
#[cfg(feature = "hot_reload")]
|
||||||
pub use dioxus_rsx_interperter::{
|
pub use dioxus_rsx_interperter::{
|
||||||
captuered_context::{CapturedContext, IfmtArgs},
|
captuered_context::{CapturedContext, IfmtArgs},
|
||||||
get_line_num, interpert_rsx, RsxTextIndex,
|
get_line_num, interpert_rsx, with_hot_reload, RsxTextIndex,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user