From 7094dee150f4cc8f7d993efb09fd9d66d1a623bf Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Sat, 22 Jun 2024 09:11:55 -0400 Subject: [PATCH] fix: signals mark subscribers dirty, but don't say they're always dirty if they haven't changed --- .../src/signal/subscriber_traits.rs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/reactive_graph/src/signal/subscriber_traits.rs b/reactive_graph/src/signal/subscriber_traits.rs index a372aec99..4e7819b3c 100644 --- a/reactive_graph/src/signal/subscriber_traits.rs +++ b/reactive_graph/src/signal/subscriber_traits.rs @@ -57,14 +57,19 @@ impl ReactiveNode for T { if let Some(inner) = self.as_subscriber_set() { let subs = inner.borrow().write().unwrap().take(); for sub in subs { - sub.mark_check(); + sub.mark_dirty(); } } } fn update_if_necessary(&self) -> bool { - // if they're being checked, signals always count as "dirty" - true + // a signal will always mark its dependents Dirty when it runs, so they know + // that they may have changed and need to check themselves at least + // + // however, it's always possible that *another* signal or memo has triggered any + // given effect/memo, and so this signal should *not* say that it is dirty, as it + // may also be checked but has not changed + false } } @@ -117,13 +122,18 @@ impl ReactiveNode for RwLock { fn mark_subscribers_check(&self) { let subs = self.write().unwrap().take(); for sub in subs { - sub.mark_check(); + sub.mark_dirty(); } } fn update_if_necessary(&self) -> bool { - // if they're being checked, signals always count as "dirty" - true + // a signal will always mark its dependents Dirty when it runs, so they know + // that they may have changed and need to check themselves at least + // + // however, it's always possible that *another* signal or memo has triggered any + // given effect/memo, and so this signal should *not* say that it is dirty, as it + // may also be checked but has not changed + false } }