diff --git a/packages/stores/src/impls/btreemap.rs b/packages/stores/src/impls/btreemap.rs index 03f41a6dc..26ac45783 100644 --- a/packages/stores/src/impls/btreemap.rs +++ b/packages/stores/src/impls/btreemap.rs @@ -131,7 +131,15 @@ impl> + 'static, K: 'static, V: 'static> K: Ord, Lens: Writable, { - self.selector().mark_dirty_shallow(); + // TODO: This method was released in 0.7 without the hash bound so we don't have a way + // to mark only the existing value as dirty. Instead we need to check if the value already exists + // in the map and mark the whole map as dirty if it does. + // In the 0.8 release, we should change this method to only mark the existing value as dirty. + if self.peek().contains_key(&key) { + self.selector().mark_dirty(); + } else { + self.selector().mark_dirty_shallow(); + } self.selector().write_untracked().insert(key, value); } diff --git a/packages/stores/src/impls/hashmap.rs b/packages/stores/src/impls/hashmap.rs index d2b0478d4..6eda1d877 100644 --- a/packages/stores/src/impls/hashmap.rs +++ b/packages/stores/src/impls/hashmap.rs @@ -139,7 +139,13 @@ impl> + 'static, K: 'static, V: 'stati St: BuildHasher, Lens: Writable, { + // Mark the store itself as dirty since the keys may have changed self.selector().mark_dirty_shallow(); + // Mark the existing value as dirty if it exists + self.selector() + .as_ref() + .hash_child_unmapped(key.borrow()) + .mark_dirty(); self.selector().write_untracked().insert(key, value); } diff --git a/packages/stores/src/scope.rs b/packages/stores/src/scope.rs index 383ebba94..b4c9541c9 100644 --- a/packages/stores/src/scope.rs +++ b/packages/stores/src/scope.rs @@ -185,6 +185,15 @@ impl SelectorScope { { self.write.write_unchecked() } + + /// Borrow the writer + pub(crate) fn as_ref(&self) -> SelectorScope<&Lens> { + SelectorScope { + path: self.path, + store: self.store, + write: &self.write, + } + } } impl Readable for SelectorScope {