Merge branch 'upstream' into simplify-native-core

This commit is contained in:
Evan Almloff committed 2023-01-08 14:03:44 -06:00
commit ecf4ee275a
142 files changed
+2951 -1853

No files matched your search

@@ -1,5 +1,5 @@
use crate::{
node::{ElementNode, NodeType},
node::{ElementNode, FromAnyValue, NodeType},
passes::{AnyMapLike, TypeErasedPass},
real_dom::RealDom,
state::State,
@@ -74,7 +74,11 @@ impl PersistantElementIter {
/// remove stale element refreneces
/// returns true if the focused element is removed
pub fn prune<S: State + Send>(&mut self, mutations: &Mutations, rdom: &RealDom<S>) -> bool {
pub fn prune<S: State<V>, V: FromAnyValue>(
&mut self,
mutations: &Mutations,
rdom: &RealDom<S, V>,
) -> bool {
let mut changed = false;
let ids_removed: Vec<_> = mutations
.edits
@@ -100,7 +104,7 @@ impl PersistantElementIter {
// if a child is removed or inserted before or at the current element, update the child index
for (el_id, child_idx) in self.stack.iter_mut() {
if let NodePosition::InChild(child_idx) = child_idx {
if let Some(children) = &rdom.tree.children_ids(*el_id) {
if let Some(children) = &rdom.children_ids(*el_id) {
for m in &mutations.edits {
match m {
Mutation::Remove { id } => {
@@ -131,7 +135,7 @@ impl PersistantElementIter {
}
/// get the next element
pub fn next<S: State + Send>(&mut self, rdom: &RealDom<S>) -> ElementProduced {
pub fn next<S: State<V>, V: FromAnyValue>(&mut self, rdom: &RealDom<S, V>) -> ElementProduced {
if self.stack.is_empty() {
let id = NodeId(0);
let new = (id, NodePosition::AtNode);
@@ -139,10 +143,10 @@ impl PersistantElementIter {
ElementProduced::Looped(id)
} else {
let (last, old_child_idx) = self.stack.last_mut().unwrap();
let node = &rdom[*last];
let node = rdom.get(*last).unwrap();
match &node.node_data.node_type {
NodeType::Element(ElementNode { .. }) => {
let children = rdom.tree.children_ids(*last).unwrap();
let children = rdom.children_ids(*last).unwrap();
*old_child_idx = old_child_idx.map(|i| i + 1);
// if we have children, go to the next child
let child_idx = old_child_idx.get_or_insert(0);
@@ -151,7 +155,8 @@ impl PersistantElementIter {
self.next(rdom)
} else {
let id = children[child_idx];
if let NodeType::Element(ElementNode { .. }) = &rdom[id].node_data.node_type
if let NodeType::Element(ElementNode { .. }) =
rdom.get(id).unwrap().node_data.node_type
{
self.stack.push((id, NodePosition::AtNode));
}
@@ -168,16 +173,19 @@ impl PersistantElementIter {
}
/// get the previous element
pub fn prev<S: State + Send>(&mut self, rdom: &RealDom<S>) -> ElementProduced {
pub fn prev<S: State<V> + Send, V: FromAnyValue>(
&mut self,
rdom: &RealDom<S, V>,
) -> ElementProduced {
// recursively add the last child element to the stack
fn push_back<S: State + Send>(
fn push_back<S: State<V> + Send, V: FromAnyValue>(
stack: &mut smallvec::SmallVec<[(NodeId, NodePosition); 5]>,
new_node: NodeId,
rdom: &RealDom<S>,
rdom: &RealDom<S, V>,
) -> NodeId {
match &rdom[new_node].node_data.node_type {
NodeType::Element(ElementNode { .. }) => {
let children = rdom.tree.children_ids(new_node).unwrap();
let children = rdom.children_ids(new_node).unwrap();
if children.is_empty() {
new_node
} else {
@@ -196,7 +204,7 @@ impl PersistantElementIter {
let node = &rdom[*last];
match &node.node_data.node_type {
NodeType::Element(ElementNode { .. }) => {
let children = rdom.tree.children_ids(*last).unwrap();
let children = rdom.children_ids(*last).unwrap();
// if we have children, go to the next child
if let NodePosition::InChild(0) = old_child_idx {
ElementProduced::Progressed(self.pop())