update to work with templates

This commit is contained in:
Evan Almloff committed 2022-08-26 16:28:46 -05:00
1 parent bc1a81b84b
commit 7b9a321356
6 files changed
+110 -307

No files matched your search

+25 -9
View File
@@ -8,7 +8,8 @@ use axum::{
};
use cargo_metadata::diagnostic::Diagnostic;
use colored::Colorize;
use dioxus_rsx_interpreter::SetRsxMessage;
use dioxus_core::{prelude::TemplateId, SetTemplateMsg};
use dioxus_rsx::try_parse_template;
use notify::{RecommendedWatcher, Watcher};
use syn::spanned::Spanned;
@@ -155,10 +156,25 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
}
}
let rsx = lines.join("\n");
messages.push(SetRsxMessage {
location: hr,
new_text: rsx,
});
let old_dyn_ctx = try_parse_template(
&format!("{}", old.tokens),
hr.to_owned(),
None,
)
.map(|(_, old_dyn_ctx)| old_dyn_ctx);
if let Ok((template, _)) = try_parse_template(
&rsx,
hr.to_owned(),
old_dyn_ctx.ok(),
) {
messages.push(SetTemplateMsg(
TemplateId(hr),
template,
));
} else {
needs_rebuild = true;
}
}
}
}
@@ -187,8 +203,8 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
}
}
}
if !messages.is_empty() {
let _ = hot_reload_tx.send(SetManyRsxMessage(messages));
for msg in messages {
let _ = hot_reload_tx.send(msg);
}
}
last_update_time = chrono::Local::now().timestamp();
@@ -428,8 +444,8 @@ fn print_console_info(port: u16, config: &CrateConfig, options: PrettierOptions)
"clear"
})
.output()
.unwrap()
.stdout
.map(|output| output.stdout)
.unwrap_or_default()
)
);