@fabwcie/free-drawing / utils/perf
utils/perf
Functions
debounce()
debounce<
T>(callback,delay?): (...args) =>void
Defined in: packages/free-drawing/src/utils/perf.ts:21
Function calling callback once calls stop for delay ms: each call within the delay restarts the timer
Type Parameters
T
T extends (...args) => any
debounced function
Parameters
callback
T
function to call, with the arguments of the last call
delay?
number = 300
time without call before calling callback (ms)
Returns
debounced function
(...args) => void
Example
// Define the function that updates the layout
function updateLayout() {
// Update the layout...
}
// Create a debounced version of the function
const debouncedUpdateLayout = debounce(updateLayout, 250);
// Listen for window resize events and call the debounced function
window.addEventListener("resize", debouncedUpdateLayout);measureTime()
measureTime<
T>(func,label):void
Defined in: packages/free-drawing/src/utils/perf.ts:78
Measure time executing function, logged in console
Type Parameters
T
T extends (...args) => any
measured function
Parameters
func
T
function called without arguments
label
string
label of the time in console
Returns
void
throttle()
throttle<
T>(func,limit?):ThrottledFunction<T>
Defined in: packages/free-drawing/src/utils/perf.ts:55
Function calling func at most once every limit ms, for events fired very often (scroll, resize, mouse move...): calls in between are ignored and return the last result
Type Parameters
T
T extends (...args) => any
throttled function
Parameters
func
T
function to call
limit?
number = 100
time before func can be called again (ms)
Returns
throttled function
Example
// Define the function that updates the layout
function updateLayout() {
// Update the layout...
}
// Create a throttled version of the function
const throttledUpdateLayout = throttle(updateLayout, 250);
// Listen for window scroll events and call the throttled function
window.addEventListener("scroll", throttledUpdateLayout);