redux-perf-middleware
Version:
Measure the time that actions needs to change the state
96 lines (66 loc) • 2.19 kB
Markdown
//badge.fury.io/js/redux-perf-middleware.svg)](https://badge.fury.io/js/redux-perf-middleware) []()
[]()
Measure the time that the actions need to change the state
[](https://nodei.co/npm/redux-perf-middleware/)
```javascript
import perflogger from 'redux-perf-middleware';
const createStoreWithMiddleware = applyMiddleware( perflogger )(createStore);
const store = createStoreWithMiddleware(reducer);
```
This project adheres to [Semantic Versioning](http://semver.org/).
**Dumb Reducer**
```javascript
function slow(){
let sum;
for(let i = 0; i< 10000; i++){
for(let j = 0; j< 10000; j++)
{
sum = i+j;
}
}
return sum;
}
export const Elements = function ( state = {}, action ) {
switch ( action.type )
{
case 'SLOW':
return slow();
default:
return state;
}
};
```
**Dumb Component**
```javascript
import React, { Component } from 'react';
import { connect } from 'react-redux';
class Input extends Component {
/**
* Renders the markup for the topbar
*/
render() {
const { dispatch } = this.props;
return (
<input onKeyDown={ () => dispatch({ type: 'SLOW' })} />
);
}
};
const selector = function( { default: elements } ){
return elements;
}
export default connect(selector)( Input );
```
On every keydown **Redux** will dispatch the action with type SLOW, and in the console the middleware will log something like:

Or check the [sample app](https://github.com/AvraamMavridis/redux-perf-middleware/tree/master/app)
Feel free to open issues, make suggestions or send PRs.
This project adheres to the Contributor Covenant [code of conduct](http://contributor-covenant.org/). By participating, you are expected to uphold this code.
Twitter: [@avraamakis](https://twitter.com/avraamakis)
MIT
[![npm version](https: