WatcherImpl<T>.immediately constructor
WatcherImpl<T>.immediately (
- SourcesFn<
T> sourcesFn, - WatcherFn<
T> fn, { - WhenFn<
T> ? when, - JoltDebugFn? onDebug,
Creates a watcher that executes the callback immediately upon creation.
This factory method is a convenience constructor for creating a watcher
with immediately set to true. The callback will be executed once
immediately with the current source values, and then whenever the sources
change and the condition (if provided) is met.
Parameters:
sourcesFn: Function that returns the values to watchfn: Callback function executed when sources changewhen: Optional condition function for custom trigger logiconDebug: Optional debug callback for reactive system debugging
Returns: A new Watcher instance that executes immediately
Example:
final signal = Signal(10);
final values = <int>[];
Watcher.immediately(
() => signal.value,
(newValue, oldValue) {
values.add(newValue);
},
);
// Callback executed immediately with value 10
expect(values, equals([10]));
signal.value = 20; // Triggers callback again
expect(values, equals([10, 20]));
Implementation
factory WatcherImpl.immediately(SourcesFn<T> sourcesFn, WatcherFn<T> fn,
{WhenFn<T>? when, JoltDebugFn? onDebug}) {
return WatcherImpl(sourcesFn, fn,
immediately: true, when: when, onDebug: onDebug);
}