Skip to content

Commit

Permalink
Fixing request animation frame callback issue. (#31)
Browse files Browse the repository at this point in the history
The issue could result in multiple animation frame requests in succession
cancelling one another out. Can result in choppy interactions or what looks
like an update issue.
  • Loading branch information
Christopher Root authored Oct 31, 2019
1 parent 5d41220 commit f2e2ded
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dist/mapd-draw-dev.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mapd-draw.js

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions src/engine/draw-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export default class DrawEngine extends EventHander {
)

this._renderFrameCb = this.renderAll.bind(this)
this._renderRequestId = 0
this._renderRequestTime = 0
this._ids = {
shapeId: 1
}
Expand Down Expand Up @@ -599,10 +599,7 @@ export default class DrawEngine extends EventHander {
}

_rerenderCb() {
if (this._renderRequestId) {
window.cancelAnimationFrame(this._renderRequestId)
}
this._renderRequestId = window.requestAnimationFrame(this._renderFrameCb)
window.requestAnimationFrame(this._renderFrameCb)
}

_reorderCb(event) {
Expand Down Expand Up @@ -634,9 +631,17 @@ export default class DrawEngine extends EventHander {
})
}

renderAll() {
renderAll(timestamp) {
if (timestamp) {
if (timestamp <= this._renderRequestTime) {
return
}
this._renderRequestTime = timestamp
} else {
this._renderRequestTime = performance.now()
}

const ctx = this._drawCtx
// ctx.clearRect(0, 0, this.width, this.height)
ctx.clearRect(
0,
0,
Expand Down

0 comments on commit f2e2ded

Please sign in to comment.