Skip to content

Instantly share code, notes, and snippets.

@fliptopbox
Created March 26, 2018 21:20
Show Gist options
  • Save fliptopbox/95cd47961c2271f49c8ec2faa7dd0914 to your computer and use it in GitHub Desktop.
Save fliptopbox/95cd47961c2271f49c8ec2faa7dd0914 to your computer and use it in GitHub Desktop.
incremental updater
var ms;
var runtime;
var i;
var total;
var diff;
var incr;
var prev = 0;
function updater (target, rtime, msec) {
if(target) {
i = 0;
total = target - (prev || 0);
if(total === 0) return target;
console.time('updater');
ms = msec || ms || 250;
runtime = rtime || runtime || 2500;
incr = total / (runtime/ms);
console.log(total, incr, ms, runtime)
}
if (i + incr < total) {
i += incr;
return setTimeout(()=>{
console.log(i + prev)
updater();
}, ms);
;
}
console.timeEnd('updater')
prev += total;
console.log("---------------------------------- done", i, prev)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment