wip: start to refactor out hot reloading from packages

Also implement alternative simpler template system
This commit is contained in:
Jonathan Kelley committed 2022-10-20 09:56:09 -07:00
1 parent 3b7b503333
commit 90982e0ccb
44 files changed
+3865 -5133

No files matched your search

+3 -46
View File
@@ -34,13 +34,9 @@ impl<'a> Iterator for ElementIdIterator<'a> {
if let Some((count, node)) = self.stack.last_mut() {
match node {
// We can only exit our looping when we get "real" nodes
VNode::Element(_)
| VNode::Text(_)
| VNode::Placeholder(_)
| VNode::TemplateRef(_) => {
VNode::Element(_) | VNode::Text(_) | VNode::Placeholder(_) => {
// We've recursed INTO an element/text
// We need to recurse *out* of it and move forward to the next
// println!("Found element! Returning it!");
should_pop = true;
returned_node = Some(&**node);
}
@@ -61,6 +57,8 @@ impl<'a> Iterator for ElementIdIterator<'a> {
// Simply swap the current node on the stack with the root of the component
*node = scope.root_node();
}
VNode::Template(_) => todo!(),
}
} else {
// If there's no more items on the stack, we're done!
@@ -84,44 +82,3 @@ impl<'a> Iterator for ElementIdIterator<'a> {
returned_node
}
}
/// This intentionally leaks once per element name to allow more flexability when hot reloding templetes
#[cfg(all(any(feature = "hot-reload", debug_assertions), feature = "serde"))]
mod leaky {
use std::sync::Mutex;
use once_cell::sync::Lazy;
use rustc_hash::FxHashSet;
static STATIC_CACHE: Lazy<Mutex<FxHashSet<&'static str>>> =
Lazy::new(|| Mutex::new(FxHashSet::default()));
pub fn deserialize_static_leaky<'de, D>(d: D) -> Result<&'static str, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::Deserialize;
let s = <&str>::deserialize(d)?;
Ok(if let Some(stat) = STATIC_CACHE.lock().unwrap().get(s) {
*stat
} else {
Box::leak(s.into())
})
}
pub fn deserialize_static_leaky_ns<'de, D>(d: D) -> Result<Option<&'static str>, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::Deserialize;
Ok(<Option<&str>>::deserialize(d)?.map(|s| {
if let Some(stat) = STATIC_CACHE.lock().unwrap().get(s) {
*stat
} else {
Box::leak(s.into())
}
}))
}
}
#[cfg(all(any(feature = "hot-reload", debug_assertions), feature = "serde"))]
pub use leaky::*;