cancelAll<TAction extends Object?> function

Rule cancelAll<TAction extends Object?>([
  1. bool predicate(
    1. ActionBase
    )?
])

cancel all action rule

Implementation

Rule cancelAll<TAction extends Object?>(
    [bool Function(ActionBase)? predicate]) {
  return (dispatcher, next) {
    if (predicate != null) {
      // cancel all actions that matches a predicate
      for (final other in dispatcher.dispatching) {
        if (predicate(other.action) == true) {
          other.cancel();
        }
      }
    } else if (null is TAction) {
      // cancel all dispatching actions
      for (final other in dispatcher.dispatching) {
        other.cancel();
      }
    } else {
      for (final other in dispatcher.dispatching) {
        if (other.action is TAction) {
          other.cancel();
        }
      }
    }
    next();
  };
}