Function
throttle (target, method, args*, spacing, immediate) Array public
Module:
@ember/runloop
Defined in packages/@ember/runloop/index.ts:868
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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.' |