title: Is there a way to dispatch an action inside redux-observable epic?
body: <p>I am developing a react/redux app that handles event registrations and have to develop an epic that is going to enrol users in different events.</p>
  
  <p>There is currently an epic that handles the process of checking for available seats and I need to perform this action right before I run the "enrol" function.</p>
  
  <p>So I've tried implementing an epic that would do the following:</p>
  
  <pre><code> - Upon recieving an enrolInEvent.request it is going to then
   - Dispatch checkAvailableSeats.request action
   - Wait for checkAvailableSeats.success action
   - Run the 'enrol' async function
   - Dispatch checkAvailableSeats.request again
   - When it gets the checkAvailableSeats.success it is then mapped to enrolInEvent.success
  </code></pre>
  
  <p>Here's the code i've build, but I can't seem to find a way to dispatch the 'checkAvailableSeats.request' in the middle of the Epic. What is going on is the <code>enrolInEvent.request</code> is getting dispatched but then no new actions pop up in the redux-logger.</p>
  
  <pre class="lang-js prettyprint-override"><code>// tl;dr:
  // enrolInEvent.request -&gt; checkAvailableSeats -&gt; enrol -&gt; checkAvailableSeats again -&gt; enrolInEvent.success
  
  export const enrolInEventEpic: EventMetadataEpic =
    (action$, state$, { eventService }) =&gt;
      action$.pipe(
        filter(isActionOf(enrolInEvent.request)),
        map(checkAvailableSeats.request), // I would need to dispatch this
        switchMap(() =&gt;
          action$.pipe(  // Then scan the action observable for a success response
            filter(isActionOf(checkAvailableSeats.success)),
            take(1),
            switchMap(() =&gt;
              from(eventService.enrolInCurrentEvent(
                state$.value.eventForm.eventStatus,
                state$.value.infrastructure.pageId,
              ))
              .pipe(
                map(checkAvailableSeats.request), // And dispatch here again
                switchMap(() =&gt;
                  action$.pipe(
                    filter(isActionOf(checkAvailableSeats.success)),
                    take(1),
                    map(checkStatus =&gt; enrolInEvent.success(checkStatus.payload)),
                    catchError((message: string) =&gt; of(enrolInEvent.failure(message))),
                  )
                )
              )
            )
          )
        )
      );
  </code></pre>
  
  <p>I was under the impression that mapping to an action in the middle of the epic would dispatch it, but this is not true it seems. What's the simplest way to achieve the behaviour I need using the redux-observable?</p>