const notify = (events) => ({ dispatch }) => next => action => {
  const returnValue = next(action);
  events.forEach( event => {
    if (event.catch.indexOf(action.type) !== -1) {
      dispatch(event.dispatch());
    }
  });
  return returnValue;
};

export default notify;

const notify = (events) => ({ dispatch }) => next => action => {
  const returnValue = next(action);
  events.forEach( event => {
    if (event.catch.indexOf(action.type) !== -1) {
      if (event.dispatch instanceof Function) dispatch(event.dispatch());
      else if (event.dispatch instanceof Array) {
        event.dispatch.forEach( fn => setTimeout(() => { dispatch(fn()) }, 0) );
      }
      else throw new Error('Expected dispatch value to be a function or an array of functions.');
    }
  });
  return returnValue;
};

export default notify;

Allow to dispatch an array of actions in parallel.
Allow to dispatch an array of actions in parallel.
