SignalValueListenable<T, N extends ValueListenable<T> , S extends ReadonlySignal<T> >.merge constructor
SignalValueListenable<T, N extends ValueListenable<T> , S extends ReadonlySignal<T> >.merge (
- N notifier,
- S source
Implementation
SignalValueListenable.merge(this.notifier, super.source) {
_SetSource? target;
source.subscribe((val) {
if (target == _SetSource.signal) return;
target = _SetSource.signal;
if (notifier is ValueNotifier<T>) {
(notifier as ValueNotifier<T>).value = val;
}
target = null;
});
void update() {
if (target == _SetSource.notifier) return;
target = _SetSource.notifier;
if (source is Signal<T>) {
(source as Signal<T>).value = notifier.value;
}
target = null;
}
notifier.addListener(update);
source.onDispose(() => notifier.removeListener(update));
}