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-re-dispatch

v1.0.5

Published

A redux middleware to dispatch recent actions based on action Que

Downloads

3

Readme

Redux Re-dispatch

A redux middleware to dispatch recent actions from action history que.

Installation:

$ npm install 'redux-re-dispatch'

Configure Middleware:

...
import { setupRedispatcher } from 'redux-re-dispatch';

const redispatchMiddleware = setupRedispatcher({
    logger: true,
    maxActionHistories: 200,
    intervalForResetingDispatch: 2000
    maxNumberOfReDispatch: 5,
 });

 const middlewares = [redispatchMiddleware];

const store = createStore(rootReducer,initialSte, compose(applyMiddleware(...middlewares)));
...

Options:

| Property | Data Type | Default Value | Description | | --- | --- | --- | --- | | logger | string | true | You can show/hide logs in console when action is redispatched | | maxActionHistories | integer | 200 | You can limit the maximum size of collection or que to save actions as history. | | intervalForResetingDispatch | integer | 3000 (Millisecond)| You can limit the maximum allocated time for re-dispatching same actionType. After every intervalForResetingDispatch time slot for each action type, the new time slot will be allocated to reach the max execution limit| If action type TYPE_X are executed the maxNumberOfReDispatch times then the counter will be reset after intervalForResetingDispatch milliseconds. | maxNumberOfReDispatch | integer | 10 | You can define the default number of execution for how many times any action will be re-dispatched using redispatched(actionType)* when second parameter is omitted. |

Usage Example:

This example describes how it can be used with redux-saga. You can use it wherever you want. In this example we are trying to pull all the station information dispatching types.GET_STATIONS action. If any error occurs while getting response from API or by any means then we may need to try the same API call or process again until we get the actual response. But the number of API call or execution should not be infinite.

You don't need to pass any payload when you redispatch any action. Payload will be added by middleware itself from the previous action of the action history que. So you need to pass the actionType and maxNumberOfDispatch as parameters. But the second parameter is optional.


import { redispatch } from 'redux-re-dispatch';
...
export function* getAllStationsSaga(payload) {
  try {
    const stations = yield call(fetchAllStations, payload);
    yield [
     put({ type: types.GET_STATIONS_SUCCESS, stations })
   ];
  } catch (error) {
    /*
    ** This will try to fetch all the stations again when thrown exception. Here it will try maximum 3 time to get all the stations as failover.
    ** @param type {string} - it's a action type that will be redispatched from recent history
    ** @param {number} - Maximum number of attempt to re-dispatch that action
    */
    redispatch(types.GET_STATIONS, 3);
    yield [
        put({ type: types.GET_STATIONS_FAILED }),
      ];
  }
};

...

APIs:

| Method Name| Arguments | Description | | --- | --- | --- | | setupRedispatcher | options {object} | This method will initialize the re-dispatch middleware using these options| | redispatch | actionType {string} {required}, maxNumberOfDispatch {number} {optional} | This method is the main dispatcher that filters actions by actionType and dispatches the most recent action from the action history without any payload. This method dispatches the given action type maxNumberOfDispatch times within intervalForResetingDispatch milliseconds managing que of actions|

Made with Love by Rahul Baruri