Skip to content

A Redux store enhancer which uses User Timing API to profile redux actions and time spent on notifying store listeners

License

Notifications You must be signed in to change notification settings

bhovhannes/redux-profiler

Folders and files

NameName
Last commit message
Last commit date
Mar 15, 2025
Dec 2, 2021
Nov 27, 2020
Sep 24, 2018
Sep 24, 2018
Nov 24, 2021
Sep 24, 2018
Sep 24, 2018
Feb 20, 2021
Jan 27, 2024
Sep 24, 2018
Nov 27, 2020
Nov 27, 2020
Nov 27, 2020
Feb 20, 2021
Mar 15, 2025
Mar 15, 2025
Nov 12, 2022

Repository files navigation

redux-profiler

NPM version NPM downloads MIT License Coverage

A Redux store enhancer which uses User Timing API to profile Redux actions and time spent on notifying store listeners

How to install

npm install redux-profiler --save

Usage

import { createStore } from 'redux'
import profileStore from 'redux-profiler'

function todos(state = [], action) {
    switch (action.type) {
        case 'ADD_TODO':
            return state.concat([action.text])
        default:
            return state
    }
}const store = createStore(todos, ['Use Redux'], profileStore())

You can also combine it with Redux middleware:

import { createStore, compose } from 'redux'
import { thunk } from 'redux-thunk'
import profileStore from 'redux-profiler'

function todos(state = [], action) {
    switch (action.type) {
        case 'ADD_TODO':
            return state.concat([action.text])
        default:
            return state
    }
}const store = createStore(
    todos,
    ['Use Redux'],
    compose(
        profileStore(),
        thunk
    )
)

or if you have multiple middlewares:

import { createStore, applyMiddleware, compose } from 'redux'
import { thunk } from 'redux-thunk'
import profileStore from 'redux-profiler'

function todos(state = [], action) {
    switch (action.type) {
        case 'ADD_TODO':
            return state.concat([action.text])
        default:
            return state
    }
}

/**
 * Logs all actions and states after they are dispatched.
 */
const logger = store => next => action => {
    console.group(action.type)
    console.info('dispatching', action)
    let result = next(action)
    console.log('next state', store.getState())
    console.groupEnd()
    return result
}const store = createStore(
    todos,
    ['Use Redux'],
    compose(
        profileStore(),
        applyMiddleware(
            thunk,
            logger
        )
    )
)

License

MIT (http://www.opensource.org/licenses/mit-license.php)