Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/stores/src/impls/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,16 @@ impl<Lens: Readable<Target = BTreeMap<K, V>> + '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) {
println!("marking map as dirty");
self.selector().mark_dirty();
} else {
self.selector().mark_dirty_shallow();
}
self.selector().write_untracked().insert(key, value);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/stores/src/impls/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ impl<Lens: Readable<Target = HashMap<K, V, St>> + '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);
}

Expand Down
9 changes: 9 additions & 0 deletions packages/stores/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ impl<Lens> SelectorScope<Lens> {
{
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<Lens: Readable> Readable for SelectorScope<Lens> {
Expand Down
Loading