Skip to content

Commit

Permalink
fix: correctly track inner subfields on Field (closes #3169) (#3170)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbj authored Oct 29, 2024
1 parent d67ff03 commit e5149fb
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
17 changes: 15 additions & 2 deletions reactive_stores/src/arc_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ where
read: Arc<dyn Fn() -> Option<StoreFieldReader<T>> + Send + Sync>,
write: Arc<dyn Fn() -> Option<StoreFieldWriter<T>> + Send + Sync>,
keys: Arc<dyn Fn() -> Option<KeyMap> + Send + Sync>,
track_field: Arc<dyn Fn() + Send + Sync>,
}

pub struct StoreFieldReader<T>(Box<dyn Deref<Target = T>>);
Expand Down Expand Up @@ -128,6 +129,10 @@ where
let value = value.clone();
move || value.keys()
}),
track_field: Arc::new({
let value = value.clone();
move || value.track_field()
}),
}
}
}
Expand Down Expand Up @@ -162,6 +167,10 @@ where
let value = value.clone();
move || value.keys()
}),
track_field: Arc::new({
let value = value.clone();
move || value.track_field()
}),
}
}
}
Expand Down Expand Up @@ -200,6 +209,10 @@ where
let value = value.clone();
move || value.keys()
}),
track_field: Arc::new({
let value = value.clone();
move || value.track_field()
}),
}
}
}
Expand All @@ -215,6 +228,7 @@ impl<T> Clone for ArcField<T> {
read: Arc::clone(&self.read),
write: Arc::clone(&self.write),
keys: Arc::clone(&self.keys),
track_field: Arc::clone(&self.track_field),
}
}
}
Expand All @@ -240,8 +254,7 @@ impl<T> Notify for ArcField<T> {

impl<T> Track for ArcField<T> {
fn track(&self) {
self.trigger.this.track();
self.trigger.children.track();
(self.track_field)();
}
}

Expand Down
4 changes: 1 addition & 3 deletions reactive_stores/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ where
Prev::Output: Sized + 'static,
{
fn track(&self) {
let trigger = self.get_trigger(self.path().into_iter().collect());
trigger.this.track();
trigger.children.track();
self.track_field();
}
}

Expand Down
22 changes: 12 additions & 10 deletions reactive_stores/src/keyed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ where
fn keys(&self) -> Option<KeyMap> {
self.inner.keys()
}

fn track_field(&self) {
let inner = self
.inner
.get_trigger(self.inner.path().into_iter().collect());
inner.this.track();
let trigger = self.get_trigger(self.path().into_iter().collect());
trigger.this.track();
trigger.children.track();
}
}

impl<Inner, Prev, K, T> KeyedSubfield<Inner, Prev, K, T>
Expand Down Expand Up @@ -287,13 +297,7 @@ where
K: Debug + Send + Sync + PartialEq + Eq + Hash + 'static,
{
fn track(&self) {
let inner = self
.inner
.get_trigger(self.inner.path().into_iter().collect());
inner.this.track();
let trigger = self.get_trigger(self.path().into_iter().collect());
trigger.this.track();
trigger.children.track();
self.track_field();
}
}

Expand Down Expand Up @@ -551,9 +555,7 @@ where
T::Output: Sized,
{
fn track(&self) {
let trigger = self.get_trigger(self.path().into_iter().collect());
trigger.this.track();
trigger.children.track();
self.track_field();
}
}

Expand Down
4 changes: 1 addition & 3 deletions reactive_stores/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ where

impl<T: 'static> Track for ArcStore<T> {
fn track(&self) {
let trigger = self.get_trigger(Default::default());
trigger.this.track();
trigger.children.track();
self.track_field();
}
}

Expand Down
4 changes: 1 addition & 3 deletions reactive_stores/src/store_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ where
S: StoreField,
{
fn track(&self) {
let trigger = self.get_trigger(self.path().into_iter().collect());
trigger.this.track();
trigger.children.track();
self.track_field();
}
}

Expand Down
18 changes: 11 additions & 7 deletions reactive_stores/src/subfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ where
fn keys(&self) -> Option<KeyMap> {
self.inner.keys()
}

fn track_field(&self) {
let inner = self
.inner
.get_trigger(self.inner.path().into_iter().collect());
inner.this.track();
let trigger = self.get_trigger(self.path().into_iter().collect());
trigger.this.track();
trigger.children.track();
}
}

impl<Inner, Prev, T> DefinedAt for Subfield<Inner, Prev, T>
Expand Down Expand Up @@ -146,13 +156,7 @@ where
T: 'static,
{
fn track(&self) {
let inner = self
.inner
.get_trigger(self.inner.path().into_iter().collect());
inner.this.track();
let trigger = self.get_trigger(self.path().into_iter().collect());
trigger.this.track();
trigger.children.track();
self.track_field();
}
}

Expand Down

0 comments on commit e5149fb

Please sign in to comment.