triggerOnActionV2<T> method

void triggerOnActionV2<T>(
  1. ActionV2<T> action, [
  2. FutureOr onAction(
    1. T payload
    )?
])
inherited

A convenience method for listening to an action and triggering automatically once the callback for said action has completed.

If onAction is provided, it will be called every time action is dispatched. If onAction returns a Future, trigger will not be called until that future has resolved.

If the Store has been disposed, this method throws a StateError.

Implementation

void triggerOnActionV2<T>(ActionV2<T> action,
    [FutureOr<dynamic> onAction(T payload)?]) {
  if (isOrWillBeDisposed) {
    throw StateError('Store of type $runtimeType has been disposed');
  }
  manageActionSubscription(action.listen((payload) async {
    if (onAction != null) {
      await onAction(payload);
    }
    trigger();
  }));
}