LxWorker<T> class

A reactive observer that executes a side-effect when a source changes.

LxWorker is the primary mechanism for reacting to state changes with non-reactive code (e.g., logging, navigation, or database writes).

Unlike a standard StreamSubscription, LxWorker provides:

  1. Observability: It is itself an LxReactive that holds LxWorkerStat.
  2. Monitoring: Tracks execution performance and recognizes async gaps.
  3. Error Handling: Provides dedicated hooks for synchronous and asynchronous errors.

Usage

final count = 0.lx;
final watcher = LxWorker(count, (v) => print('New value: $v'));
Inheritance

Constructors

LxWorker(LxReactive<T> source, void callback(T value), {dynamic onError(Object error, StackTrace stackTrace)?, dynamic onProcessingError(Object error, StackTrace stackTrace)?, bool? enableMonitoring, String? name})
Creates a new watcher instance.

Properties

callback → void Function(T value)
The callback to execute whenever the source notifies a change.
final
graphDepth int
Returns the current depth in the dependency graph.
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
hasListener bool
Whether there are active listeners.
no setterinherited
id int
A unique runtime identifier for this reactive instance.
finalinherited
isDisposed bool
Whether the reactive object has been closed/disposed.
no setterinherited
isMonitoringEnabled bool
Returns true if this watcher is capturing performance metrics.
no setter
name String?
An optional descriptive name for debugging and profiling.
getter/setter pairinherited
onCancel → void Function()?
Called when the stream is cancelled.
finalinherited
onListen → void Function()?
Called when the stream is listened to.
finalinherited
ownerId String?
The registration key of the owning controller, if applicable.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
source LxReactive<T>
The reactive source being monitored.
final
stream Stream<LxWorkerStat>
A Stream that emits the latest value whenever it updates.
no setterinherited
value LxWorkerStat
The current state of the reactive object.
no setterinherited

Methods

addListener(void listener()) → void
Adds a listener.
inherited
bind(Stream<LxWorkerStat> externalStream) → void
Binds an external stream to this reactive variable.
inherited
call() LxWorkerStat
Functor-like call to get value.
inherited
close() → void
Permanently closes the reactive object and releases all internal resources.
override
dispose() → void
Disposes the notifier.
inherited
mutate(void mutator(LxWorkerStat value)) → void
Mutates the value in place and triggers a refresh.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notify() → void
Alias for refresh.
inherited
refresh() → void
Triggers a notification without changing the value.
inherited
removeListener(void listener()) → void
Removes a listener.
inherited
setValueInternal(LxWorkerStat val, {bool notifyListeners = true}) → void
Internal setter for subclasses (Computed, etc.)
inherited
toString() String
A string representation of this object.
inherited
unbind() → void
Unbinds any external stream.
inherited
updateValue(LxWorkerStat fn(LxWorkerStat val)) → void
Updates the value using a transformation function.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

watchFalse(LxReactive<bool> source, void callback(), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) LxWorker<bool>
Triggers callback only when the boolean source becomes false.
watchStatus<T>(LxReactive<LxStatus<T>> source, {void onIdle()?, void onWaiting()?, void onSuccess(T value)?, void onError(Object error)?, dynamic onProcessingError(Object error, StackTrace stackTrace)?}) LxWorker<LxStatus<T>>
Watches an async source and triggers callbacks for specific state transitions.
watchTrue(LxReactive<bool> source, void callback(), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) LxWorker<bool>
Triggers callback only when the boolean source becomes true.
watchValue<T>(LxReactive<T> source, T targetValue, void callback(), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) LxWorker<T>
Triggers callback only when source matches targetValue.