StatusRelay<TSourceBloc extends JuiceBloc<TSourceState> , TDestBloc extends JuiceBloc<BlocState> , TSourceState extends BlocState> class
Relays StreamStatus changes from one bloc to another.
Deprecated — removed in 3.0.0. Use Reaction with JuiceBloc.react.
A reaction sees state and nothing else, so one use of StatusRelay has
NO drop-in port: mapping a waiting or failure STATUS to an event. Put
what the destination needs in a state field of the source and react to
that, or — when it is the outcome of one operation — have its caller
take it as a typed result (sendForResult).
Similar to StateRelay, but provides access to the full StreamStatus including waiting, failure, and canceling states. Use this when you need to react differently based on the status type.
Example
final relay = StatusRelay<AuthBloc, ProfileBloc, AuthState>(
toEvent: (status) => status.when(
updating: (state, _, __) => state.isAuthenticated
? LoadProfileEvent(userId: state.userId!)
: ClearProfileEvent(),
waiting: (_, __, ___) => ProfileLoadingEvent(),
failure: (_, __, ___) => ClearProfileEvent(),
canceling: (_, __, ___) => ClearProfileEvent(),
),
);
- Annotations
-
- @Deprecated('Use Reaction with JuiceBloc.react. A reaction sees state only: a ' 'StatusRelay that maps a waiting or failure status to an event has no ' 'drop-in port. Put what the destination needs in a state field of the ' 'source and react to that, or have the caller of the operation take its ' 'outcome as a typed result (sendForResult). Removed in 3.0.0.')
Constructors
-
StatusRelay({required EventBase toEvent(StreamStatus<
TSourceState> status), bool when(StreamStatus<TSourceState> status)?, Object? sourceScope, Object? destScope, BlocDependencyResolver? resolver}) - Creates a StatusRelay to connect two blocs via StreamStatus changes.
Properties
- destScope → Object?
-
Optional scope key for resolving destination bloc.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isClosed → bool
-
Whether this relay has been closed.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sourceScope → Object?
-
Optional scope key for resolving source bloc.
final
-
toEvent
→ EventBase Function(StreamStatus<
TSourceState> status) -
Function that transforms source StreamStatus into an event for destination bloc.
final
-
when
→ bool Function(StreamStatus<
TSourceState> status)? -
Optional predicate to filter which status changes should be relayed.
final
Methods
-
close(
) → Future< void> - Closes the relay and releases all resources.
-
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 ==(
Object other) → bool -
The equality operator.
inherited