New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

throttle-action

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

throttle-action

Create a throttled Redux action

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
205
91.59%
Maintainers
1
Weekly downloads
 
Created
Source

Throttle Action NPM version

Create throttled redux-thunk actions. Throttled actions can be dispatched at most once per every wait milliseconds.

Installation

npm i --save throttle-action

Usage

import throttleAction from 'throttle-action';

const INCREMENT_COUNTER = 'INCREMENT_COUNTER';

function increment() {
  return {
    type: INCREMENT_COUNTER
  };
}

function incrementThunk() {
  return dispatch => {
    dispatch(increment());
  };
}

// wrap normal actions with throttleAction() to create throttled actions
const incrementThrottled = throttleAction(increment, 1000);
const incrementThunkThrottled = throttleAction(incrementThunk, 5000, {trailing: false});

// call throttled actions like normal redux actions
import {createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers';

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

store.dispatch(incrementThrottled());
// --> INCREMENT_COUNTER dispatched immediately
store.dispatch(incrementThrottled());
// --> INCREMENT_COUNTER dispatched again after one second

store.dispatch(incrementThunkThrottled());
// --> INCREMENT_COUNTER dispatched immediately
store.dispatch(incrementThunkThrottled());
store.dispatch(incrementThunkThrottled());
// --> nothing dispatched

Uses lodash's throttle.

License

MIT

Keywords

throttle

FAQs

Package last updated on 22 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts