redux-effects-timeout
v0.1.7
Published
redux-effects middleware for managing timeouts/intervals/requestAnimationFrames
Downloads
895
Readme
redux-effects-timeout
Driver and set of action creators for timing related effects in redux-effects.
Installation
$ npm install redux-effects-timeout
Usage
Middleware
To install the middleware, just do this:
import timeout from 'redux-effects-timeout'
applyMiddleware(timeout())(createStore)
Action creators
raf(cb)
- executecb
on the next animation frametimeout(cb, ms)
- executecb
inms
millisecondsinterval(cb, ms)
- executecb
everyms
millisecondscancelTimeout(id)
- cancel the timeout specified byid
cancelInterval(id)
- cancel the interval specified byid
cancelAnimationFrame(id)
- cancel the animation frame callback specified byid
Each of the first three methods returns an id
(which may then be passed to each of the latter three, respectively) to any handlers in .meta.steps
.
import {interval, cancelInterval} from 'redux-effects-timeout'
import {createAction} from 'redux-actions'
import {bind} from 'redux-effects'
function startCounting () {
return bind(interval(incrementCounter, 1000), id => intervalCreated)
}
function stopCounting (id) {
return cancelInterval(id)
}
const intervalCreated = createAction('INTERVAL_CREATED')
// ... in your state reducer:
function reduce (state, action) {
if (action.type === 'INTERVAL_CREATED') {
state = {...state, intervalId: action.payload}
}
return state
}
License
The MIT License
Copyright © 2015, Weo.io <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.