call<T> method
Watcher
call<T>(
- SourcesFn<
T> sourcesFn, - WatcherFn<
T> fn, { - WhenFn<
T> ? when, - bool immediately = false,
- JoltDebugFn? onDebug,
Creates a watcher hook that observes specific reactive sources.
Watchers provide more control than effects by explicitly defining what to watch and comparing old vs new values before executing the callback.
Parameters:
sourcesFn: Function that returns the values to watchfn: Callback function executed when sources changewhen: Optional condition function for custom trigger logicimmediately: Whether to execute the callback immediately (default is false)onDebug: Optional debug callback for reactive system debugging
Returns: A Watcher with fine-grained change detection
Example:
setup(context, props) {
final count = useSignal(0);
final name = useSignal('Alice');
useWatcher(
() => [count.value, name.value],
(newValues, oldValues) {
print('Changed from $oldValues to $newValues');
},
);
return () => Text('${name.value}: ${count.value}');
}
Implementation
Watcher call<T>(
SourcesFn<T> sourcesFn,
WatcherFn<T> fn, {
WhenFn<T>? when,
bool immediately = false,
JoltDebugFn? onDebug,
}) {
return useAutoDispose(() => Watcher<T>(sourcesFn, fn,
when: when, immediately: immediately, onDebug: onDebug));
}