npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redux-usage-report

v1.3.1

Published

A Redux devtools monitor focused on your app's usage of the Redux store

Downloads

14

Readme

Redux Usage Report

This library tracks the way your app is actually using the data in your Redux store. By setting up the monitor in devtools you can see a live view of when different parts of your store are accessed:

Redux usage monitor in action

If you want to know exactly when a certain value is being accessed, you can set a breakpoint to explore the call stack when the app touches that particular value.

Demo

Try it out on the TodoMVC app here.

1. Install the required libs

yarn install redux-usage-report redux-devtools redux-devtools-dock-monitor

2. Create the DevTools component

DevTools.js

import React from 'react';
import { createDevTools } from 'redux-devtools';
import DockMonitor from 'redux-devtools-dock-monitor';
import { UsageMonitor } from 'redux-usage-report';

export default createDevTools(
  <DockMonitor toggleVisibilityKey='ctrl-h'
               changePositionKey='ctrl-q'
               changeMonitorKey='ctrl-m'>
    <UsageMonitor />
  </DockMonitor>
);

3. Add the generateReduxReport and the DevTools.instrument store enhancers

Make sure to put the DevTools.instrument() call last in the order of composed functions.

configureStore.js

import { createStore, applyMiddleware, compose } from "redux"
import rootReducer from "platform/state/reducers"

import generateReduxReport from "redux-usage-report"
import DevTools from '../DevTools';

const enhancer = compose(
  generateReduxReport(),
  // DevTools.instrument() should go last
  DevTools.instrument()
  )

const store = createStore(rootReducer, initialState, enhancer)

3. Render <DevTools/> into the app

The easiest way to do this is just render the <DevTools/> component in your App component.

Read more about setting up redux devtools in the official documentation.

Please make sure to only include the devtools for your development build!

How to use it

The json view of your store will show the parts that have been not accessed at reduced opacity, as well as an estimate of the total percentage of your store that has been used so far by your app.

Set a breakpoint

You can set a breakpoint by doing shift + click on any key in the json view. The next time the key is accessed, the debugger will stop execution. Feel free to reload the page, the breakpoint will persist until you remove it by holding shift and clicking it again.

Setting a breakpoint

How it works

The generateReduxReport enhancer wraps the store in a proxy, so that each object access can be tracked.

It tries to be smart about ignoring object accesses that come from outside your app's code. For instance, if you're also using the persistStore Devtools plugin, even though that plugin accesses every key in your store, you shouldn't see that reflected in the Usage Report monitor. The monitor attempts to filter out object access that originates in any module located in the node_modules folder or from a browser extension. This filtering logic only works in Chrome, or failing that, if you are using something like the eval option or some other lightweight type of source map that preserves file pathnames in stacktraces.

If you are curious as to why a value is marked "accessed", you can always shift + click the relevant key in the monitor to set a breakpoint.

Performance

If you notice any performance issues, you can speed things up by turning off the most expensive check (whether to ignore object access that originates from node_modules) by typing in the console:

reduxReport.__skipAccessOriginCheck = true