0.0.7 • Published 6 years ago

redux-count-dispatch-middleware v0.0.7

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

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
0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago