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-timeout

v2.0.0

Published

Client side session timeout monitoring for redux

Downloads

3,646

Readme

Timeout middleware for Redux.

Installation

npm install --save redux-timeout

What is it?

Gives ability to call functions if certain actions have not been dispatched in x amount of time.

redux-effects-timeout is a similar library to work with timeouts in redux. The main difference between the 2, is this library (redux-timeout) will watch for actions as they are dispatched and reset the setTimeout accordingly. If you are just looking for a way to dispatch actions after a certain period of time, redux-effects-timeout should be perfectly fine for you.

Why?

Because Redux gives us a predictable way to track if events / actions are taking place in the application, we can make some assumptions from this and use this to our advantage.

Example 1. If no actions have been dispatched in the past > 30 minutes, it's pretty safe to assume that the user is not actively using the application. We could then dispatch an action that triggers the user to be logged out and require a fresh login.

Example 2. In a live editing document, if no actions have been dispatched from a form in the past 2 seconds we could dispatch an action that persists the form to the server, therefore eliminating any need for some other debounce logic.

Usage

Checkout the tests / examples folder for further examples.

Initialize the middleware

import { reduxTimeout } from 'redux-timeout'
const store = createStore(reducer, applyMiddleware(reduxTimeout()))

Add action to be watched

import { addTimeout } from 'redux-timeout'
import { ACTION_TO_WATCH, SAVE } from '/path/to/my/action/constants'

...

componentDidMount() {
  const { addTimeout, save } = this.props
  addTimeout(1000, ACTION_TO_WATCH, save)  
}

...

const mapDispatchToProps = (dispatch) => {
  return {
    addTimeout: (timeout, action, fn) => {
      dispatch(addTimeout(timeout, action, fn))
    },
    save: () => {
      dispatch({ type: SAVE })
    }
  }
}

Remove action being watched

import { removeTimeout } from 'redux-timeout'
import { ACTION_TO_WATCH } from '/path/to/my/action/constants'

...

dispatch(removeTimeout(ACTION_TO_WATCH))

...

API

addTimeout(timeout, ACTION_TO_WATCH, functionToCall)

Arguments

  • timeout (Integer): time in ms. Uses this value when initializing the setTimeout. This setTimeout will be cleared and recreated on any dispatches of ACTION_TO_WATCH.

  • ACTION_TO_WATCH (String | Array): action or array of actions to watch for. See purpose above.

  • functionToCall (Function): function to call when timeout is triggered.

removeTimeout(ACTION_TO_REMOVE)

Arguments

  • ACTION_TO_REMOVE (String | Array): action to remove from the watched list

Constants

WATCH_ALL: set as an action to watch and the middleware will watch for ANY actions that are dispatched. Useful if implementing session timeout functionality (examples above or in test lib)