WatcherImpl<T> constructor

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

Implementation

WatcherImpl(this.sourcesFn, this.fn,
    {bool immediately = false,
    this.when,
    bool detach = false,
    JoltDebugOption? debug}) {
  raw = EffectNode(_effectFn, lazy: true, detach: detach, debug: debug);

  previousValues = currentValues = raw.track(sourcesFn);
  if (immediately) {
    untracked(() {
      final prevWatcher = Watcher.activeWatcher;
      Watcher.activeWatcher = this;
      try {
        fn(currentValues, null);
      } finally {
        Watcher.activeWatcher = prevWatcher;
      }
    });
  }
}