Skip to content

Instantly share code, notes, and snippets.

@runspired
Created May 5, 2015 21:10
Show Gist options
  • Save runspired/a3dc4ddd1af7688a9bb8 to your computer and use it in GitHub Desktop.
Save runspired/a3dc4ddd1af7688a9bb8 to your computer and use it in GitHub Desktop.
Debounced and Throttle computed properties
Ember.computed.debounce = function debouncedProperty() {
var args = [].slice.apply(arguments);
var bounce = args.pop();
var method = args.pop();
var __value = null;
var methodFn = function() {
__value = method.call(this);
};
args.push(function() {
Ember.run.debounce(this, methodFn, bounce);
return __value;
});
return Ember.computed.apply(this, args);
};
Ember.computed.throttle = function throttledProperty() {
var args = [].slice.apply(arguments);
var bounce = args.pop();
var method = args.pop();
var __value = null;
var methodFn = function() {
__value = method.call(this);
};
args.push(function() {
Ember.run.throttle(this, methodFn, bounce);
return __value;
});
return Ember.computed.apply(this, args);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment