Skip to content
Snippets Groups Projects
Commit f396b9b8 authored by Hakim El Hattab's avatar Hakim El Hattab
Browse files

limit how often the notes window updates presentation states

parent c02d185c
Branches
No related tags found
No related merge requests found
......@@ -244,6 +244,9 @@
}
// Limit to max one state update per X ms
handleStateMessage = debounce( handleStateMessage, 200 );
/**
* Creates the preview iframes.
*/
......@@ -340,6 +343,37 @@
}
/**
* Limits the frequency at which a function can be called.
*/
function debounce( fn, ms ) {
var lastTime = 0,
timeout;
return function() {
var args = arguments;
var context = this;
clearTimeout( timeout );
var timeSinceLastCall = Date.now() - lastTime;
if( timeSinceLastCall > ms ) {
fn.apply( context, args );
lastTime = Date.now();
}
else {
timeout = setTimeout( function() {
fn.apply( context, args );
lastTime = Date.now();
}, ms - timeSinceLastCall );
}
}
}
})();
</script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment