half-build-times
This commit is contained in:
1 parent
f69b84bf34
commit
3d8d8a1b6f
24 files changed
+489
-456
No files matched your search
+15
-3
@@ -15,18 +15,22 @@
|
||||
mod errors;
|
||||
mod component;
|
||||
mod element;
|
||||
#[cfg(feature = "hot_reload")]
|
||||
pub mod hot_reload;
|
||||
mod ifmt;
|
||||
mod node;
|
||||
|
||||
use std::{collections::HashMap, fmt::Debug, hash::Hash};
|
||||
use std::{fmt::Debug, hash::Hash};
|
||||
|
||||
// Re-export the namespaces into each other
|
||||
pub use component::*;
|
||||
#[cfg(feature = "hot_reload")]
|
||||
use dioxus_core::{Template, TemplateAttribute, TemplateNode};
|
||||
pub use element::*;
|
||||
#[cfg(feature = "hot_reload")]
|
||||
pub use hot_reload::HotReloadingContext;
|
||||
pub use ifmt::*;
|
||||
#[cfg(feature = "hot_reload")]
|
||||
use internment::Intern;
|
||||
pub use node::*;
|
||||
|
||||
@@ -38,6 +42,7 @@ use syn::{
|
||||
Result, Token,
|
||||
};
|
||||
|
||||
#[cfg(feature = "hot_reload")]
|
||||
// interns a object into a static object, resusing the value if it already exists
|
||||
fn intern<T: Eq + Hash + Send + Sync + ?Sized + 'static>(s: impl Into<Intern<T>>) -> &'static T {
|
||||
s.into().as_ref()
|
||||
@@ -50,6 +55,7 @@ pub struct CallBody {
|
||||
}
|
||||
|
||||
impl CallBody {
|
||||
#[cfg(feature = "hot_reload")]
|
||||
/// This will try to create a new template from the current body and the previous body. This will return None if the rsx has some dynamic part that has changed.
|
||||
/// This function intentionally leaks memory to create a static template.
|
||||
/// Keeping the template static allows us to simplify the core of dioxus and leaking memory in dev mode is less of an issue.
|
||||
@@ -140,6 +146,7 @@ pub struct TemplateRenderer<'a> {
|
||||
}
|
||||
|
||||
impl<'a> TemplateRenderer<'a> {
|
||||
#[cfg(feature = "hot_reload")]
|
||||
fn update_template<Ctx: HotReloadingContext>(
|
||||
&mut self,
|
||||
previous_call: Option<CallBody>,
|
||||
@@ -248,14 +255,16 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "hot_reload")]
|
||||
#[derive(Default, Debug)]
|
||||
struct DynamicMapping {
|
||||
attribute_to_idx: HashMap<ElementAttr, Vec<usize>>,
|
||||
attribute_to_idx: std::collections::HashMap<ElementAttr, Vec<usize>>,
|
||||
last_attribute_idx: usize,
|
||||
node_to_idx: HashMap<BodyNode, Vec<usize>>,
|
||||
node_to_idx: std::collections::HashMap<BodyNode, Vec<usize>>,
|
||||
last_element_idx: usize,
|
||||
}
|
||||
|
||||
#[cfg(feature = "hot_reload")]
|
||||
impl DynamicMapping {
|
||||
fn from(nodes: Vec<BodyNode>) -> Self {
|
||||
let mut new = Self::default();
|
||||
@@ -349,6 +358,7 @@ pub struct DynamicContext<'a> {
|
||||
}
|
||||
|
||||
impl<'a> DynamicContext<'a> {
|
||||
#[cfg(feature = "hot_reload")]
|
||||
fn update_node<Ctx: HotReloadingContext>(
|
||||
&mut self,
|
||||
root: &'a BodyNode,
|
||||
@@ -558,6 +568,7 @@ impl<'a> DynamicContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "hot_reload")]
|
||||
#[test]
|
||||
fn create_template() {
|
||||
let input = quote! {
|
||||
@@ -643,6 +654,7 @@ fn create_template() {
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "hot_reload")]
|
||||
#[test]
|
||||
fn diff_template() {
|
||||
use dioxus_core::Scope;
|
||||
|
||||
Reference in new issue
Block a user