Connect<T, S extends T> class

A highly powerful connector utility that allows you to dynamically stream and pipe multiple asynchronous streams directly into a single reactive Signal.

The concept is inspired by Angular Signals integration with RxJS streams.

Start with an existing mutable Signal and call connect(signal) to create a connector instance.

1. Chaining Streams

You can bind multiple streams to feed the same destination signal. The connector will handle the subscription management for all streams seamlessly.

final counter = signal(0);
final connector = connect(counter);

final fastStream = Stream.periodic(Duration(seconds: 1), (i) => i);
final slowStream = Stream.periodic(Duration(seconds: 5), (i) => i * 10);

// Values from both streams will be piped into the counter signal!
connector.from(fastStream).from(slowStream);

2. The Shift Operator (<<)

For a more concise and beautiful visual flow, you can use the shift operator (<<) to chain streams:

final s = signal(0);
final c = connect(s);

c << fastStream << slowStream;

3. Lifecycle and Disposal

To avoid memory leaks, make sure to dispose the connector when it is no longer needed. Disposing the connector will automatically cancel all underlying active stream subscriptions.

connector.dispose(); // Cancels all stream subscriptions safely

Constructors

Connect(Signal<T> signal)
Connects a Stream to a Signal.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
signal Signal<T>
Internal signal to connect to.
final

Methods

dispose() → void
Cancels all subscriptions.
from(Stream<S> source, {bool? cancelOnError, Function? onError, Function? onDone, void onValue(T)?}) Connect<T, S>
Connects a Stream to a Signal.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator <<(Stream<S> source) Connect<T, S>
Synonym for from(Stream<T> source)
operator ==(Object other) bool
The equality operator.
inherited