Browse Source

fix nodes not being marked as dirty with multiple mutations

Evan Almloff 2 years ago
parent
commit
6bc9bc6ef9
2 changed files with 16 additions and 8 deletions
  1. 1 1
      packages/native-core/src/node_ref.rs
  2. 15 7
      packages/native-core/src/real_dom.rs

+ 1 - 1
packages/native-core/src/node_ref.rs

@@ -126,7 +126,7 @@ impl AttributeMask {
     pub fn union(&self, other: &Self) -> Self {
     pub fn union(&self, other: &Self) -> Self {
         match (self, other) {
         match (self, other) {
             (AttributeMask::Some(s), AttributeMask::Some(o)) => {
             (AttributeMask::Some(s), AttributeMask::Some(o)) => {
-                AttributeMask::Some(s.intersection(o).cloned().collect())
+                AttributeMask::Some(s.union(o).cloned().collect())
             }
             }
             _ => AttributeMask::All,
             _ => AttributeMask::All,
         }
         }

+ 15 - 7
packages/native-core/src/real_dom.rs

@@ -186,6 +186,8 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
             .entry(id)
             .entry(id)
             .or_default()
             .or_default()
             .extend(self.dirty_nodes.passes.iter().map(|x| x.this_type_id));
             .extend(self.dirty_nodes.passes.iter().map(|x| x.this_type_id));
+        self.dirty_nodes
+            .mark_dirty(id, NodeMaskBuilder::ALL.build());
         let watchers = self.node_watchers.clone();
         let watchers = self.node_watchers.clone();
         for watcher in &*watchers.read().unwrap() {
         for watcher in &*watchers.read().unwrap() {
             watcher.on_node_added(NodeMut::new(id, self));
             watcher.on_node_added(NodeMut::new(id, self));
@@ -216,16 +218,19 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
         self.root_id
         self.root_id
     }
     }
 
 
+    /// Check if a node exists in the dom.
+    pub fn contains(&self, id: NodeId) -> bool {
+        self.tree_ref().contains(id)
+    }
+
     /// Get a reference to a node.
     /// Get a reference to a node.
     pub fn get(&self, id: NodeId) -> Option<NodeRef<'_, V>> {
     pub fn get(&self, id: NodeId) -> Option<NodeRef<'_, V>> {
-        self.tree_ref()
-            .contains(id)
-            .then_some(NodeRef { id, dom: self })
+        self.contains(id).then_some(NodeRef { id, dom: self })
     }
     }
 
 
     /// Get a mutable reference to a node.
     /// Get a mutable reference to a node.
     pub fn get_mut(&mut self, id: NodeId) -> Option<NodeMut<'_, V>> {
     pub fn get_mut(&mut self, id: NodeId) -> Option<NodeMut<'_, V>> {
-        let contains = self.tree_ref().contains(id);
+        let contains = self.contains(id);
         contains.then(|| NodeMut::new(id, self))
         contains.then(|| NodeMut::new(id, self))
     }
     }
 
 
@@ -399,7 +404,7 @@ impl<'a, V: Component<Tracking = Untracked> + Send + Sync> DerefMut for ViewEntr
 }
 }
 
 
 /// A immutable view of a node
 /// A immutable view of a node
-pub trait NodeImmutable<V: FromAnyValue + Send + Sync>: Sized {
+pub trait NodeImmutable<V: FromAnyValue + Send + Sync = ()>: Sized {
     /// Get the real dom this node was created in
     /// Get the real dom this node was created in
     fn real_dom(&self) -> &RealDom<V>;
     fn real_dom(&self) -> &RealDom<V>;
 
 
@@ -573,7 +578,9 @@ impl<'a, V: FromAnyValue + Send + Sync> NodeMut<'a, V> {
             .or_default()
             .or_default()
             .insert(TypeId::of::<T>());
             .insert(TypeId::of::<T>());
         let view_mut: ViewMut<T> = self.dom.borrow_raw().ok()?;
         let view_mut: ViewMut<T> = self.dom.borrow_raw().ok()?;
-        Some(ViewEntryMut::new(view_mut, self.id))
+        view_mut
+            .contains(self.id)
+            .then_some(ViewEntryMut::new(view_mut, self.id))
     }
     }
 
 
     /// Insert a custom component into this node
     /// Insert a custom component into this node
@@ -684,7 +691,8 @@ impl<'a, V: FromAnyValue + Send + Sync> NodeMut<'a, V> {
         for child in children_ids_vec {
         for child in children_ids_vec {
             self.dom.get_mut(child).unwrap().remove();
             self.dom.get_mut(child).unwrap().remove();
         }
         }
-        self.dom.tree_mut().remove_single(id);
+        self.dom.tree_mut().remove(id);
+        self.real_dom_mut().raw_world_mut().delete_entity(id);
     }
     }
 
 
     /// Replace this node with a different node
     /// Replace this node with a different node