mirror of
https://github.com/konvajs/konva.git
synced 2025-12-05 03:24:23 +08:00
tweaked throttling algo and added unit tests
This commit is contained in:
10
src/Layer.js
10
src/Layer.js
@@ -44,6 +44,7 @@ Kinetic.Layer.prototype = {
|
||||
this.lastDrawTime = time;
|
||||
if(this.drawTimeout !== undefined) {
|
||||
clearTimeout(this.drawTimeout);
|
||||
this.drawTimeout = undefined;
|
||||
}
|
||||
}
|
||||
/*
|
||||
@@ -52,10 +53,15 @@ Kinetic.Layer.prototype = {
|
||||
*/
|
||||
else if(this.drawTimeout === undefined) {
|
||||
var that = this;
|
||||
/*
|
||||
* if timeout duration is too short, we will
|
||||
* get a lot of unecessary layer draws. Make sure
|
||||
* that the timeout is slightly more than the throttle
|
||||
* amount
|
||||
*/
|
||||
this.drawTimeout = setTimeout(function() {
|
||||
that.draw();
|
||||
clearTimeout(that.drawTimeout);
|
||||
}, 5);
|
||||
}, throttle + 10);
|
||||
}
|
||||
},
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user