bigskysoftware / bigskysoftware/htmx
DoOrDelay Utility function
- Dominant language
- JavaScript
- Stars
- 49.4k
- Forks
- 1.7k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 30
Description
There are several occurrences of this particular functionality, so I'd like to propose adding the following utility function.
If you do a search for `getWindow().setTimeout` you will see that this function is appropriate for the majority of cases that `window.setTimeout` is used.
It is fairly self-explanatory:
```
/**
* @param {number} delay
* @param {function} callback
* @param {function} elseCallback (optional)
* @returns { any }
*/
function doOrDelay(callback, delay, elseCallback) {
if (delay && delay > 0) {
return getWindow().setTimeout(callback, delay);
} else if (elseCallback) {
return elseCallback();
} else {
return callback();
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.