mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Uses rAF by default for debounce/throtte unless `wait` is specified. (#3560)
This commit is contained in:
committed by
John-David Dalton
parent
fa73d46885
commit
d985dbffb8
20
throttle.js
20
throttle.js
@@ -3,11 +3,11 @@ import isObject from './isObject.js'
|
||||
|
||||
/**
|
||||
* Creates a throttled function that only invokes `func` at most once per
|
||||
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
||||
* method to cancel delayed `func` invocations and a `flush` method to
|
||||
* immediately invoke them. Provide `options` to indicate whether `func`
|
||||
* should be invoked on the leading and/or trailing edge of the `wait`
|
||||
* timeout. The `func` is invoked with the last arguments provided to the
|
||||
* every `wait` milliseconds (or once per browser frame). The throttled function
|
||||
* comes with a `cancel` method to cancel delayed `func` invocations and a
|
||||
* `flush` method to immediately invoke them. Provide `options` to indicate
|
||||
* whether `func` should be invoked on the leading and/or trailing edge of the
|
||||
* `wait` timeout. The `func` is invoked with the last arguments provided to the
|
||||
* throttled function. Subsequent calls to the throttled function return the
|
||||
* result of the last `func` invocation.
|
||||
*
|
||||
@@ -16,7 +16,11 @@ import isObject from './isObject.js'
|
||||
* is invoked more than once during the `wait` timeout.
|
||||
*
|
||||
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
||||
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
||||
* until the next tick, similar to `setTimeout` with a timeout of `0`.
|
||||
*
|
||||
* If `wait` is omitted in an environment with `requestAnimationFrame`, `func`
|
||||
* invocation will be deferred until the next frame is drawn (typically about
|
||||
* 16ms).
|
||||
*
|
||||
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
||||
* for details over the differences between `throttle` and `debounce`.
|
||||
@@ -24,7 +28,9 @@ import isObject from './isObject.js'
|
||||
* @since 0.1.0
|
||||
* @category Function
|
||||
* @param {Function} func The function to throttle.
|
||||
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
||||
* @param {number} [wait=0]
|
||||
* The number of milliseconds to throttle invocations to; if omitted,
|
||||
* `requestAnimationFrame` is used (if available).
|
||||
* @param {Object} [options={}] The options object.
|
||||
* @param {boolean} [options.leading=true]
|
||||
* Specify invoking on the leading edge of the timeout.
|
||||
|
||||
Reference in New Issue
Block a user