From 21a42ceb5e87472fee2b2b9fcc022a6201a28ba1 Mon Sep 17 00:00:00 2001 From: Samuel Guerra Date: Sun, 4 Jun 2023 12:05:32 -0300 Subject: [PATCH] Identified issue with bidi binding that is causing the --- TODO/_current.md | 2 +- tests/config.rs | 1 - zero-ui-core/src/var.rs | 1 + zero-ui-core/src/var/tests.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/TODO/_current.md b/TODO/_current.md index bc99af503..2f76f00b1 100644 --- a/TODO/_current.md +++ b/TODO/_current.md @@ -39,7 +39,7 @@ # Config * Test reset. - - Not working, see `config.rs/fallback_reset`. + - Not working, see `fallback_reset` and `binding_bidi_set_both`. - FallbackConfig loses connection with sources? - No amount of updates gets the value, so probably. - Sometimes the test works, but due to the fallback loading faster. diff --git a/tests/config.rs b/tests/config.rs index 4e5baa878..54f2d8aa6 100644 --- a/tests/config.rs +++ b/tests/config.rs @@ -390,7 +390,6 @@ fn fallback_reset() { if status != ConfigStatus::Loaded { panic!("{status}"); } - assert_eq!("fallback", key.get()); } diff --git a/zero-ui-core/src/var.rs b/zero-ui-core/src/var.rs index e2c9f2b01..049efeda0 100644 --- a/zero-ui-core/src/var.rs +++ b/zero-ui-core/src/var.rs @@ -1423,6 +1423,7 @@ pub trait Var: IntoVar + AnyVar + Clone { let (_, ots_id) = last_update.load(Relaxed); if update_id != ots_id { // other_to_self did not cause this assign, propagate. + last_update.store((update_id, ots_id), Relaxed); if let Some(value) = map(value) { let _ = other.set(value); } diff --git a/zero-ui-core/src/var/tests.rs b/zero-ui-core/src/var/tests.rs index 6444d438c..22e01f089 100644 --- a/zero-ui-core/src/var/tests.rs +++ b/zero-ui-core/src/var/tests.rs @@ -415,6 +415,33 @@ mod bindings { assert_eq!(1, a.strong_count()); assert_eq!(1, b.strong_count()); } + + #[test] + fn binding_bidi_set_both() { + let mut app = App::minimal().run_headless(false); + { + // behavior of double assign in same update cycle + let a = var(1); + a.set(10); + a.set(20); + + app.update(false).assert_wait(); + + assert_eq!(20, a.get()); + } + + let a = var(1); + let b = var(1); + + a.bind_bidi(&b); + + a.set(10); + b.set(20); + app.update(false).assert_wait(); + + assert_eq!(20, a.get()); + assert_eq!(20, b.get()); + } } mod context {