reduceHandlers
Allows you to glue handlers together to run in sequence. It's useful for responseHandlers
and transformers
. Inspired by reduce-reducers.
Similar to reduceReducers
, reducerHandlers
simply passes the previous return value to the next handler in the sequence. When used with handlers created by handleResponseActions
or handleTransformerActions
, only the functions matching the action type will be executed.
reduceHandlers
is forresponseHandlers
andtransformers
.- If you are trying to join
requestCreators
together, trysomeRequestHandlers
. - If you are trying to join
responders
together, trysomeResponders
.
Usage
import createFetchAction, { reduceHandlers } from 'fetch-actions'
import 'fetch-everywhere'
import logHandler from './responseHandlers/logHandler'
import errorHandler from './responseHandlers/errorHandler'
import blueberryTransformer from './transformers/blueberryTransformer'
import carrotTransformer from './transformers/carrotTransformer'
const fetchAction = createFetchAction({
fetch,
responseHandler: reduceHandlers(
logHandler, // <-- logs all responses
errorHandler // <-- fields error responses
),
transformer: reduceHandlers(
blueberryTransformer, // <-- handles blueberry actions
carrotTransformer // <-- handles carrot actions
)
})
export fetchAction