Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matpaul/redux-timer-middleware
Simple middleware for periodically dispatch actions
https://github.com/matpaul/redux-timer-middleware
redux redux-middleware
Last synced: 23 days ago
JSON representation
Simple middleware for periodically dispatch actions
- Host: GitHub
- URL: https://github.com/matpaul/redux-timer-middleware
- Owner: matpaul
- License: mit
- Created: 2016-11-17T17:57:32.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-22T18:58:35.000Z (over 6 years ago)
- Last Synced: 2024-10-06T15:34:26.087Z (about 1 month ago)
- Topics: redux, redux-middleware
- Language: JavaScript
- Size: 8.79 KB
- Stars: 22
- Watchers: 1
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# redux-timer-middleware
Simple middleware to dispatch actions periodically
## Installation$ npm i --save redux-timer-middleware
## Usage
```javascript
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:
```javascript
import {START_TIMER} from 'redux-timer-middleware';dispatch({
type: START_TIMER,
payload: {
actionName: 'SOME_ACTION_TICK',
timerName: 'infiniteTimer'
}
});
```With a payload:
```javascript
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:
```javascript
import {STOP_TIMER} from 'redux-timer-middleware';dispatch({
type: STOP_TIMER,
payload: {
timerName: 'infiniteTimer'
}
});
```Timer that ends after 10 seconds:
```javascript
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