Ember.run.throttle()

throttle (target, method, args*, spacing, immediate) Arraypublic

Defined in packages/ember-metal/lib/run_loop.js:625

Ensure that the target method is never called more frequently than the specified spacing period. The target method is called immediately.

function whoRan() {
  console.log(this.name + ' ran.');
}

let myContext = { name: 'throttle' };

run.throttle(myContext, whoRan, 150);
// whoRan is invoked with context myContext
// console logs 'throttle ran.'

// 50ms passes
run.throttle(myContext, whoRan, 150);

// 50ms passes
run.throttle(myContext, whoRan, 150);

// 150ms passes
run.throttle(myContext, whoRan, 150);
// whoRan is invoked with context myContext
// console logs 'throttle ran.'

Parameters:

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 cancelling, see `run.cancel`.
doc_EmberJs
2016-11-30 16:51:42
Comments
Leave a Comment

Please login to continue.