Skip to content

Instantly share code, notes, and snippets.

@FoxxMD
Created December 10, 2015 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FoxxMD/c16c38a23e4256c5a92e to your computer and use it in GitHub Desktop.
Save FoxxMD/c16c38a23e4256c5a92e to your computer and use it in GitHub Desktop.
something to use for animations with react/redux
//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