Socket
Socket
Sign inDemoInstall

redux-timer-middleware

Package Overview
Dependencies
3
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    redux-timer-middleware

redux-timer-middleware


Version published
Weekly downloads
116
increased by12.62%
Maintainers
1
Install size
83.9 kB
Created
Weekly downloads
 

Changelog

Source

1.0.0

  • Add ability add actionPayload to timerAction

Readme

Source

redux-timer-middleware

Simple middleware to dispatch actions periodically

Installation

$ npm i --save redux-timer-middleware

Usage

import timerMiddleware from 'redux-timer-middleware'

applyMiddleware(timerMiddleware)(createStore)
Start Timer

You need to dispatch action START_TIMER and provide in payload:

  • actionName (required) - action that will be dispatched each timer tick
  • timerName (required) - timer name (need for stop feature)
  • actionPayload - payload that will be provided to the actionName
  • timerInterval - interval in ms (default 1000)
  • timerPeriod - tick count after which timer ends, when timer ends - action name with _END will be dispatched
Stop Timer or Stop multiple timers

You need to dispatch action STOP_TIMER and provide in payload:

  • timerName (required) - timer name that we stop
  • timerNames [] - timer names in array if we need to stop multiple timers

Examples

Infinite timer:

import {START_TIMER} from 'redux-timer-middleware';

dispatch({
    type: START_TIMER,
    payload: {
        actionName: 'SOME_ACTION_TICK',
        timerName: 'infiniteTimer'
    }
});

With a payload:

import {START_TIMER} from 'redux-timer-middleware';

dispatch({
    type: START_TIMER,
    payload: {
        actionName: 'SOME_ACTION_TICK',
        actionPayload: { /* my cool payload */ },
        timerName: 'infiniteTimer'
    }
});

To stop this timer:

import {STOP_TIMER} from 'redux-timer-middleware';

dispatch({
    type: STOP_TIMER,
    payload: {
        timerName: 'infiniteTimer'
    }
});

Timer that ends after 10 seconds:

import {START_TIMER} from 'redux-timer-middleware';

dispatch({
    type: START_TIMER,
    payload: {
        actionName: 'SOME_ACTION_TICK',
        timerName: 'testTimer',
        timerPeriod: 10
    }
});

After timer ends action with type 'SOME_ACTION_TICK_END' will be dispatched

Keywords

FAQs

Last updated on 22 Apr 2018

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc