Minimize CPU-hungry sidebar drag operations
Unified · Split
| @@ -44,14 +44,20 @@ app.views.Resizer = class Resizer extends app.View { · 43 unmodified lines | ||
| 44 | 44 | return; |
| 45 | 45 | } |
| 46 | 46 | this.lastDragValue = value; |
| 47 | − if (this.lastDrag && this.lastDrag > Date.now() - 50) { | |
| 47 | + if (this.rafPending) { | |
| 48 | 48 | return; |
| 49 | 49 | } |
| 50 | − this.lastDrag = Date.now(); | |
| 51 | − this.resize(value, false); | |
| 50 | + this.rafPending = requestAnimationFrame(() => { | |
| 51 | + this.rafPending = null; | |
| 52 | + this.resize(this.lastDragValue, false); | |
| 53 | + }); | |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | 56 | onDragEnd(event) { |
| 57 | + if (this.rafPending) { | |
| 58 | + cancelAnimationFrame(this.rafPending); | |
| 59 | + this.rafPending = null; | |
| 60 | + } | |
| 55 | 61 | $.off(window, "dragover", this.onDrag); |
| 56 | 62 | let value = event.pageX || event.screenX - window.screenX; |
| 57 | 63 | if ( |