Travis build: 840 [ci skip]

This commit is contained in:
Travis CI
2018-01-02 08:50:06 +00:00
parent 347cb3558b
commit f9525f865e
3 changed files with 39 additions and 2 deletions

View File

@ -133,6 +133,7 @@
* [`defer`](#defer) * [`defer`](#defer)
* [`functionName`](#functionname) * [`functionName`](#functionname)
* [`memoize`](#memoize) * [`memoize`](#memoize)
* [`once`](#once)
* [`runPromisesInSeries`](#runpromisesinseries) * [`runPromisesInSeries`](#runpromisesinseries)
* [`sleep`](#sleep) * [`sleep`](#sleep)
@ -2458,6 +2459,34 @@ anagramsCached('javascript'); // returns virtually instantly since it's now cach
<br>[⬆ Back to top](#table-of-contents) <br>[⬆ Back to top](#table-of-contents)
### once
Ensures a function is called only once.
Utilizing a closure, use a flag, `called`, and set it to `true` once the function is called for the first time, preventing it from being called again.
Allow the function to be supplied with an arbitrary number of arguments using the spread (`...`) operator.
```js
const once = fn =>
(called => (...args) => (!called ? ((called = true), fn(...args)) : undefined))();
```
<details>
<summary>Examples</summary>
```js
const startApp = event => {
// initializes the app
console.log(event); // access to any arguments supplied
};
document.addEventListener('click', once(startApp)); // only runs `startApp` once upon click
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### runPromisesInSeries ### runPromisesInSeries
Runs an array of promises in series. Runs an array of promises in series.

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,8 @@ Utilizing a closure, use a flag, `called`, and set it to `true` once the functio
Allow the function to be supplied with an arbitrary number of arguments using the spread (`...`) operator. Allow the function to be supplied with an arbitrary number of arguments using the spread (`...`) operator.
```js ```js
const once = fn => (called => (...args) => !called ? (called = true, fn(...args)) : undefined)() const once = fn =>
(called => (...args) => (!called ? ((called = true), fn(...args)) : undefined))();
``` ```
```js ```js