Refactor Mutations and simplify Templates (#578)
* update mutations to be path based rather than renderer integrated
This commit is contained in:
1 parent
020c4bf0f8
commit
3b7b503333
44 files changed
+2643
-3134
No files matched your search
@@ -1,10 +1,10 @@
|
||||
use std::{marker::PhantomData, ops::Deref};
|
||||
use std::{fmt::Write, marker::PhantomData, ops::Deref};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::{
|
||||
template::{TemplateNodeId, TextTemplateSegment},
|
||||
AttributeValue, Listener, VNode,
|
||||
AttributeValue, Listener, TextTemplate, VNode,
|
||||
};
|
||||
|
||||
/// A lazily initailized vector
|
||||
@@ -96,28 +96,6 @@ where
|
||||
nodes_with_listeners: listeners,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn all_dynamic(&self) -> impl Iterator<Item = TemplateNodeId> + '_ {
|
||||
self.nodes
|
||||
.as_ref()
|
||||
.iter()
|
||||
.filter_map(|o| o.as_ref())
|
||||
.chain(
|
||||
self.text
|
||||
.as_ref()
|
||||
.iter()
|
||||
.flat_map(|ids| ids.as_ref().iter()),
|
||||
)
|
||||
.copied()
|
||||
.chain(
|
||||
self.attributes
|
||||
.as_ref()
|
||||
.iter()
|
||||
.flat_map(|ids| ids.as_ref().iter())
|
||||
.map(|dynamic| dynamic.0),
|
||||
)
|
||||
.chain(self.nodes_with_listeners.as_ref().iter().copied())
|
||||
}
|
||||
}
|
||||
|
||||
/// A dynamic node mapping that is stack allocated
|
||||
@@ -161,19 +139,38 @@ pub struct TemplateContext<'b> {
|
||||
|
||||
impl<'b> TemplateContext<'b> {
|
||||
/// Resolve text segments to a string
|
||||
pub fn resolve_text<TextSegments, Text>(&self, text: &TextSegments) -> String
|
||||
pub fn resolve_text<TextSegments, Text>(
|
||||
&self,
|
||||
text: &TextTemplate<TextSegments, Text>,
|
||||
) -> String
|
||||
where
|
||||
TextSegments: AsRef<[TextTemplateSegment<Text>]>,
|
||||
Text: AsRef<str>,
|
||||
{
|
||||
let mut result = String::new();
|
||||
for seg in text.as_ref() {
|
||||
let mut result = String::with_capacity(text.min_size);
|
||||
self.resolve_text_into(text, &mut result);
|
||||
result
|
||||
}
|
||||
|
||||
/// Resolve text and writes the result
|
||||
pub fn resolve_text_into<TextSegments, Text>(
|
||||
&self,
|
||||
text: &TextTemplate<TextSegments, Text>,
|
||||
result: &mut impl Write,
|
||||
) where
|
||||
TextSegments: AsRef<[TextTemplateSegment<Text>]>,
|
||||
Text: AsRef<str>,
|
||||
{
|
||||
for seg in text.segments.as_ref() {
|
||||
match seg {
|
||||
TextTemplateSegment::Static(s) => result += s.as_ref(),
|
||||
TextTemplateSegment::Dynamic(idx) => result += self.text_segments[*idx],
|
||||
TextTemplateSegment::Static(s) => {
|
||||
let _ = result.write_str(s.as_ref());
|
||||
}
|
||||
TextTemplateSegment::Dynamic(idx) => {
|
||||
let _ = result.write_str(self.text_segments[*idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// Resolve an attribute value
|
||||
|
||||
Reference in new issue
Block a user