Skip to content

Commit

Permalink
doc: some notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanceras committed Mar 9, 2024
1 parent 311d0bb commit a9a78ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion crates/core/src/dom/component/stateful_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ pub fn register_template<MSG>(
where
MSG: 'static,
{
let (dom_template, vdom_template) = template::build_template(&view);
let (dom_template, vdom_template) = template::build_template(view);
let template = TEMPLATE_LOOKUP.with_borrow_mut(|map| {
if let Some(existing) = map.get(&type_id) {
existing.clone_node_with_deep(true).expect("deep clone")
} else {
log::info!("---->> Adding to template...");
map.insert(type_id, dom_template.clone());
dom_template
}
});
(template, vdom_template)
}


/// lookup for the template
pub fn lookup_template(type_id: TypeId) -> Option<web_sys::Node> {
TEMPLATE_LOOKUP.with_borrow_mut(|map| {
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/dom/dom_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ where
#[cfg(feature = "use-template")]
{
let template = lookup_template(comp.type_id).expect("must have a template");
//Note: we don't want the patches to be stored in the StatelessModel
//since it has a lifetime, which will infect the Node, Element, Attribute, etc
let patches = diff(&comp.vdom_template, &comp.view);
log::info!("patching template: {:#?}", patches);
let dom_patches = self
Expand Down
4 changes: 2 additions & 2 deletions examples/js-performance-benchmark-sauron/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ crate-type = ["cdylib"]
[dependencies]
rand = { version = "0.8.5", features = ["small_rng"] }
getrandom = { version = "0.2.7", features = ["js"] }
#sauron = { path = "../../../sauron", features = ["with-debug", "with-measure", "use-template"] }
sauron = { path = "../../../sauron", features = ["with-debug", "with-measure"] }
sauron = { path = "../../../sauron", features = ["with-debug", "with-measure", "use-template"] }
#sauron = { path = "../../../sauron", features = ["with-debug", "with-measure"] }
log = "0.4"
console_log = "0.2"
console_error_panic_hook = "0.1"
Expand Down

0 comments on commit a9a78ac

Please sign in to comment.