Skip to content

Instantly share code, notes, and snippets.

@isao
Created January 26, 2021 19:54
Show Gist options
  • Save isao/b416013441c688063b8e3cda126e492b to your computer and use it in GitHub Desktop.
Save isao/b416013441c688063b8e3cda126e492b to your computer and use it in GitHub Desktop.
`this.args` is undefined in methods wrapped with these decorators.
import { debounce as _debounce, throttle as _throttle } from '@ember/runloop';
function timingDecorator(fn) {
return function (delay) {
return function (instance, property, descriptor) {
return {
value(...args) {
if (!instance.isDestroying && !instance.isDestroyed) {
return fn(instance, descriptor.value, ...args, delay);
}
},
};
};
};
}
const debounce = timingDecorator(_debounce);
const throttle = timingDecorator(_throttle);
export { debounce, throttle };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment