Created
December 10, 2015 13:49
-
-
Save FoxxMD/c16c38a23e4256c5a92e to your computer and use it in GitHub Desktop.
something to use for animations with react/redux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//requires https://github.com/gaearon/redux-thunk | |
//https://www.reddit.com/r/reactjs/comments/3vw7xq/reduxflux_animation_confusion/cxrpjbx | |
export default { | |
offset: 0, | |
interval: 0, | |
started: false, | |
paused: false, | |
start(offset, onTick) { | |
this.reset(); | |
this.offset = offset; | |
this.started = true; | |
this.onTick = onTick; | |
this.tick(); | |
}, | |
pause() { | |
this.paused = true; | |
}, | |
resume() { | |
this.paused = false; | |
this.tick(); | |
}, | |
tick() { | |
if (!this.paused && this.started) { | |
this.interval += this.offset; | |
if (typeof this.onTick === 'function') this.onTick(); | |
setTimeout(() => this.tick(), this.offset); | |
} | |
}, | |
reset() { | |
this.offset = 0; | |
this.interval = 0; | |
this.started = false; | |
this.paused = false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment