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 🙏

© 2025 – Pkg Stats / Ryan Hefner

redux-idle-middleware

v0.0.1

Published

Redux middleware to be notified when your users go idle

Downloads

14

Readme

Redux Idle

Redux middleware and reducer to update your store when your user goes idle.

Table of Contents

Installation

npm i redux-idle-middleware

redux-idle-middleware has a peer dependency over redux. You will get a warning if it's not already installed in your node nodules.

Quickstart

import { combineReducers, createStore, applyMiddleware } from 'redux';
import { idleMiddleware, idleReducer } from 'redux-idle-middleware';

/**
 * Use the provided reducer to quickly update some part of your state.
 */
const rootReducer = combineReducers({
  isUserIdle: idleReducer(),
});

/**
 * Configure the provided middleware.
 */
const loadedIdleMiddleware = idleMiddleware({ timeToWaitBeforeIdleness: 5000 });

/**
 * Create your store with your middlewares.
 */
const store = createStore(rootReducer, applyMiddleware(loadedIdleMiddleware));

API

The following are part of the public API and can be imported from redux-idle-middleware.

idleReducer

This provided reducer factory can be plugged into your state and automatically update some part of it out of the box. You choose to which part of the state it gets plugged in, isUserIdle is just for the example.

Usage

import { combineReducers } from 'redux';
import { idleReducer } from 'redux-idle-middleware';

const rootReducer = combineReducers({
  isUserIdle: idleReducer(),
});

idleMiddleware

This provided middleware factory can be configured and used when creating the redux store. The following options can be provided:

{
  /**
   * How much time must enlapse before `redux-idle-middleware` considers the current user to be idle. The value is in **milliseconds**
   */
  timeToWaitBeforeIdleness: number;
}

Usage

import { createStore, applyMiddleware } from 'redux';
import { idleMiddleware } from 'redux-idle-middleware';

const rootReducer = ...;
const loadedIdleMiddleware = idleMiddleware({
  timeToWaitBeforeIdleness: 5000 // 5 seconds.
})

const store = createStore(rootReducer, applyMiddleware(loadedIdleMiddleware));

REDUX_IDLE_ACTION_TYPE

This is the action type that's being dispatched by the idle middleware. Usually, if you use the provided reducer you are not going to need this. Although, for some cases if you need to react on this action in some other reducer, you can use it.

Usage

import { REDUX_IDLE_ACTION_TYPE } from 'redux-idle-middleware';

const bannerReducer = (state, action) => {
  if (action.type === REDUX_IDLE_ACTION_TYPE) {
    return { ...state, shouldShowIdleBanner: action.isIdle };
  }

  return state;
};

Contribute

Contributions are welcome! Please open issues when you found a bug. If you wish to fix a bug, a pull request is necessary. The PR is required to pass the tests and the linter before being merged. If you wish to work on a new feature, open an issue and we'll talk about it.

Run tests:

npm t

Build

npm run build

Misc

This aims to be a simple middleware you can plug into your store and gives you a boolean if your user is considered idle or not. It doesn't do more than that.

Bundlephobia

TBD.

License

MIT