1
Fork 0

Add some JSDoc comments to rustdoc JS

This follows the Closure Compiler dialect of JSDoc, so we
can use it to do some basic type checking. We don't plan to
compile with Closure Compiler, just use it to check types. See
https://github.com/google/closure-compiler/wiki/ for details.
This commit is contained in:
Jacob Hoffman-Andrews 2021-12-16 21:17:22 -08:00
parent e100ec5bc7
commit 7ba086c6db
5 changed files with 170 additions and 30 deletions

View file

@ -55,6 +55,12 @@ function removeClass(elem, className) {
elem.classList.remove(className);
}
/**
* Run a callback for every element of an Array.
* @param {Array<?>} arr - The array to iterate over
* @param {function(?)} func - The callback
* @param {boolean} [reversed] - Whether to iterate in reverse
*/
function onEach(arr, func, reversed) {
if (arr && arr.length > 0 && func) {
var length = arr.length;
@ -76,6 +82,16 @@ function onEach(arr, func, reversed) {
return false;
}
/**
* Turn an HTMLCollection or a NodeList into an Array, then run a callback
* for every element. This is useful because iterating over an HTMLCollection
* or a "live" NodeList while modifying it can be very slow.
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection
* https://developer.mozilla.org/en-US/docs/Web/API/NodeList
* @param {NodeList<?>|HTMLCollection<?>} lazyArray - An array to iterate over
* @param {function(?)} func - The callback
* @param {boolean} [reversed] - Whether to iterate in reverse
*/
function onEachLazy(lazyArray, func, reversed) {
return onEach(
Array.prototype.slice.call(lazyArray),