EventHandler<TSaga extends Saga, TEvent, TState> class
Defines how to handle a specific event type.
Built using a fluent API:
when<OrderCreated>()
.where((e) => e.amount > 100)
.set((saga, e) => saga.orderId = e.id)
.execute(NotifyActivity())
.transitionTo(OrderStatus.created)
Constructors
-
EventHandler({EventFilter<
TEvent> ? filter}) - Creates a new event handler.
Properties
-
actions
→ List<
SagaAction< TSaga, TEvent> > -
Get all actions.
no setter
-
activities
→ List<
Activity< TSaga, TEvent> > -
Get all activities.
no setter
- eventType → Type
-
The event type this handler handles.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scheduleEventType → Type?
-
Event type to schedule (if any).
no setter
- scheduleTimeout → Duration?
-
Timeout to schedule (if any).
no setter
-
setters
→ List<
SagaSetter< TSaga, TEvent> > -
Get all setters.
no setter
- shouldFinalize → bool
-
Whether this handler finalizes the saga.
no setter
-
unscheduleTypes
→ List<
Type> -
Get types to unschedule.
no setter
Methods
-
canHandle(
dynamic event) → bool - Check if this handler can handle the given event.
-
execute(
Activity< TSaga, TEvent> activity) → EventHandler<TSaga, TEvent, TState> - Execute an activity (with optional compensation).
-
executeWith(
TSaga saga, dynamic event, Scheduler scheduler, dynamic previousState) → Future< void> - Execute all setters, activities, and actions with the given saga and event. This method maintains type safety by executing with the proper TEvent type.
-
finalize(
) → EventHandler< TSaga, TEvent, TState> - Mark the saga as finalized after this handler.
-
getTargetState(
BehaviorContext< TSaga, TEvent> context) → TState? - Get the target state for transition.
-
getTargetStateWith(
TSaga saga, dynamic event, Scheduler scheduler, dynamic previousState) → TState? - Get the target state for transition (uses dynamic event cast internally).
-
matches(
TEvent event) → bool - Check if this handler matches the event.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
schedule<
TTimeoutEvent> (Duration timeout) → EventHandler< TSaga, TEvent, TState> - Schedule a timeout event.
-
set(
SagaSetter< TSaga, TEvent> setter) → EventHandler<TSaga, TEvent, TState> - Set saga properties from the event.
-
then(
SagaAction< TSaga, TEvent> action) → EventHandler<TSaga, TEvent, TState> - Execute a custom action.
-
toString(
) → String -
A string representation of this object.
inherited
-
transitionTo(
TState state) → EventHandler< TSaga, TEvent, TState> - Transition to a specific state.
-
transitionToState(
StateResolver< TSaga, TEvent, TState> resolver) → EventHandler<TSaga, TEvent, TState> - Transition to a dynamically determined state.
-
unschedule<
TScheduledEvent> () → EventHandler< TSaga, TEvent, TState> - Cancel a previously scheduled event.
-
where(
EventFilter< TEvent> filter) → EventHandler<TSaga, TEvent, TState> - Filter events by a condition.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited