applyAsyncEpics

A function that takes a stream of Epics and returns a store enhancer. for dynamic Epic injection.

Arguments

Returns

(Function): (Function): A store enhancer that is used as an argument for createStore. to enable dynamic Epic injection.

Example: Setting-up The dynamic Epic Injection

./src/epics

import { createRootEpic } from '@react-observatory/inject-epic'

const logger = action$ =>
  action$
    .ofType('Up')
    .do(console.log)
    .ignoreElements()

const { epic$, rootEpic } = createRootEpic(logger)

export { epic$, rootEpic }

./src/configureStore

import { createStore, compose, applyMiddleware } from 'redux'
import { applyAsyncEpics } from '@react-observatory/inject-epic'
import { createEpicMiddleware } from 'redux-observable'
import reducers from './reducers'
import { rootEpic, epic$ } from './epics'

const epicMiddleware = createEpicMiddleware(rootEpic)

export default function configureStore(initialState = {}) {
  const store = createStore(
    reducers,
    initialState,
    compose(
      applyAsyncEpics(epic$),
      applyMiddleware(epicMiddleware)
    )
  )

  return store
}

Last updated