LxStream<T> class

A reactive wrapper for a Stream.

LxStream tracks the latest state (LxStatus) of a source stream and supports lazy subscription. The underlying stream is only listened to when the LxStream itself has active observers or listeners.

Key Features:

// Example usage:

final counter = Stream.periodic(Duration(seconds: 1), (i) => i).lx;

// UI automatically rebuilds on new events
LWatch(() => Text('${counter.value.data}'));
Inheritance
Available extensions

Constructors

LxStream(Stream<T> stream, {T? initial, LxStreamCompletionPolicy completionPolicy = LxStreamCompletionPolicy.close})
Creates an LxStream bound to the given stream. Note: If the stream is a single-subscription stream, it cannot be safely re-listened to after losing all subscribers. Prefer using LxStream.defer for single-subscription streams.
factory
LxStream.defer(Stream<T> factory(), {T? initial, LxStreamCompletionPolicy completionPolicy = LxStreamCompletionPolicy.close})
Creates an LxStream that lazily generates its underlying stream using factory whenever it becomes active. This is strictly required for safely recreating single-subscription operations like .map when an LxStream re-activates.
factory
LxStream.idle({T? initial, LxStreamCompletionPolicy completionPolicy = LxStreamCompletionPolicy.close})
Creates an LxStream in an LxIdle state.
factory

Properties

completionPolicy LxStreamCompletionPolicy
Behavior applied when the current source stream completes.
final
computedValue → T

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Alias for requireValue.
no setter
equals bool Function(LxStatus<T> previous, LxStatus<T> current)?
Custom equality function. When null, uses ==.
finalinherited
errorOrNull Object?

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Returns the current error if the status is LxError, otherwise 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 setteroverride
hasValue bool

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Alias for isSuccess.
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<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Returns true if the status is LxError.
no setter
isIdle bool

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Returns true if the status is LxIdle.
no setter
isLoading bool

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Alias for isWaiting.
no setter
isSensitive bool
Whether this reactive object contains sensitive data.
getter/setter pairinherited
isSuccess bool

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Returns true if the status is LxSuccess.
no setter
isWaiting bool

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Returns true if the status is LxWaiting.
no setter
lastValue → T?

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Returns the LxStatus.lastValue (the most recent successful value).
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<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Force-retrieves the current value if the status is LxSuccess.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stackTraceOrNull StackTrace?

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Returns the stack trace if the status is LxError, otherwise null.
no setter
status LxStatus<T>
Returns the current LxStatus of the stream.
no setter
stream Stream<LxStatus<T>>
A Stream that emits the latest value whenever it updates.
no setterinherited
value LxStatus<T>
The current state of the reactive object.
no setterinherited
valueOrNull → T?

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Returns the current value if the status is LxSuccess, otherwise null.
no setter
valueStream Stream<T>
Returns the raw stream of values, unwrapped from LxStatus.
no setter
wait Future<T>

Available on LxReactive<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Returns a Future that completes when the operation reaches a terminal state.
no setter

Methods

addListener(void listener()) → void
Adds a listener.
inherited
asyncMap<E>(FutureOr<E> convert(T event)) LxStream<E>
Asynchronously transforms each data event.
call() LxStatus<T>
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
distinct([bool equals(T previous, T next)?]) LxStream<T>
Skips duplicate events.
expand<R>(Iterable<R> convert(T element)) LxStream<R>
Expands each event into an iterable of events.
fold<R>(R initialValue, R combine(R previous, T element)) LxFuture<R>
Folds the stream into a single LxFuture result.
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<LxStatus<T>>, provided by the LxStatusReactiveExtensions extension

Specialized listen for async status that allows handling individual states.
map<R>(R convert(T event)) LxStream<R>
Transforms each data event with convert.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notify() → void
Alias for refresh.
inherited
reduce(T combine(T previous, T element)) LxFuture<T>
Reduces the stream to a single value using combine.
refresh() → void
Triggers a notification without changing the value.
inherited
removeListener(void listener()) → void
Removes a listener.
inherited
restart(Stream<T> stream) → void
Re-executes the stream operation with a new stream. This binds to a static stream instance. See restartDeferred for single-subscription streams.
restartDeferred(Stream<T> factory()) → void
Re-executes the stream operation and registers a new factory for future re-activations.
select<R>(R selector(LxStatus<T> 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.
override
transform<R>(Stream<R> transformer(Stream<LxStatus<T>> stream)) LxStream<R>
Transforms the status sequence into a new LxStream.
inherited
where(bool test(T event)) LxStream<T>
Filters events based on test.

Operators

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