mithril-vndb/test-utils/throttleMock.js
2017-06-13 15:20:29 +02:00

24 lines
465 B
JavaScript

module.exports = function() {
var queue = []
return {
throttle: function(fn) {
var pending = false
return function() {
if (!pending) {
queue.push(function(){
pending = false
fn()
})
pending = true
}
}
},
fire: function() {
queue.forEach(function(fn) {fn()})
queue.length = 0
},
queueLength: function(){
return queue.length
}
}
}