call method

  1. @override
void call(
  1. Store<State> store,
  2. dynamic action,
  3. NextDispatcher next
)

A Middleware function that intercepts a dispatched action

Implementation

@override
void call(Store<State> store, dynamic action, NextDispatcher next) {
  if (!_isSubscribed) {
    _epics.stream
        .switchMap<dynamic>((epic) => epic(_actions.stream, EpicStore(store)))
        .listen(store.dispatch);

    _epics.add(_epic);

    _isSubscribed = true;
  }

  next(action);

  if (supportAsyncGenerators) {
    // Future.delayed is an ugly hack to support async* functions.
    //
    // See: https://github.com/dart-lang/sdk/issues/33818
    Future.delayed(Duration.zero, () {
      _actions.add(action);
    });
  } else {
    _actions.add(action);
  }
}