It compiles

This commit is contained in:
Evan Almloff committed 2022-05-25 14:08:59 -05:00
1 parent f8143a5fc1
commit 871f51f91b
6 files changed
+33 -16

No files matched your search

+12 -7
View File
@@ -191,15 +191,20 @@ pub fn rsx(s: TokenStream) -> TokenStream {
quote! {
{
let line_num = get_line_num();
LazyNodes::new(|factory|{
LazyNodes::new(move |factory|{
let rsx_text_index: RsxTextIndex = cx.consume_context().unwrap();
let read = rsx_text_index.read();
let text = read.get(line_num).unwrap();
interpert_rsx(
factory,
&text,
#captured
)
if let Some(text) = read.get(line_num){
interpert_rsx(
factory,
&text,
#captured
)
}
else{
println!("rsx: line number {} not found", line_num);
factory.static_text("")
}
})
}
}
+1 -1
View File
@@ -48,4 +48,4 @@ backtrace = "0.3"
[features]
default = []
serialize = ["serde"]
debug_vdom = []
debug_vdom = []
+1
View File
@@ -10,3 +10,4 @@ dioxus-rsx = { path = "../rsx" }
dioxus-ssr = { path = "../ssr" }
dioxus-core = { path = "../core" }
dioxus-html = { path = "../html" }
dioxus-hooks = { path = "../hooks"}
@@ -17,6 +17,7 @@ impl CapturedContextBuilder {
self.attributes.extend(other.attributes);
self.text.extend(other.text);
self.components.extend(other.components);
self.iterators.extend(other.iterators);
}
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()))
.flatten()
.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);
tokens.append_all(quote! {
CapturedContext {
captured: IfmtArgs{
named_args: &[#((#captured_names, #captured_expr)),*]
named_args: vec![#((#captured_names, #captured_expr.to_string())),*]
},
components: vec![#(#components),*],
iterators: vec![#(#iterators),*],
@@ -114,7 +115,7 @@ pub struct CapturedContext<'a> {
pub struct IfmtArgs {
// live reload only supports named arguments
pub named_args: &'static [(&'static str, String)],
pub named_args: Vec<(&'static str, String)>,
}
enum IfmtSegment<'a> {
+14 -4
View File
@@ -1,17 +1,27 @@
use crate::interperter::build;
use dioxus_core::{LazyNodes, VNode};
use dioxus_rsx::CallBody;
use dioxus_core::{Component, Element, LazyNodes, Scope, VNode};
use dioxus_hooks::*;
use std::collections::HashMap;
use std::panic::Location;
use std::rc::Rc;
use std::sync::{RwLock, RwLockReadGuard};
use syn::{parse_str, Result};
use syn::parse_str;
mod attributes;
pub mod captuered_context;
mod elements;
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>(
factory: dioxus_core::NodeFactory<'a>,
text: &str,
+1 -1
View File
@@ -57,6 +57,6 @@ pub mod prelude {
#[cfg(feature = "hot_reload")]
pub use dioxus_rsx_interperter::{
captuered_context::{CapturedContext, IfmtArgs},
get_line_num, interpert_rsx, RsxTextIndex,
get_line_num, interpert_rsx, with_hot_reload, RsxTextIndex,
};
}