Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.