Watcher<T> constructor

Watcher<T>(
  1. SourcesFn<T> sourcesFn,
  2. WatcherFn<T> fn, {
  3. bool immediately,
  4. WhenFn<T>? when,
  5. bool? detach,
  6. JoltDebugOption? debug,
})

Creates a new watcher with the given sources and callback.

Parameters:

  • sourcesFn: Function that returns the values to watch
  • fn: Callback function executed when sources change
  • immediately: Whether to execute the callback immediately
  • when: Optional condition function for custom trigger logic
  • detach: Whether to detach this watcher from the current effect scope. If true, the watcher will not be automatically disposed when its parent scope is disposed.
  • debug: Optional debug options

Example:

final signal = Signal(0);

final watcher = Watcher(
  () => signal.value,
  (newValue, oldValue) => print('Changed: $oldValue -> $newValue'),
  immediately: true,
  when: (newValue, oldValue) => newValue > oldValue, // Only when increasing
);

Implementation

factory Watcher(
  SourcesFn<T> sourcesFn,
  WatcherFn<T> fn, {
  bool immediately,
  WhenFn<T>? when,
  bool? detach,
  JoltDebugOption? debug,
}) = WatcherImpl<T>;