-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor utils #8360
base: main
Are you sure you want to change the base?
Refactor utils #8360
Changes from 6 commits
f136aa0
9ed2e0a
df64c8a
4c938e0
dee5402
4610a2f
9d71e8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,19 +60,15 @@ export const bind_ = function(context, fn, uid) { | |
* | ||
* @return {Function} | ||
*/ | ||
export const throttle = function(fn, wait) { | ||
let last = window.performance.now(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was changed to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good question, we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main reason to use performance.now() here isn't the higher resolution but the guarantee of monotonic time updates. I would be inclined to leave it as is due to that. I'm not sure that the performance difference between Date.now() and performance.now() in this usage are significant enough to worry about. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the method used to determine the start time should be configurable, I can imagine That being said, please don't change it back to |
||
|
||
const throttled = function(...args) { | ||
const now = window.performance.now(); | ||
|
||
if (now - last >= wait) { | ||
fn(...args); | ||
last = now; | ||
} | ||
export const throttle = function(func, delay) { | ||
let lastCallTime = 0; | ||
return function throttled(...args) { | ||
const currentTime = Date.now() | ||
if (currentTime - lastCallTime >= delay) { | ||
lastCallTime = currentTime; | ||
func(...args); | ||
} | ||
}; | ||
|
||
return throttled; | ||
}; | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -141,7 +141,7 @@ function createTimeRangesObj(ranges) { | |||||||
export function createTimeRanges(start, end) { | ||||||||
if (Array.isArray(start)) { | ||||||||
return createTimeRangesObj(start); | ||||||||
} else if (start === undefined || end === undefined) { | ||||||||
} if (start === undefined || end === undefined) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
return createTimeRangesObj(); | ||||||||
} | ||||||||
return createTimeRangesObj([[start, end]]); | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tries to redefine a const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's unbelievable mistake, I've fixed it.