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-persist-expire

v1.1.1

Published

Create expiring storage for your Redux stores

Downloads

11,665

Readme

redux-persist-expire

npm

Expiring transformer for redux-persist – Create expiring storage for your Redux stores

Installation

npm install redux-persist-expire

Usage

Create a transform using expireReducer(reducerKey, config) where reducerKey is the reducer to which expiry is to be applied and configuration can be used to configure expire behavior.

const { persistReducer, persistStore } = require('redux-persist');

// Import the transformer creator
const expireReducer = require('redux-persist-expire');

// Create persisted reducers using redux-persist
const persistedReducers = persistReducer({
    transforms: [
       // Create a transformer by passing the reducer key and configuration. Values
       // shown below are the available configurations with default values
       expireReducer('preference', {
         // (Optional) Key to be used for the time relative to which store is to be expired
         persistedAtKey: '__persisted_at',
         // (Required) Seconds after which store will be expired
         expireSeconds: null,
         // (Optional) State to be used for resetting e.g. provide initial reducer state
         expiredState: {},
         // (Optional) Use it if you don't want to manually set the time in the reducer i.e. at `persistedAtKey` 
         // and want the store to  be automatically expired if the record is not updated in the `expireSeconds` time
         autoExpire: false
       })
       // You can add more `expireReducer` calls here for different reducers
       // that you may want to expire
    ]
  },
  rootReducer,
);

export const store = createStore(persistedReducers);
export const persist = persistStore(store);

Examples

Here is the configuration for the common usecases

Expire the item in store if it has not been updated for the past n seconds

// Reset `preference` key to empty object if it has not been updated for the past hour
expireReducer('preference', {
    expireSeconds: 3600
})

Reset an item to empty array after it has not been updated for the past 30 minutes

// Reset `preference` key to given defaults if it has not been updated for the past hour
expireReducer('preference', {
    expireSeconds: 1800,
    expiredState: {
      viewType: 'list',
      token: ''
    }
})

Expire the item in store after 30 minutes of loading it

// Reset `users` key to empty array if it had been loaded 30 minutes ago
expireReducer('users', {
    persistedAtKey: 'loadedAt',
    expireSeconds: 1800,
    expiredState: []        // Reset to empty array after expiry
})

// Note that in this case, you have to manually set the `loadedAt` in
// this case e.g. your reducer might look like this
...
case USERS_LOADED:
    return {
      loadedAt: moment(),  // or use (new Date()).toJSON()
      users: payload
    };
...

Feel free to open an issue if you need help with some specific usecase.

Contributions

  • Report issues with problems and suggestions
  • Open pull request with improvements
  • Spread the word
  • Reach out with any feedback Twitter URL

License

MIT © Kamran Ahmed