GithubHelp home page GithubHelp logo

harshithmullapudi / redux-timer-middleware Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matpaul/redux-timer-middleware

0.0 2.0 0.0 11 KB

Simple middleware for periodically dispatch actions

License: MIT License

JavaScript 100.00%

redux-timer-middleware's Introduction

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

redux-timer-middleware's People

Contributors

matpaul avatar ahmednuaman avatar harshithmullapudi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.