hot reloading intigration
This commit is contained in:
1 parent
9877dd7ed8
commit
7214130c40
7 files changed
+274
-35
No files matched your search
@@ -9,36 +9,12 @@ use crate::prelude::ServeConfig;
|
||||
pub struct SSRState {
|
||||
// We keep a cache of renderers to avoid re-creating them on every request. They are boxed to make them very cheap to move
|
||||
renderers: Arc<object_pool::Pool<Renderer>>,
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload"))]
|
||||
// The cache of all templates that have been modified since the last time we checked
|
||||
templates: Arc<std::sync::RwLock<std::collections::HashSet<dioxus_core::Template<'static>>>>,
|
||||
}
|
||||
|
||||
impl Default for SSRState {
|
||||
fn default() -> Self {
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload"))]
|
||||
let templates = {
|
||||
let templates = Arc::new(std::sync::RwLock::new(std::collections::HashSet::new()));
|
||||
dioxus_hot_reload::connect({
|
||||
let templates = templates.clone();
|
||||
move |msg| match msg {
|
||||
dioxus_hot_reload::HotReloadMsg::UpdateTemplate(template) => {
|
||||
if let Ok(mut templates) = templates.write() {
|
||||
templates.insert(template);
|
||||
}
|
||||
}
|
||||
dioxus_hot_reload::HotReloadMsg::Shutdown => {
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
templates
|
||||
};
|
||||
|
||||
Self {
|
||||
renderers: Arc::new(object_pool::Pool::new(10, pre_renderer)),
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload"))]
|
||||
templates,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user