bigskysoftware / bigskysoftware/htmx

DoOrDelay Utility function

Open
#3,373 3 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.