mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-22 16:49:22 -05:00
made sync_signal more robust
This commit is contained in:
parent
c9377fe1f9
commit
26938f8e52
1 changed files with 11 additions and 5 deletions
|
@ -148,7 +148,7 @@ pub fn sync_signal<T>(
|
||||||
right: impl Into<UseRwSignal<T>>,
|
right: impl Into<UseRwSignal<T>>,
|
||||||
) -> impl Fn() + Clone
|
) -> impl Fn() + Clone
|
||||||
where
|
where
|
||||||
T: Clone + PartialEq + 'static,
|
T: Clone + 'static,
|
||||||
{
|
{
|
||||||
sync_signal_with_options(left, right, SyncSignalOptions::default())
|
sync_signal_with_options(left, right, SyncSignalOptions::default())
|
||||||
}
|
}
|
||||||
|
@ -160,8 +160,8 @@ pub fn sync_signal_with_options<L, R>(
|
||||||
options: SyncSignalOptions<L, R>,
|
options: SyncSignalOptions<L, R>,
|
||||||
) -> impl Fn() + Clone
|
) -> impl Fn() + Clone
|
||||||
where
|
where
|
||||||
L: Clone + PartialEq + 'static,
|
L: Clone + 'static,
|
||||||
R: Clone + PartialEq + 'static,
|
R: Clone + 'static,
|
||||||
{
|
{
|
||||||
let SyncSignalOptions {
|
let SyncSignalOptions {
|
||||||
immediate,
|
immediate,
|
||||||
|
@ -178,14 +178,18 @@ where
|
||||||
let mut stop_watch_left = None;
|
let mut stop_watch_left = None;
|
||||||
let mut stop_watch_right = None;
|
let mut stop_watch_right = None;
|
||||||
|
|
||||||
|
let is_sync_update = StoredValue::new(false);
|
||||||
|
|
||||||
if matches!(direction, SyncDirection::Both | SyncDirection::LeftToRight) {
|
if matches!(direction, SyncDirection::Both | SyncDirection::LeftToRight) {
|
||||||
stop_watch_left = Some(watch(
|
stop_watch_left = Some(watch(
|
||||||
move || left.get(),
|
move || left.get(),
|
||||||
move |new_value, _, _| {
|
move |new_value, _, _| {
|
||||||
let new_value = (*transform_ltr)(new_value);
|
let new_value = (*transform_ltr)(new_value);
|
||||||
|
|
||||||
if right.with_untracked(|right| right != &new_value) {
|
if !is_sync_update.get_value() {
|
||||||
|
is_sync_update.set_value(true);
|
||||||
right.update(|right| assign_ltr(right, new_value));
|
right.update(|right| assign_ltr(right, new_value));
|
||||||
|
is_sync_update.set_value(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
immediate,
|
immediate,
|
||||||
|
@ -198,8 +202,10 @@ where
|
||||||
move |new_value, _, _| {
|
move |new_value, _, _| {
|
||||||
let new_value = (*transform_rtl)(new_value);
|
let new_value = (*transform_rtl)(new_value);
|
||||||
|
|
||||||
if left.with_untracked(|left| left != &new_value) {
|
if !is_sync_update.get_value() {
|
||||||
|
is_sync_update.set_value(true);
|
||||||
left.update(|left| assign_rtl(left, new_value));
|
left.update(|left| assign_rtl(left, new_value));
|
||||||
|
is_sync_update.set_value(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
immediate,
|
immediate,
|
||||||
|
|
Loading…
Add table
Reference in a new issue