redux-count-dispatch-middleware

0.0.7 • Public • Published

redux-count-dispatch-middleware

Build Status Build status

npm (scoped) downloads Dependency Status devDependency Status

License: MIT

A Redux middleware to count dispatch.

install

$ npm i redux-count-dispatch-middleware -S
# or 
$ yarn add redux-count-dispatch-middleware

usage

import { createStore, applyMiddleware, combineReducers } from 'redux'
import {
  createCountDispatchMiddleware,
  countDispatchReducer,
} from 'redux-count-dispatch-middleware'
 
/**
 * matcher
 * @param  {string} type   type
 * @param  {object} action action
 * @return {string|false}  counter key or false for no count
 */
const filter = (type, action) =>
  type === 'noop' ? false : 'dispatched ' + type
 
const initialState = {}
 
const middlewares = [createCountDispatchMiddleware({ filter })]
const store = createStore(
  combineReducers({
    dispatchCounter: countDispatchReducer,
  }),
  initialState,
  applyMiddleware(...middlewares)
)
 
store.dispatch({ type: 'hello' })
store.dispatch({ type: 'hello' })
store.dispatch({ type: 'world' })
store.dispatch({ type: 'noop' })
store.getState().dispatchCounter // { 'dispatched hello': 2, 'dispatched world': 1 }

development

$ git clone https://github.com/kamataryo/redux-count-dispatch-middleware.git
cd redux-count-dispatch-middleware
$ npm test

Package Sidebar

Install

npm i redux-count-dispatch-middleware

Weekly Downloads

0

Version

0.0.7

License

MIT

Unpacked Size

120 kB

Total Files

17

Last publish

Collaborators

  • kamataryo