WatcherImpl<T> class
Implementation of Watcher that observes changes to reactive sources and executes a callback.
This is the concrete implementation of the Watcher interface. Watchers are similar to effects but provide more control over when they trigger. They compare old and new values and only execute when values actually change (or when a custom condition is met).
See Watcher for the public interface and usage examples.
Example:
final count = Signal(0);
final name = Signal('Alice');
final watcher = Watcher(
() => [count.value, name.value], // Sources to watch
(newValues, oldValues) {
print('Count: ${newValues[0]}, Name: ${newValues[1]}');
},
);
count.value = 1; // Triggers watcher
name.value = 'Bob'; // Triggers watcher
- Inheritance
-
- Object
- ReactiveNode
- EffectReactiveNode
- WatcherImpl
- Implemented types
-
- Watcher<
T>
- Watcher<
- Mixed-in types
Constructors
-
WatcherImpl(SourcesFn<
T> sourcesFn, WatcherFn<T> fn, {bool immediately = false, WhenFn<T> ? when, JoltDebugFn? onDebug}) - Creates a new watcher with the given sources and callback.
-
WatcherImpl.immediately(SourcesFn<
T> sourcesFn, WatcherFn<T> fn, {WhenFn<T> ? when, JoltDebugFn? onDebug}) -
Creates a watcher that executes the callback immediately upon creation.
factory
-
WatcherImpl.once(SourcesFn<
T> sourcesFn, WatcherFn<T> fn, {WhenFn<T> ? when, JoltDebugFn? onDebug}) -
Creates a watcher that executes once and then automatically disposes itself.
factory
Properties
- deps ↔ Link?
-
First dependency link in the chain.
getter/setter pairinherited
- depsTail ↔ Link?
-
Last dependency link in the chain.
getter/setter pairinherited
- flags ↔ int
-
Reactive flags for this node.
getter/setter pairinherited
-
fn
→ WatcherFn<
T> -
Callback function executed when sources change.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
no setterinherited
- isPaused → bool
-
Whether this watcher is currently paused.
no setteroverride
- prevSources ↔ T
-
The previous source values for comparison.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
sourcesFn
→ SourcesFn<
T> -
Function that provides the source values to watch.
final
- subs ↔ Link?
-
First subscriber link in the chain.
getter/setter pairinherited
- subsTail ↔ Link?
-
Last subscriber link in the chain.
getter/setter pairinherited
- testCachedSources → T
-
no setter
-
when
→ WhenFn<
T> ? -
Optional condition function for custom trigger logic.
final
Methods
-
dispose(
) → void -
Disposes this node and cleans up resources.
inherited
-
doCleanup(
) → void -
Executes all registered cleanup functions and clears the cleanup list.
inherited
-
ignoreUpdates<
U> (U fn()) → U -
Temporarily ignores updates from the reactive sources during function execution.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onCleanUp(
Disposer fn) → void -
Registers a cleanup function to be called when this effect is disposed or re-run.
inherited
-
onDispose(
) → void -
Called during the disposal process to perform custom cleanup.
override
-
pause(
) → void -
Pauses the watcher, preventing it from responding to changes.
override
-
resume(
[bool tryRun = false]) → void -
Resumes the watcher, re-enabling it to respond to changes.
override
-
run(
) → void -
Manually runs the watcher function.
override
-
runEffect(
) → void -
Executes the effect when it is dirty or pending.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
trigger(
{required T? sources}) → void
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited