Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@
var index = 0;
var taskStart = 0;
var tasklength = 0;

const getCurrentTime = typeof performance === 'object' && typeof performance.now === 'function'
? () => performance.now()
: () => Date.now();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this work without the arrow functions?

  ? performance.now
  : Date.now;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it works, but I added the arrow function to prevent redundant calling


var IdleDeadline = {
get didTimeout(){
return false;
},
timeRemaining: function(){
var timeRemaining = remainingTime - (Date.now() - taskStart);
var timeRemaining = remainingTime - (getCurrentTime() - taskStart);
return Math.max(0, timeRemaining)
},
};

var setInactive = debounce(function(){
remainingTime = 22;
throttle = 66;
Expand All @@ -44,7 +50,7 @@
var id, timestamp;
var wait = 99;
var check = function(){
var last = (Date.now()) - timestamp;
var last = (getCurrentTime()) - timestamp;

if (last < wait) {
id = setTimeout(check, wait - last);
Expand All @@ -54,7 +60,7 @@
}
};
return function(){
timestamp = Date.now();
timestamp = getCurrentTime();
if(!id){
id = setTimeout(check, wait);
}
Expand Down Expand Up @@ -100,9 +106,9 @@
function scheduleLazy(){

if(isRunning){return;}
throttleDelay = throttle - (Date.now() - taskStart);
throttleDelay = throttle - (getCurrentTime() - taskStart);

scheduleStart = Date.now();
scheduleStart = getCurrentTime();

isRunning = true;

Expand All @@ -125,7 +131,7 @@
1
;

taskStart = Date.now();
taskStart = getCurrentTime();
isRunning = false;

lazytimer = null;
Expand Down