diff --git a/packages/rsx/Cargo.toml b/packages/rsx/Cargo.toml index 40b785b6e..40655ed77 100644 --- a/packages/rsx/Cargo.toml +++ b/packages/rsx/Cargo.toml @@ -12,3 +12,4 @@ syn = { version = "1.0", features = ["full", "extra-traits"] } quote = { version = "1.0" } dioxus-core = { path = "../core", features = ["serialize"] } serde = { version = "1.0", features = ["derive"] } +internment = "0.7.0" \ No newline at end of file diff --git a/packages/rsx/src/lib.rs b/packages/rsx/src/lib.rs index 81babed6c..c6dbd5862 100644 --- a/packages/rsx/src/lib.rs +++ b/packages/rsx/src/lib.rs @@ -19,12 +19,15 @@ mod hot_reloading_context; mod ifmt; mod node; +use std::{borrow::Borrow, hash::Hash}; + // Re-export the namespaces into each other pub use component::*; use dioxus_core::{Template, TemplateAttribute, TemplateNode}; pub use element::*; use hot_reloading_context::{Empty, HotReloadingContext}; pub use ifmt::*; +use internment::Intern; pub use node::*; // imports @@ -35,6 +38,13 @@ use syn::{ Result, Token, }; +// interns a object into a static object, resusing the value if it already exists +fn intern<'a, T: Eq + Hash + Send + Sync + ?Sized + 'static>( + s: impl Into>, +) -> &'static T { + s.into().as_ref() +} + /// Fundametnally, every CallBody is a template #[derive(Default)] pub struct CallBody { @@ -47,15 +57,20 @@ pub struct CallBody { } impl CallBody { + /// 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. /// the previous_location is the location of the previous template at the time the template was originally compiled. - pub fn leak_template(&self, previous_location: &'static str) -> Template { + pub fn update_template( + &self, + template: Option<&CallBody>, + location: &'static str, + ) -> Option