mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-27 09:54:41 -05:00
Merge pull request #3803 from leptos-rs/store-test-fixes
Store test fixes
This commit is contained in:
@@ -116,8 +116,10 @@ where
|
||||
}
|
||||
|
||||
fn writer(&self) -> Option<Self::Writer> {
|
||||
let mut parent = self.inner.writer()?;
|
||||
parent.untrack();
|
||||
let triggers = self.triggers_for_current_path();
|
||||
let guard = WriteGuard::new(triggers, self.inner.writer()?);
|
||||
let guard = WriteGuard::new(triggers, parent);
|
||||
Some(MappedMut::new(guard, self.read, self.write))
|
||||
}
|
||||
|
||||
@@ -464,7 +466,8 @@ where
|
||||
}
|
||||
|
||||
fn writer(&self) -> Option<Self::Writer> {
|
||||
let inner = self.inner.writer()?;
|
||||
let mut inner = self.inner.writer()?;
|
||||
inner.untrack();
|
||||
let inner_path = self.inner.path().into_iter().collect::<StorePath>();
|
||||
let keys = self
|
||||
.inner
|
||||
|
||||
@@ -296,9 +296,18 @@ mod tests {
|
||||
println!("inner_first: next run");
|
||||
}
|
||||
|
||||
// note: we specifically want to test whether using `.patch()`
|
||||
// correctly limits notifications on the first field when only the second
|
||||
// field has changed
|
||||
//
|
||||
// `.map()` would also track the parent field (to track when it changed from Some
|
||||
// to None), which would mean the notification numbers were always the same
|
||||
//
|
||||
// so here, we'll do `.map_untracked()`, but in general in a real case you'd want
|
||||
// to use `.map()` so that if the parent switches to None you do track that
|
||||
println!(
|
||||
" value = {:?}",
|
||||
store.inner().map(|inner| inner.first().get())
|
||||
store.inner().map_untracked(|inner| inner.first().get())
|
||||
);
|
||||
inner_first_count.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
@@ -325,6 +334,7 @@ mod tests {
|
||||
assert_eq!(inner_first_count.load(Ordering::Relaxed), 1);
|
||||
assert_eq!(inner_second_count.load(Ordering::Relaxed), 1);
|
||||
|
||||
println!("\npatching with A/C");
|
||||
store.patch(Outer {
|
||||
inner: Some(Inner {
|
||||
first: "A".to_string(),
|
||||
@@ -333,17 +343,18 @@ mod tests {
|
||||
});
|
||||
|
||||
tick().await;
|
||||
assert_eq!(parent_count.load(Ordering::Relaxed), 1);
|
||||
assert_eq!(parent_count.load(Ordering::Relaxed), 2);
|
||||
assert_eq!(inner_first_count.load(Ordering::Relaxed), 1);
|
||||
assert_eq!(inner_second_count.load(Ordering::Relaxed), 2);
|
||||
|
||||
store.patch(Outer { inner: None });
|
||||
|
||||
tick().await;
|
||||
assert_eq!(parent_count.load(Ordering::Relaxed), 2);
|
||||
assert_eq!(parent_count.load(Ordering::Relaxed), 3);
|
||||
assert_eq!(inner_first_count.load(Ordering::Relaxed), 2);
|
||||
assert_eq!(inner_second_count.load(Ordering::Relaxed), 3);
|
||||
|
||||
println!("\npatching with A/B");
|
||||
store.patch(Outer {
|
||||
inner: Some(Inner {
|
||||
first: "A".to_string(),
|
||||
@@ -352,8 +363,8 @@ mod tests {
|
||||
});
|
||||
|
||||
tick().await;
|
||||
assert_eq!(parent_count.load(Ordering::Relaxed), 3);
|
||||
assert_eq!(inner_first_count.load(Ordering::Relaxed), 3);
|
||||
assert_eq!(parent_count.load(Ordering::Relaxed), 4);
|
||||
assert_eq!(inner_first_count.load(Ordering::Relaxed), 2);
|
||||
assert_eq!(inner_second_count.load(Ordering::Relaxed), 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,13 @@ where
|
||||
}
|
||||
|
||||
fn writer(&self) -> Option<Self::Writer> {
|
||||
let parent = self.inner.writer()?;
|
||||
let mut parent = self.inner.writer()?;
|
||||
|
||||
// we will manually include all the parent and ancestor `children` triggers
|
||||
// in triggers_for_current_path() below. we want to untrack the parent writer
|
||||
// so that it doesn't notify on the parent's `this` trigger, which would notify our
|
||||
// siblings too
|
||||
parent.untrack();
|
||||
let triggers = self.triggers_for_current_path();
|
||||
let guard = WriteGuard::new(triggers, parent);
|
||||
Some(MappedMut::new(guard, self.read, self.write))
|
||||
|
||||
Reference in New Issue
Block a user