feat: get desktop working with new template strategy

This commit is contained in:
Jonathan Kelley committed 2022-12-05 16:08:41 -08:00
1 parent df4a1b6c7a
commit 7b1cdb7d85
11 files changed
+79 -31

No files matched your search

+3 -3
View File
@@ -40,7 +40,7 @@ impl<'b> VirtualDom {
for (root_idx, root) in template.template.roots.iter().enumerate() {
// We might need to generate an ID for the root node
on_stack += match root {
TemplateNode::DynamicText(id) | TemplateNode::Dynamic(id) => {
TemplateNode::DynamicText { id } | TemplateNode::Dynamic { id } => {
match &template.dynamic_nodes[*id] {
// a dynamic text node doesn't replace a template node, instead we create it on the fly
DynamicNode::Text(VText { id: slot, value }) => {
@@ -70,7 +70,7 @@ impl<'b> VirtualDom {
}
}
TemplateNode::Element { .. } | TemplateNode::Text(_) => {
TemplateNode::Element { .. } | TemplateNode::Text { .. } => {
let this_id = self.next_root(template, root_idx);
template.root_ids[root_idx].set(this_id);
@@ -215,7 +215,7 @@ impl<'b> VirtualDom {
.filter(|root| {
matches!(
root,
TemplateNode::Dynamic(_) | TemplateNode::DynamicText(_)
TemplateNode::Dynamic { .. } | TemplateNode::DynamicText { .. }
)
})
.count();
+1 -1
View File
@@ -911,7 +911,7 @@ fn matching_components<'a>(
.zip(right.template.roots.iter())
.map(|(l, r)| {
let (l, r) = match (l, r) {
(TemplateNode::Dynamic(l), TemplateNode::Dynamic(r)) => (l, r),
(TemplateNode::Dynamic { id: l }, TemplateNode::Dynamic { id: r }) => (l, r),
_ => return None,
};
+1
View File
@@ -13,6 +13,7 @@ use crate::{arena::ElementId, ScopeId, Template};
/// Templates, however, apply to all subtrees, not just target subtree.
///
/// Mutations are the only link between the RealDOM and the VirtualDOM.
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[derive(Debug, Default)]
#[must_use = "not handling edits can lead to visual inconsistencies in UI"]
pub struct Mutations<'a> {
+11 -7
View File
@@ -78,8 +78,8 @@ impl<'a> VNode<'a> {
/// Returns [`None`] if the root is actually a static node (Element/Text)
pub fn dynamic_root(&self, idx: usize) -> Option<&'a DynamicNode<'a>> {
match &self.template.roots[idx] {
TemplateNode::Element { .. } | TemplateNode::Text(_) => None,
TemplateNode::Dynamic(id) | TemplateNode::DynamicText(id) => {
TemplateNode::Element { .. } | TemplateNode::Text { text: _ } => None,
TemplateNode::Dynamic { id } | TemplateNode::DynamicText { id } => {
Some(&self.dynamic_nodes[*id])
}
}
@@ -132,7 +132,7 @@ pub struct Template<'a> {
///
/// This can be created at compile time, saving the VirtualDom time when diffing the tree
#[derive(Debug, Clone, Copy, PartialEq, Hash, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize), serde(tag = "type"))]
pub enum TemplateNode<'a> {
/// An statically known element in the dom.
///
@@ -159,15 +159,15 @@ pub enum TemplateNode<'a> {
},
/// This template node is just a piece of static text
Text(&'a str),
Text { text: &'a str },
/// This template node is unknown, and needs to be created at runtime.
Dynamic(usize),
Dynamic { id: usize },
/// This template node is known to be some text, but needs to be created at runtime
///
/// This is separate from the pure Dynamic variant for various optimizations
DynamicText(usize),
DynamicText { id: usize },
}
/// A node created at runtime
@@ -252,7 +252,11 @@ pub struct VText<'a> {
/// An attribute of the TemplateNode, created at compile time
#[derive(Debug, PartialEq, Hash, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "serialize",
derive(serde::Serialize, serde::Deserialize),
serde(tag = "type")
)]
pub enum TemplateAttribute<'a> {
/// This attribute is entirely known at compile time, enabling
Static {