-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
/** | ||
A simple debounce function taken from here https://www.freecodecamp.org/news/javascript-debounce-example/ | ||
@param {function} func The function to debounce. | ||
@param {Function} func The function to debounce. | ||
@param {number} timeout The time in ms to wait. | ||
@returns {function} | ||
@returns {Function} | ||
*/ | ||
export default function debounce(func, timeout = 300) { | ||
const debounce = (func, timeout = 300) => { | ||
/** @type {string | number | NodeJS.Timeout | undefined} */ | ||
let timer; | ||
return (...args) => { | ||
return (/** @type {any[]} */ ...args) => { | ||
clearTimeout(timer); | ||
timer = setTimeout(() => { | ||
func.apply(this, args); | ||
}, timeout); | ||
}; | ||
} | ||
}; | ||
|
||
export default debounce; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import canBeZero from './canBeZero.js'; | ||
/** | ||
Make an accessor from a string, number, function or an array of the combination of any | ||
@param {string|number|Function|Array} acc The accessor function, key or list of them. | ||
@returns {Function} An accessor function. | ||
@param {string|number|Function|Array<string|number|Function>} acc The accessor function, key or list of them. | ||
@returns {Function|null} An accessor function. | ||
*/ | ||
export default function makeAccessor(acc) { | ||
if (!canBeZero(acc)) return null; | ||
if (Array.isArray(acc)) { | ||
return d => | ||
return /** @param {any} d */ d => | ||
acc.map(k => { | ||
return typeof k !== 'function' ? d[k] : k(d); | ||
}); | ||
} else if (typeof acc !== 'function') { | ||
return d => d[acc]; | ||
return /** @param {any} d */ d => d[acc]; | ||
} | ||
return acc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters