https://github.com/kamataryo/redux-count-dispatch-middleware
https://github.com/kamataryo/redux-count-dispatch-middleware
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kamataryo/redux-count-dispatch-middleware
- Owner: kamataryo
- Created: 2018-06-15T04:19:40.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-16T13:25:00.000Z (about 7 years ago)
- Last Synced: 2025-02-21T09:39:03.627Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 47.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# redux-count-dispatch-middleware
[](https://travis-ci.org/kamataryo/redux-count-dispatch-middleware)
[](https://ci.appveyor.com/project/kamataryo/redux-count-dispatch-middleware)[](https://www.npmjs.com/package/redux-count-dispatch-middleware)
[](https://www.npmjs.com/package/redux-count-dispatch-middleware)
[](https://david-dm.org/kamataryo/redux-count-dispatch-middleware)
[](https://david-dm.org/kamataryo/redux-count-dispatch-middleware#info=devDependencies)[](https://opensource.org/licenses/MIT)
A Redux middleware to count dispatch.
## install
```shell
$ npm i redux-count-dispatch-middleware -S
# or
$ yarn add redux-count-dispatch-middleware
```## usage
```javascript
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 ' + typeconst 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
```shell
$ git clone https://github.com/kamataryo/redux-count-dispatch-middleware.git
$ cd redux-count-dispatch-middleware
$ npm test
```