Function
throttle (target, method, args*, spacing, immediate) Array public
Module: | @ember/runloop |
---|
Defined in packages/@ember/runloop/index.js:699
import { throttle } from '@ember/runloop';
- target
- Object
- target of method to invoke
- method
- Function|String
- The method to invoke. May be a function or a string. If you pass a string then it will be looked up on the passed target.
- args*
- Object
- Optional arguments to pass to the timeout.
- spacing
- Number
- Number of milliseconds to space out requests.
- immediate
- Boolean
- Trigger the function on the leading instead of the trailing edge of the wait interval. Defaults to true.
- returns
- Array
- Timer information for use in canceling, see `cancel`.
Ensure that the target method is never called more frequently than the specified spacing period. The target method is called immediately.
import { throttle } from '@ember/runloop'; function whoRan() { console.log(this.name + ' ran.'); } let myContext = { name: 'throttle' }; throttle(myContext, whoRan, 150); // whoRan is invoked with context myContext // console logs 'throttle ran.' // 50ms passes throttle(myContext, whoRan, 150); // 50ms passes throttle(myContext, whoRan, 150); // 150ms passes throttle(myContext, whoRan, 150); // whoRan is invoked with context myContext // console logs 'throttle ran.'
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Frunloop/throttle