1.0.1 • Published 7 years ago

radhoc v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Radhoc

Build Status codecov

Add an ad hoc case to your Redux reducer.

Install

npm install --save-dev radhoc

or

yarn add radhoc -D

Usage

import { createStore } from 'redux'
import reducer from './reducers'
import radhoc from 'radhoc'

const store = createStore(radhoc(reducer))

export default store

Then, 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'