LxComputed<T> class
A value derived from other reactive objects.
LxComputed automatically tracks its dependencies and re-evaluates when they change. Calculations are lazy and memoized.
// Example usage:
final firstName = 'John'.lx;
final lastName = 'Doe'.lx;
// Updates only when firstName or lastName changes
final fullName = LxComputed(() => '${firstName()} ${lastName()}');
- Inheritance
-
- Object
- LevitReactiveNotifier
- LxBase<
T> - LxComputed
- Available extensions
Constructors
- LxComputed(T _compute(), {bool equals(T previous, T current)?, bool staticDeps = false, bool eager = false, String? name})
- Creates a synchronous computed value.
Properties
- computedValue → T
-
Available on LxReactive<
Alias for requireValue.LxStatus< , provided by the LxStatusReactiveExtensions extensionT> >no setter - equals → bool Function(T previous, T current)?
-
Custom equality function. When null, uses
==.finalinherited - errorOrNull → Object?
-
Available on LxReactive<
Returns the current error if the status is LxError, otherwiseLxStatus< , provided by the LxStatusReactiveExtensions extensionT> >null.no setter - 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
- hasValue → bool
-
Available on LxReactive<
Alias for isSuccess.LxStatus< , provided by the LxStatusReactiveExtensions extensionT> >no setter - id → int
-
A unique runtime identifier for this reactive instance.
finalinherited
- isDisposed → bool
-
Whether the reactive object has been closed/disposed.
no setterinherited
- isError → bool
-
Available on LxReactive<
ReturnsLxStatus< , provided by the LxStatusReactiveExtensions extensionT> >trueif the status is LxError.no setter - isIdle → bool
-
Available on LxReactive<
ReturnsLxStatus< , provided by the LxStatusReactiveExtensions extensionT> >trueif the status is LxIdle.no setter - isLoading → bool
-
Available on LxReactive<
Alias for isWaiting.LxStatus< , provided by the LxStatusReactiveExtensions extensionT> >no setter - isSensitive ↔ bool
-
Whether this reactive object contains sensitive data.
getter/setter pairinherited
- isSuccess → bool
-
Available on LxReactive<
ReturnsLxStatus< , provided by the LxStatusReactiveExtensions extensionT> >trueif the status is LxSuccess.no setter - isWaiting → bool
-
Available on LxReactive<
ReturnsLxStatus< , provided by the LxStatusReactiveExtensions extensionT> >trueif the status is LxWaiting.no setter - lastValue → T?
-
Available on LxReactive<
Returns the LxStatus.lastValue (the most recent successful value).LxStatus< , provided by the LxStatusReactiveExtensions extensionT> >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
- requireValue → T
-
Available on LxReactive<
Force-retrieves the current value if the status is LxSuccess.LxStatus< , provided by the LxStatusReactiveExtensions extensionT> >no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stackTraceOrNull → StackTrace?
-
Available on LxReactive<
Returns the stack trace if the status is LxError, otherwiseLxStatus< , provided by the LxStatusReactiveExtensions extensionT> >null.no setter -
stream
→ Stream<
T> -
A Stream that emits the latest value whenever it updates.
no setterinherited
- value → T
-
The current state of the reactive object.
no setteroverride
- valueOrNull → T?
-
Available on LxReactive<
Returns the current value if the status is LxSuccess, otherwiseLxStatus< , provided by the LxStatusReactiveExtensions extensionT> >null.no setter -
wait
→ Future<
T> -
Available on LxReactive<
Returns a Future that completes when the operation reaches a terminal state.LxStatus< , provided by the LxStatusReactiveExtensions extensionT> >no setter
Methods
-
addListener(
void listener()) → void -
Adds a listener.
inherited
-
call(
) → T -
Functor-like call to get value.
inherited
-
close(
) → void -
Permanently closes the reactive object and releases all internal resources.
inherited
-
dispose(
) → void -
Disposes the notifier.
inherited
-
listen(
void callback(T value)) → LxWorker< T> -
Available on LxReactive<
Attaches a listener to this reactive value.T> , provided by the LxReactiveWatchExtensions extension -
listen(
void onSuccess(T value), {void onIdle()?, void onWaiting()?, void onError(Object error)?, dynamic onProcessingError(Object error, StackTrace stackTrace)?}) → LxWorker< LxStatus< T> > -
Available on LxReactive<
Specialized listen for async status that allows handling individual states.LxStatus< , provided by the LxStatusReactiveExtensions extensionT> > -
maybeNotifyGraphChange(
Iterable< LxReactive> reactives) → void -
Notifies observers of a graph change only if the dependencies have actually changed.
inherited
-
named(
String name) → R -
Available on R, provided by the LxNamingExtension extension
assigns a debugnameto this reactive object. -
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.
override
-
register(
String ownerId) → R -
Available on R, provided by the LxNamingExtension extension
Links this reactive object to an owner ID. -
removeListener(
void listener()) → void -
Removes a listener.
inherited
-
select<
R> (R selector(T value)) → LxComputed< R> -
Creates a specific selection of the state that only updates when the selected value changes.
inherited
-
sensitive(
) → R -
Available on R, provided by the LxNamingExtension extension
Marks this object as containing sensitive data (redacted in logs). -
toString(
) → String -
A string representation of this object.
override
-
transform<
R> (Stream< R> transformer(Stream<T> stream)) → LxStream<R> -
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
async<
T> (Future< T> compute(), {bool equals(T previous, T current)?, bool showWaiting = false, bool staticDeps = false, T? initial, String? name, LxAsyncConcurrency concurrency = LxAsyncConcurrency.latest}) → LxAsyncComputed<T> - Creates an asynchronous computed value.
-
deferred<
T> (T compute(), {bool equals(T previous, T current)?, bool showWaiting = false, bool staticDeps = false, T? initial, String? name, LxAsyncConcurrency concurrency = LxAsyncConcurrency.latest}) → LxAsyncComputed< T> - Creates a deferred computation that runs in a microtask and returns LxStatus.