Merge remote-tracking branch 'origin/master'

This commit is contained in:
Angelos Chalaris
2018-01-28 15:23:06 +02:00
2 changed files with 56 additions and 1 deletions

View File

@ -229,6 +229,7 @@ average(1, 2, 3);
* [`compose`](#compose) * [`compose`](#compose)
* [`composeRight`](#composeright) * [`composeRight`](#composeright)
* [`curry`](#curry) * [`curry`](#curry)
* [`debounce`](#debounce)
* [`defer`](#defer) * [`defer`](#defer)
* [`delay`](#delay) * [`delay`](#delay)
* [`functionName`](#functionname) * [`functionName`](#functionname)
@ -3738,6 +3739,44 @@ curry(Math.min, 3)(10)(50)(2); // 2
<br>[⬆ Back to top](#table-of-contents) <br>[⬆ Back to top](#table-of-contents)
### debounce
Creates a debounced function that delays invoking the provided function until after `wait` milliseconds have elapsed since the last time the debounced function was invoked.
Use `setTimeout()` and `clearTimeout()` to debounce the given method, `fn`.
Use `Function.apply()` to apply the `this` context to the function and provide the necessary `arguments`.
Omit the second argument, `wait`, to set the timeout at a default of 0 ms.
```js
const debounce = (fn, wait = 0) => {
let inDebounce;
return function() {
const context = this,
args = arguments;
clearTimeout(inDebounce);
inDebounce = setTimeout(() => fn.apply(context, args), wait);
};
};
```
<details>
<summary>Examples</summary>
```js
window.addEventListener(
'resize',
debounce(function(evt) {
console.log(window.innerWidth);
console.log(window.innerHeight);
}, 250)
); // Will log the window dimensions at most every 250ms
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### defer ### defer
Defers invoking a function until the current call stack has cleared. Defers invoking a function until the current call stack has cleared.

File diff suppressed because one or more lines are too long