Sawtaytoes
9/30/2018 - 11:02 AM

Managing Notifications

We're able to show a notification and both allow it to be closed and time out at the same time.

const showErrorNotificationEpic = (
  action$,
) => (
  action$
  .pipe(
    ofType(SHOW_ERROR_NOTIFICATION),
    switchMap(() => (
      race(
        (
          timer(5000)
        ),
        (
          action$
          .pipe(
            ofType(HIDE_ERROR_NOTIFICATION),
            take(1),
          )
        ),
      )
    )),
    filter(({ type }) => (
      type !== HIDE_ERROR_NOTIFICATION
    )),
    map(hideErrorNotification),
  )
)