Skip to content

Commit

Permalink
Merge pull request #701 from jeongsd/master
Browse files Browse the repository at this point in the history
cube setInterval -> requestAnimationFrame
  • Loading branch information
skipjack authored Jan 24, 2017
2 parents 3512d57 + 3072fa4 commit 9a2237c
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions components/cube/cube.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,22 @@ export default class Cube extends React.Component {
let degrees = 0;
let axis = 'y';

this._interval = setInterval(() => {
let obj = {};
obj[axis] = degrees += 90;

this.setState({ ...obj, iteration: (this.state.iteration + 1) % 4 });
}, repeatDelay);
let lastTime = performance.now();
let animation = () => {
let nowTime = performance.now();
let deltaTime = nowTime - lastTime;

if (repeatDelay <= deltaTime) {
let obj = {};
obj[axis] = degrees += 90;

this.setState({ ...obj, iteration: (this.state.iteration + 1) % 4 });
lastTime = performance.now();
}

this._requestAnimation = requestAnimationFrame(animation);
};
animation();
}
}

Expand All @@ -95,7 +105,7 @@ export default class Cube extends React.Component {
this.container.removeEventListener('mouseleave', this.listeners.reset);

} else if (continuous) {
clearInterval(this._interval);
cancelAnimationFrame(this._requestAnimation);
}
}

Expand Down

0 comments on commit 9a2237c

Please sign in to comment.