LxWorker<T> class
A reactive observer for side-effects.
LxWorker executes a callback whenever a source reactive changes. Unlike LxComputed, it does not produce a new value but performs an action (e.g., logging, navigation, saving to DB).
// Example usage:
final count = 0.lx;
// Log every change
final worker = LxWorker(count, (v) => print('Changed: $v'));
- Inheritance
-
- Object
- LevitReactiveNotifier
- LxBase<
LxWorkerStat> - LxWorker
Constructors
-
LxWorker(LxReactive<
T> source, FutureOr<void> callback(T value), {dynamic onError(Object error, StackTrace stackTrace)?, dynamic onProcessingError(Object error, StackTrace stackTrace)?, bool? enableMonitoring, String? name, LxAsyncConcurrency concurrency = LxAsyncConcurrency.latest}) - Creates a new watcher instance.
Properties
-
callback
→ FutureOr<
void> Function(T value) -
The callback to execute whenever the source notifies a change.
final
- concurrency → LxAsyncConcurrency
-
Admission policy for asynchronous callback executions.
final
- equals → bool Function(LxWorkerStat previous, LxWorkerStat current)?
-
Custom equality function. When null, uses
==.finalinherited - 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
trueif this watcher is capturing performance metrics.no setter - isSensitive ↔ bool
-
Whether this reactive object contains sensitive data.
getter/setter pairinherited
- 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
-
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
-
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
-
select<
R> (R selector(LxWorkerStat value)) → LxComputed< R> -
Creates a specific selection of the state that only updates when the selected value changes.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
debounce<
T> (LxReactive< T> source, Duration duration, void callback(T value), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) → LxWorker<T> -
Triggers
callbackafterdurationhas passed without new source updates. -
onChangeDistinct<
T> (LxReactive< T> source, void callback(T value), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) → LxWorker<T> -
Triggers
callbackwhensourceemits a value distinct from the previous one. -
onFalling(
LxReactive< bool> source, void callback(), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) → LxWorker<bool> -
Triggers
callbackonly whensourcetransitions fromtruetofalse. -
onRising(
LxReactive< bool> source, void callback(), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) → LxWorker<bool> -
Triggers
callbackonly whensourcetransitions fromfalsetotrue. -
throttle<
T> (LxReactive< T> source, Duration duration, void callback(T value), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) → LxWorker<T> -
Triggers
callbackimmediately, then ignores updates forduration. -
watchFalse(
LxReactive< bool> source, void callback(), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) → LxWorker<bool> -
Triggers
callbackwhen a booleansourcebecomesfalse. -
watchStatus<
T> (LxReactive< LxStatus< source, {void onIdle()?, void onWaiting()?, void onSuccess(T value)?, void onError(Object error)?, dynamic onProcessingError(Object error, StackTrace stackTrace)?}) → LxWorker<T> >LxStatus< T> > -
Triggers callbacks based on status changes of an async
source. -
watchTrue(
LxReactive< bool> source, void callback(), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) → LxWorker<bool> -
Triggers
callbackwhen a booleansourcebecomestrue. -
watchValue<
T> (LxReactive< T> source, T targetValue, void callback(), {dynamic onProcessingError(Object error, StackTrace stackTrace)?}) → LxWorker<T> -
Triggers
callbackwhensourceequalstargetValue.