1.0.1 • Published 9 years ago
radhoc v1.0.1
Radhoc
Add an ad hoc case to your Redux reducer.
Install
npm install --save-dev radhocor
yarn add radhoc -DUsage
import { createStore } from 'redux'
import reducer from './reducers'
import radhoc from 'radhoc'
const store = createStore(radhoc(reducer))
export default storeThen, you dispatch any action with an update key.
store.dispatch({
type: 'RADHOC',
update: {
rad: 'hoc'
}
})What It Does
Radhoc is a higher-order function for Redux reducers. It listens for a specified action.type and then returns the next state (more details below). If the action.type is anything else, it simply returns the reducer it takes as an argument, passing state and action to it.
API
radhoc(reducer, name)The radhoc() function takes two arguments, a reducer and an optional name. If a name is passed, it is uppercased and appended to the default action.type.
radhoc(reducer) // action.type === 'RADHOC'
// Passing in a name argument
radhoc(reducer, 'root') // action.type === 'RADHOC_ROOT'